Private
Public Access
1
0

Implement beforeMessageGUID/afterMessageGUID/beforeDate

This commit is contained in:
2023-08-08 21:38:04 -07:00
parent 5c9f580dff
commit 6a0b7ca225
3 changed files with 189 additions and 5 deletions

View File

@@ -92,8 +92,6 @@ func (m *MockHTTPServer) handleConversations(w http.ResponseWriter, r *http.Requ
}
func (m *MockHTTPServer) handleMessages(w http.ResponseWriter, r *http.Request) {
// TODO handle optional "limit", "beforeDate", "beforeMessageGUID", and "afterMessageGUID" parameters
guid := r.URL.Query().Get("guid")
if len(guid) == 0 {
log.Error().Msg("handleMessage: Got empty guid parameter")
@@ -108,7 +106,43 @@ func (m *MockHTTPServer) handleMessages(w http.ResponseWriter, r *http.Request)
return
}
messages := m.Server.MessagesForConversation(conversation)
beforeDate := r.URL.Query().Get("beforeDate")
beforeGUID := r.URL.Query().Get("beforeMessageGUID")
afterGUID := r.URL.Query().Get("afterMessageGUID")
limit := r.URL.Query().Get("limit")
stringOrNil := func(s string) *string {
if len(s) == 0 {
return nil
}
return &s
}
dateOrNil := func(s string) *time.Time {
if len(s) == 0 {
return nil
}
t, _ := time.Parse(time.RFC3339, s)
return &t
}
intOrNil := func(s string) *int {
if len(s) == 0 {
return nil
}
i, _ := strconv.Atoi(s)
return &i
}
query := server.MessagesQuery{
Limit: intOrNil(limit),
BeforeDate: dateOrNil(beforeDate),
BeforeGUID: stringOrNil(beforeGUID),
AfterGUID: stringOrNil(afterGUID),
ConversationGUID: conversation.Guid,
}
messages := m.Server.PerformMessageQuery(&query)
jsonData, err := json.Marshal(messages)
if err != nil {