This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
75 lines (63 loc) · 2.96 KB
/
event.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
69
70
71
72
73
74
75
package stream_chat
import (
"errors"
"net/http"
"net/url"
"path"
"time"
)
type EventType string
const (
EventUserPresenceChanged EventType = "user.presence.changed"
EventUserWatchingStart EventType = "user.watching.start"
EventUserWatchingStop EventType = "user.watching.stop"
EventUserUpdated EventType = "user.updated"
EventTypingStart EventType = "typing.start"
EventTypingStop EventType = "typing.stop"
EventMessageNew EventType = "message.new"
EventMessageUpdated EventType = "message.updated"
EventMessageDeleted EventType = "message.deleted"
EventMessageRead EventType = "message.read"
EventReactionNew EventType = "reaction.new"
EventReactionDeleted EventType = "reaction.deleted"
EventMemberAdded EventType = "member.added"
EventMemberUpdated EventType = "member.updated"
EventMemberRemoved EventType = "member.removed"
EventChannelUpdated EventType = "channel.updated"
EventChannelDeleted EventType = "channel.deleted"
EventHealthCheck EventType = "health.check"
EventNotificationNewMessage EventType = "notification.message_new"
EventNotificationMarkRead EventType = "notification.mark_read"
EventNotificationInvited EventType = "notification.invited"
EventNotificationInviteAccepted EventType = "notification.invite_accepted"
EventNotificationAddedToChannel EventType = "notification.added_to_channel"
EventNotificationRemovedFromChannel EventType = "notification.removed_from_channel"
EventNotificationMutesUpdated EventType = "notification.mutes_updated"
)
type Event struct {
CID string `json:"cid,omitempty"` // Channel ID
Type EventType `json:"type"` // Event type, one of Event* constants
Message *Message `json:"message,omitempty"`
Reaction *Reaction `json:"reaction,omitempty"`
Channel *Channel `json:"channel,omitempty"`
Member *ChannelMember `json:"member,omitempty"`
User *User `json:"user,omitempty"`
UserID string `json:"user_id,omitempty"`
OwnUser *User `json:"me,omitempty"`
WatcherCount int `json:"watcher_count,omitempty"`
ExtraData map[string]interface{} `json:"-"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
type eventRequest struct {
Event *Event `json:"event"`
}
// SendEvent sends an event on this channel
func (ch *Channel) SendEvent(event *Event, userID string) error {
if event == nil {
return errors.New("event is nil")
}
event.User = &User{ID: userID}
req := eventRequest{Event: event}
p := path.Join("channels", url.PathEscape(ch.Type), url.PathEscape(ch.ID), "event")
return ch.client.makeRequest(http.MethodPost, p, nil, req, nil)
}