create empty client, add function of collecting user unread messages on channels

This commit is contained in:
2026-05-09 21:40:59 +02:00
parent 53652d1f79
commit 6e3e27e63d
3367 changed files with 3200 additions and 1128383 deletions
+1 -1
View File
@@ -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
}
+2
View File
@@ -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
View File
@@ -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 {
+3
View File
@@ -106,6 +106,9 @@ func WsSendEventMessageToPermittedChannelUsersCloseIfTimeout(excluded uuid.UUID,
if err != nil {
continue
}
if target.WsConn == nil {
target.IncrementUnreadMessagesWithCap(channel.Id)
}
WsSendMessageCloseIfTimeout(target, message)
}
}