Private
Public Access
1
0

server: implements /markConversation

This commit is contained in:
2023-07-19 12:10:25 -06:00
parent 1fce2c7cb3
commit b77020e23c
3 changed files with 88 additions and 6 deletions

View File

@@ -229,6 +229,29 @@ func (m *MockHTTPServer) handlePollUpdates(w http.ResponseWriter, r *http.Reques
}
}
func (m *MockHTTPServer) handleMarkConversation(w http.ResponseWriter, r *http.Request) {
guid := r.URL.Query().Get("guid")
if len(guid) == 0 {
log.Error().Msg("handleMarkConversation: Got empty guid parameter")
http.Error(w, "no guid parameter specified", http.StatusBadRequest)
return
}
// Find conversation
convo, err := m.Server.ConversationForGUID(guid)
if err != nil {
log.Error().Err(err).Msgf("handleMarkConversation: Error finding conversation (%s)", guid)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Mark conversation
m.Server.MarkConversationAsRead(convo)
// Respond 200
w.WriteHeader(http.StatusOK)
}
func (m *MockHTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
m.logRequest(r, r.URL.Query().Encode())
m.mux.ServeHTTP(w, r)
@@ -248,6 +271,7 @@ func NewMockHTTPServer(config MockHTTPServerConfiguration) *MockHTTPServer {
this.mux.Handle("/messages", http.HandlerFunc(this.handleMessages))
this.mux.Handle("/pollUpdates", http.HandlerFunc(this.handlePollUpdates))
this.mux.Handle("/sendMessage", http.HandlerFunc(this.handleSendMessage))
this.mux.Handle("/markConversation", http.HandlerFunc(this.handleMarkConversation))
this.mux.Handle("/", http.HandlerFunc(this.handleNotFound))