From bc181ee9a236982f4fa52fa1498345eab9415276 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Fri, 26 Apr 2019 13:51:23 +0200 Subject: [PATCH] User list is no longer sent on ws connect --- internal/payload/outgoing.go | 14 +----------- internal/payload/outgoing/channel_member.go | 4 ++-- internal/payload/outgoing/payload.go | 3 --- internal/payload/outgoing/user.go | 23 +++++--------------- messaging/websocket/session.go | 20 ----------------- messaging/websocket/session_incoming.go | 3 --- messaging/websocket/session_incoming_user.go | 17 --------------- 7 files changed, 8 insertions(+), 76 deletions(-) delete mode 100644 messaging/websocket/session_incoming_user.go diff --git a/internal/payload/outgoing.go b/internal/payload/outgoing.go index f56169b6c..6eecf278b 100644 --- a/internal/payload/outgoing.go +++ b/internal/payload/outgoing.go @@ -40,7 +40,6 @@ func Message(ctx context.Context, msg *messagingTypes.Message) *outgoing.Message Replies: msg.Replies, RepliesFrom: Uint64stoa(msg.RepliesFrom), - User: User(msg.User), Attachment: Attachment(msg.Attachment, currentUserID), Mentions: messageMentionSet(msg.Mentions), Reactions: messageReactionSumSet(msg.Flags), @@ -174,7 +173,7 @@ func Channels(channels messagingTypes.ChannelSet) *outgoing.ChannelSet { func ChannelMember(m *messagingTypes.ChannelMember) *outgoing.ChannelMember { return &outgoing.ChannelMember{ - User: User(m.User), + UserID: m.UserID, Type: string(m.Type), CreatedAt: m.CreatedAt, UpdatedAt: m.UpdatedAt, @@ -229,17 +228,6 @@ func User(user *systemTypes.User) *outgoing.User { } } -func Users(users []*systemTypes.User) *outgoing.UserSet { - uu := make([]*outgoing.User, len(users)) - for k, u := range users { - uu[k] = User(u) - } - - retval := outgoing.UserSet(uu) - - return &retval -} - func Attachment(in *messagingTypes.Attachment, userID uint64) *outgoing.Attachment { if in == nil { return nil diff --git a/internal/payload/outgoing/channel_member.go b/internal/payload/outgoing/channel_member.go index 4475500d8..56e8d8401 100644 --- a/internal/payload/outgoing/channel_member.go +++ b/internal/payload/outgoing/channel_member.go @@ -8,8 +8,8 @@ import ( type ( ChannelMember struct { // Channel to part (nil) for ALL channels - User *User `json:"user"` - Type string `json:"type""` + UserID uint64 `json:"userID,string"` + Type string `json:"type"` CreatedAt time.Time `json:"createdAt"` UpdatedAt *time.Time `json:"updatedAt,omitempty"` } diff --git a/internal/payload/outgoing/payload.go b/internal/payload/outgoing/payload.go index 465468a85..cc7f452af 100644 --- a/internal/payload/outgoing/payload.go +++ b/internal/payload/outgoing/payload.go @@ -25,9 +25,6 @@ type ( *ChannelMember `json:"channelMember,omitempty"` *ChannelMemberSet `json:"channelMembers,omitempty"` - *User `json:"user,omitempty"` - *UserSet `json:"users,omitempty"` - *CommandSet `json:"commands,omitempty"` } diff --git a/internal/payload/outgoing/user.go b/internal/payload/outgoing/user.go index 132596a08..d9860bcf1 100644 --- a/internal/payload/outgoing/user.go +++ b/internal/payload/outgoing/user.go @@ -1,27 +1,14 @@ package outgoing -import ( - "encoding/json" -) - type ( User struct { // Channel to part (nil) for ALL channels - ID uint64 `json:"ID,string"` - Name string `json:"name"` - Email string `json:"email"` - Username string `json:"username"` - Handle string `json:"handle"` - Connections uint `json:"connections"` + ID uint64 `json:"ID,string"` + Name string `json:"name"` + Email string `json:"email"` + Username string `json:"username"` + Handle string `json:"handle"` } UserSet []*User ) - -func (p *User) EncodeMessage() ([]byte, error) { - return json.Marshal(Payload{User: p}) -} - -func (p *UserSet) EncodeMessage() ([]byte, error) { - return json.Marshal(Payload{UserSet: p}) -} diff --git a/messaging/websocket/session.go b/messaging/websocket/session.go index b880709e7..c101eb6e2 100644 --- a/messaging/websocket/session.go +++ b/messaging/websocket/session.go @@ -17,7 +17,6 @@ import ( "github.com/crusttech/crust/messaging/types" systemService "github.com/crusttech/crust/system/service" - systemTypes "github.com/crusttech/crust/system/types" ) type ( @@ -70,28 +69,9 @@ func (sess *Session) Context() context.Context { func (sess *Session) connected() (err error) { var ( - uu systemTypes.UserSet cc types.ChannelSet ) - // Push user info about all users we know... - if uu, err = systemService.User(sess.ctx).Find(nil); err != nil { - log.Printf("Error: %v", err) - } else { - userPayload := payload.Users(uu) - store.Walk(func(session *Session) { - for _, u := range *userPayload { - if u.ID == session.user.Identity() { - u.Connections++ - } - } - }) - - if err = sess.sendReply(userPayload); err != nil { - return - } - } - // Push user info about all channels he has access to... if cc, err = sess.svc.ch.With(sess.ctx).Find(&types.ChannelFilter{}); err != nil { log.Printf("Error: %v", err) diff --git a/messaging/websocket/session_incoming.go b/messaging/websocket/session_incoming.go index 1d11a7135..5508d0241 100644 --- a/messaging/websocket/session_incoming.go +++ b/messaging/websocket/session_incoming.go @@ -37,9 +37,6 @@ func (s *Session) dispatch(raw []byte) error { // @deprecated case p.ChannelViewRecord != nil: return s.channelViewRecord(ctx, p.ChannelViewRecord) - - case p.Users != nil: - return s.userList(ctx, p.Users) } return nil diff --git a/messaging/websocket/session_incoming_user.go b/messaging/websocket/session_incoming_user.go deleted file mode 100644 index a8890ff14..000000000 --- a/messaging/websocket/session_incoming_user.go +++ /dev/null @@ -1,17 +0,0 @@ -package websocket - -import ( - "context" - - "github.com/crusttech/crust/internal/payload" - "github.com/crusttech/crust/internal/payload/incoming" - systemService "github.com/crusttech/crust/system/service" -) - -func (s *Session) userList(ctx context.Context, p *incoming.Users) error { - users, err := systemService.User(ctx).Find(nil) - if err != nil { - return err - } - return s.sendReply(payload.Users(users)) -}