User/channel activity echoing service
This commit is contained in:
parent
62fa9c4704
commit
2ec5934d2e
@ -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"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -12,6 +12,8 @@ type Payload struct {
|
||||
|
||||
*ChannelViewRecord `json:"recordChannelView"`
|
||||
|
||||
*ChannelActivity `json:"channelActivity"`
|
||||
|
||||
// Get channel message history
|
||||
*Messages `json:"messages"`
|
||||
|
||||
|
||||
@ -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})
|
||||
}
|
||||
|
||||
@ -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"`
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user