3
0

User list is no longer sent on ws connect

This commit is contained in:
Denis Arh 2019-04-26 13:51:23 +02:00
parent b0239761f7
commit bc181ee9a2
7 changed files with 8 additions and 76 deletions

View File

@ -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

View File

@ -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"`
}

View File

@ -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"`
}

View File

@ -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})
}

View File

@ -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)

View File

@ -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

View File

@ -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))
}