🐛 Fix message notifying

This commit is contained in:
LittleSheep 2024-06-09 22:32:20 +08:00
parent f44a75d225
commit 40179a5557

View File

@ -85,16 +85,18 @@ func NewMessage(message models.Message) (models.Message, error) {
channel := message.Channel channel := message.Channel
message, _ = GetMessage(message.Channel, message.ID) message, _ = GetMessage(message.Channel, message.ID)
for _, member := range members { for _, member := range members {
doesNotify := true PushCommand(member.AccountID, models.UnifiedCommand{
if member.ID == message.SenderID { Action: "messages.new",
doesNotify = false Payload: message,
} else { })
if member.ID != message.SenderID {
switch member.Notify { switch member.Notify {
case models.NotifyLevelNone: case models.NotifyLevelNone:
doesNotify = false continue
case models.NotifyLevelMentioned: case models.NotifyLevelMentioned:
if member.ID == message.ReplyTo.SenderID { if member.ID == message.ReplyTo.SenderID {
break continue
} }
if val, ok := message.Content["mentioned_users"]; ok { if val, ok := message.Content["mentioned_users"]; ok {
if usernames, ok := val.([]string); ok { if usernames, ok := val.([]string); ok {
@ -103,13 +105,10 @@ func NewMessage(message models.Message) (models.Message, error) {
} }
} }
} }
doesNotify = false
default: default:
break break
} }
}
if doesNotify {
var displayText string var displayText string
if message.Content["algorithm"] == "plain" { if message.Content["algorithm"] == "plain" {
displayText, _ = message.Content["value"].(string) displayText, _ = message.Content["value"].(string)
@ -132,11 +131,6 @@ func NewMessage(message models.Message) (models.Message, error) {
log.Warn().Err(err).Msg("An error occurred when trying notify user.") log.Warn().Err(err).Msg("An error occurred when trying notify user.")
} }
} }
PushCommand(member.AccountID, models.UnifiedCommand{
Action: "messages.new",
Payload: message,
})
} }
} }