github.com/glide-im/glide@v1.6.0/pkg/subscription/subscription_impl/message.go (about) 1 package subscription_impl 2 3 import ( 4 "github.com/glide-im/glide/pkg/messages" 5 "github.com/glide-im/glide/pkg/subscription" 6 ) 7 8 const ( 9 errUnknownMessageType = "unknown message type" 10 ) 11 12 const ( 13 typeUnknown = iota 14 15 // TypeNotify is the notification message type. 16 TypeNotify 17 18 // TypeMessage is the chat message type. 19 TypeMessage 20 21 // TypeSystem is the system message type. 22 TypeSystem 23 ) 24 25 // PublishMessage is the message published to the channel. 26 type PublishMessage struct { 27 // From the message sender. 28 From subscription.SubscriberID 29 // To specified receiver, empty express all subscribers will be received. 30 To []subscription.SubscriberID 31 Seq int64 32 // Type the message type. 33 Type int 34 Message *messages.GlideMessage 35 } 36 37 func (p *PublishMessage) GetFrom() subscription.SubscriberID { 38 return p.From 39 } 40 41 func (p *PublishMessage) GetChatMessage() (*messages.ChatMessage, error) { 42 cm := &messages.ChatMessage{} 43 err := p.Message.Data.Deserialize(cm) 44 if err != nil { 45 return nil, err 46 } 47 return cm, nil 48 } 49 50 func IsUnknownMessageType(err error) bool { 51 return err.Error() == errUnknownMessageType 52 } 53 54 func isValidMessageType(t int) bool { 55 return t > typeUnknown && t <= TypeSystem 56 }