-
Notifications
You must be signed in to change notification settings - Fork 31
/
message_history.go
68 lines (55 loc) · 1.82 KB
/
message_history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package stream_chat
import (
"context"
"encoding/json"
"errors"
"net/http"
"time"
)
type QueryMessageHistoryRequest struct {
Filter map[string]any `json:"filter"`
Sort []*SortOption `json:"sort,omitempty"`
Limit int `json:"limit,omitempty"`
Next string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"`
}
type MessageHistoryEntry struct {
MessageID string `json:"message_id"`
MessageUpdatedByID string `json:"message_updated_by_id"`
MessageUpdatedAt time.Time `json:"message_updated_at"`
Text string `json:"text"`
Attachments []*Attachment `json:"attachments"`
ExtraData map[string]interface{} `json:"-"`
}
var _ json.Unmarshaler = (*MessageHistoryEntry)(nil)
var _ json.Marshaler = (*MessageHistoryEntry)(nil)
type messageHistoryJson MessageHistoryEntry
func (m *MessageHistoryEntry) UnmarshalJSON(data []byte) error {
var m2 messageHistoryJson
if err := json.Unmarshal(data, &m2); err != nil {
return err
}
*m = MessageHistoryEntry(m2)
if err := json.Unmarshal(data, &m.ExtraData); err != nil {
return err
}
removeFromMap(m.ExtraData, *m)
return nil
}
func (m MessageHistoryEntry) MarshalJSON() ([]byte, error) {
return addToMapAndMarshal(m.ExtraData, messageHistoryJson(m))
}
type QueryMessageHistoryResponse struct {
MessageHistory []*MessageHistoryEntry `json:"message_history"`
Next *string `json:"next,omitempty"`
Prev *string `json:"prev,omitempty"`
Response
}
func (c *Client) QueryMessageHistory(ctx context.Context, request QueryMessageHistoryRequest) (*QueryMessageHistoryResponse, error) {
if len(request.Filter) == 0 {
return nil, errors.New("you need specify one filter at least")
}
var resp QueryMessageHistoryResponse
err := c.makeRequest(ctx, http.MethodPost, "messages/history", nil, request, &resp)
return &resp, err
}