3
0

User/channel activity echoing service

This commit is contained in:
Denis Arh 2018-10-24 17:17:31 +02:00
parent 62fa9c4704
commit 2ec5934d2e
6 changed files with 32 additions and 0 deletions

View File

@ -32,4 +32,10 @@ type (
ChannelDelete struct {
ChannelID string `json:"id"`
}
// ChannelActivity is sent from the client when there is an activity on the channel...
ChannelActivity struct {
ChannelID uint64 `json:"ID,string"`
Kind string `json:"kind,omitempty"`
}
)

View File

@ -12,6 +12,8 @@ type Payload struct {
*ChannelViewRecord `json:"recordChannelView"`
*ChannelActivity `json:"channelActivity"`
// Get channel message history
*Messages `json:"messages"`

View File

@ -22,6 +22,13 @@ type (
UserID string `json:"userID"`
}
// ChannelActivity indicates where the activity is and who is active
ChannelActivity struct {
ID uint64 `json:"channelID,string"`
UserID uint64 `json:"userID,string"`
Kind string `json:"kind,omitempty"`
}
Channel struct {
// Channel to part (nil) for ALL channels
ID string `json:"ID"`
@ -49,6 +56,10 @@ func (p *ChannelPart) EncodeMessage() ([]byte, error) {
return json.Marshal(Payload{ChannelPart: p})
}
func (p *ChannelActivity) EncodeMessage() ([]byte, error) {
return json.Marshal(Payload{ChannelActivity: p})
}
func (p *Channel) EncodeMessage() ([]byte, error) {
return json.Marshal(Payload{Channel: p})
}

View File

@ -15,6 +15,8 @@ type (
*Channel `json:"channel,omitempty"`
*ChannelSet `json:"channels,omitempty"`
*ChannelActivity `json:"channelActivity,omitempty"`
*ChannelMember `json:"channelMember,omitempty"`
*ChannelMemberSet `json:"channelMembers,omitempty"`

View File

@ -39,6 +39,8 @@ func (s *Session) dispatch(raw []byte) error {
return s.channelUpdate(ctx, p.ChannelUpdate)
case p.ChannelViewRecord != nil:
return s.channelViewRecord(ctx, p.ChannelViewRecord)
case p.ChannelActivity != nil:
return s.channelActivity(ctx, p.ChannelActivity)
case p.Users != nil:
return s.userList(ctx, p.Users)

View File

@ -119,3 +119,12 @@ func (s *Session) channelViewRecord(ctx context.Context, p *incoming.ChannelView
return s.svc.ch.With(ctx).RecordView(channelID, userID, lastMessageID)
}
// Echoes received channel activity back to all subscribers
func (s *Session) channelActivity(ctx context.Context, p *incoming.ChannelActivity) error {
return s.sendToAllSubscribers(&outgoing.ChannelActivity{
ID: p.ChannelID,
UserID: auth.GetIdentityFromContext(ctx).Identity(),
Kind: p.Kind,
}, payload.Uint64toa(p.ChannelID))
}