-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.go
65 lines (53 loc) · 1.44 KB
/
message.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
package rtm2
// MessageType for Message Channel and Stream Channel
type MessageType int
const (
MessageTypeBinary MessageType = 0
MessageTypeString MessageType = 1
)
type Message struct {
UserId string
Type MessageType
Message []byte
}
type MessageOptions struct {
Type MessageType
Message bool
Metadata bool
Presence bool
Lock bool
}
func DefaultMessageOptions() *MessageOptions {
return &MessageOptions{Type: MessageTypeBinary, Message: true, Metadata: false, Presence: true, Lock: false}
}
type MessageOption func(c *MessageOptions)
// WithMessageType is MessageTypeBinary by default.
func WithMessageType(t MessageType) MessageOption {
return func(c *MessageOptions) {
c.Type = t
}
}
// WithMessage whether to subscribe message in the Message Channel.
func WithMessage(enabled bool) MessageOption {
return func(c *MessageOptions) {
c.Message = enabled
}
}
// WithMessageMetadata whether to subscribe Channel Metadata in the Message Channel.
func WithMessageMetadata(enabled bool) MessageOption {
return func(c *MessageOptions) {
c.Metadata = enabled
}
}
// WithMessagePresence whether to subscribe user Presence in the Message Channel.
func WithMessagePresence(enabled bool) MessageOption {
return func(c *MessageOptions) {
c.Presence = enabled
}
}
// WithMessageLock whether to subscribe Lock in the Message Channel.
func WithMessageLock(enabled bool) MessageOption {
return func(c *MessageOptions) {
c.Lock = enabled
}
}