-
Notifications
You must be signed in to change notification settings - Fork 13
/
message.go
56 lines (45 loc) · 1.16 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
package subscription_impl
import (
"github.com/glide-im/glide/pkg/messages"
"github.com/glide-im/glide/pkg/subscription"
)
const (
errUnknownMessageType = "unknown message type"
)
const (
typeUnknown = iota
// TypeNotify is the notification message type.
TypeNotify
// TypeMessage is the chat message type.
TypeMessage
// TypeSystem is the system message type.
TypeSystem
)
// PublishMessage is the message published to the channel.
type PublishMessage struct {
// From the message sender.
From subscription.SubscriberID
// To specified receiver, empty express all subscribers will be received.
To []subscription.SubscriberID
Seq int64
// Type the message type.
Type int
Message *messages.GlideMessage
}
func (p *PublishMessage) GetFrom() subscription.SubscriberID {
return p.From
}
func (p *PublishMessage) GetChatMessage() (*messages.ChatMessage, error) {
cm := &messages.ChatMessage{}
err := p.Message.Data.Deserialize(cm)
if err != nil {
return nil, err
}
return cm, nil
}
func IsUnknownMessageType(err error) bool {
return err.Error() == errUnknownMessageType
}
func isValidMessageType(t int) bool {
return t > typeUnknown && t <= TypeSystem
}