create empty client, add function of collecting user unread messages on channels
This commit is contained in:
@@ -288,7 +288,7 @@ func HandleHubJoin(response http.ResponseWriter, request *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func HandleHubMessage(response http.ResponseWriter, request *http.Request) {
|
||||
func HandleHubChannelMessage(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(response, request, normal) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ func HandleUserNewToken(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user.ChannelUnreadMessage = make(map[uuid.UUID]uint8)
|
||||
|
||||
cache.SaveUser(user)
|
||||
|
||||
token, err := tokens.TokenCreate(user.Id)
|
||||
|
||||
+24
-13
@@ -27,19 +27,30 @@ func RandomRgba() Rgba {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Pronouns string `json:"pronouns"`
|
||||
Description string `json:"description"`
|
||||
AvatarKey string `json:"avatarType"`
|
||||
ProfileBgKey string `json:"profileBackgroundType"`
|
||||
PasswordHash string `json:"-"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
WsConn *websocket.Conn `json:"-"`
|
||||
Id uuid.UUID `json:"-"`
|
||||
Connections map[uuid.UUID]*Connection `json:"-"`
|
||||
Hubs map[uuid.UUID]*Hub `json:"hubs-to-delete"`
|
||||
Color Rgba `json:"color"`
|
||||
Mu sync.RWMutex `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Pronouns string `json:"pronouns"`
|
||||
Description string `json:"description"`
|
||||
AvatarKey string `json:"avatarType"`
|
||||
ProfileBgKey string `json:"profileBackgroundType"`
|
||||
PasswordHash string `json:"-"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
WsConn *websocket.Conn `json:"-"`
|
||||
Id uuid.UUID `json:"-"`
|
||||
Connections map[uuid.UUID]*Connection `json:"-"`
|
||||
Hubs map[uuid.UUID]*Hub `json:"hubs-to-delete"`
|
||||
ChannelUnreadMessage map[uuid.UUID]uint8 `json:"-"`
|
||||
Color Rgba `json:"color"`
|
||||
}
|
||||
|
||||
func (u *User) IncrementUnreadMessagesWithCap(channel uuid.UUID) {
|
||||
u.Mu.Lock()
|
||||
defer u.Mu.Unlock()
|
||||
|
||||
if u.ChannelUnreadMessage[channel] == uint8(math.MaxUint8) {
|
||||
return
|
||||
}
|
||||
u.ChannelUnreadMessage[channel]++
|
||||
}
|
||||
|
||||
type UserProfileUpdate struct {
|
||||
|
||||
@@ -106,6 +106,9 @@ func WsSendEventMessageToPermittedChannelUsersCloseIfTimeout(excluded uuid.UUID,
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if target.WsConn == nil {
|
||||
target.IncrementUnreadMessagesWithCap(channel.Id)
|
||||
}
|
||||
WsSendMessageCloseIfTimeout(target, message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user