commit 56b8cadd9aeb743f8d259a968908f7bfb697af7f parent fedaa3695cabaca6cb87e3beca8ba5698752d915 Author: n0tr1v <n0tr1v@protonmail.com> Date: Sat, 10 Jun 2023 06:30:07 -0700 cleanup Diffstat:
6 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/pkg/database/tableChatMessages.go b/pkg/database/tableChatMessages.go @@ -167,7 +167,7 @@ func (m *ChatMessage) UserCanSee(user User) bool { } } // msg user is not hb || own msg || msg user is hb & user is also hb || user can see and wish to see hb - return !m.User.IsHellbanned || user.ID == m.UserID || (m.User.IsHellbanned && user.IsHellbanned) || (user.CanSeeHB() && user.DisplayHellbanned) + return !m.User.IsHellbanned || m.OwnMessage(user) || (m.User.IsHellbanned && user.IsHellbanned) || (user.CanSeeHB() && user.DisplayHellbanned) } func (m *ChatMessage) DeleteSecondsRemaining() int64 { diff --git a/pkg/database/utils/processMessage.go b/pkg/database/utils/processMessage.go @@ -179,7 +179,7 @@ func GetQuoteTxt(db *database.DkfDB, roomKey string, quoted database.ChatMessage if err != nil { return } - if quoted.ToUserID != nil { + if quoted.IsPm() { if m := pmRgx.FindStringSubmatch(decrypted); len(m) == 3 { decrypted = m[2] } diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -247,7 +247,7 @@ func shouldPlaySound(authUser *database.User, lastKnownDate string, msgs []datab if strings.Contains(msg.Message, authUser.Username.AtStr()) { taggedSound = true } - if msg.ToUserID != nil && *msg.ToUserID == authUser.ID { + if msg.IsPmRecipient(*authUser) { pmSound = true } break diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go @@ -234,11 +234,8 @@ func handleGetQuote(db *database.DkfDB, msgUUID, roomKey string, room database.C // Build prefix for /m | /pm | /g | /hbm prefix := "" - if quoted.ToUserID != nil { - toUsername := quoted.User.Username - if quoted.UserID == authUser.ID { - toUsername = quoted.ToUser.Username - } + if quoted.IsPm() { + toUsername := utils.Ternary(quoted.OwnMessage(*authUser), quoted.ToUser.Username, quoted.User.Username) prefix = fmt.Sprintf(`/pm %s `, toUsername) } else if quoted.GroupID != nil { prefix = fmt.Sprintf(`/g %s `, quoted.Group.Name) diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5017,6 +5017,7 @@ func closeSignalChan(c echo.Context) <-chan struct{} { return ctx.Done() } +// Returns either or not authUser is allowed to see msg func verifyMsgAuth(db *database.DkfDB, authUser *database.User, msg *database.ChatMessage) bool { // Verify moderators channel authorization if msg.Moderators && !authUser.IsModerator() { @@ -5030,7 +5031,7 @@ func verifyMsgAuth(db *database.DkfDB, authUser *database.User, msg *database.Ch } } // verify PM authorization - if msg.ToUserID != nil { + if msg.IsPm() { if msg.UserID != authUser.ID && *msg.ToUserID != authUser.ID { return false } @@ -5339,7 +5340,7 @@ Loop: if strings.Contains(renderedMsg, authUser.Username.AtStr()) { taggedSound = true } - if msg.ToUserID != nil && msg.ToUser.ID == authUser.ID { + if msg.IsPmRecipient(*authUser) { pmSound = true } } diff --git a/pkg/web/handlers/interceptors/slashInterceptor.go b/pkg/web/handlers/interceptors/slashInterceptor.go @@ -1314,7 +1314,7 @@ func handleDeleteMsgCmd(c *command.Command) (handled bool) { if err := msg.UserCanDeleteErr(*c.AuthUser); err != nil { return err } - if msg.RoomID == config.GeneralRoomID && msg.ToUserID == nil { + if msg.RoomID == config.GeneralRoomID && !msg.IsPm() { msg.User.GeneralMessagesCount-- msg.User.DoSave(c.DB) }