🐛 Fix every use got same reply token

This commit is contained in:
LittleSheep 2024-12-21 22:00:31 +08:00
parent 5fae613da5
commit 3d1c7e1bda

View File

@ -105,7 +105,7 @@ func NewEvent(event models.Event) (models.Event, error) {
event.Channel.Realm = &realm event.Channel.Realm = &realm
} }
} }
NotifyMessageEvent(members, event) go NotifyMessageEvent(members, event)
} }
return event, nil return event, nil
@ -180,16 +180,14 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
} }
displayTitle := fmt.Sprintf("%s (%s)", event.Sender.Nick, event.Channel.DisplayText()) displayTitle := fmt.Sprintf("%s (%s)", event.Sender.Nick, event.Channel.DisplayText())
replyToken, err := CreateReplyToken(event.ID, event.Sender.AccountID)
metadata := map[string]any{ metadata := map[string]any{
"avatar": event.Sender.Avatar, "avatar": event.Sender.Avatar,
"user_id": event.Sender.AccountID, "user_id": event.Sender.AccountID,
"user_name": event.Sender.Name, "user_name": event.Sender.Name,
"user_nick": event.Sender.Nick, "user_nick": event.Sender.Nick,
"channel_id": event.ChannelID, "channel_id": event.ChannelID,
"event_id": event.ID, "event_id": event.ID,
"reply_token": replyToken,
} }
if len(pendingUsers) > 0 { if len(pendingUsers) > 0 {
@ -199,21 +197,29 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
Int("count", len(pendingUsers)). Int("count", len(pendingUsers)).
Msg("Notifying new event...") Msg("Notifying new event...")
err := authkit.NotifyUserBatch( for _, pendingUser := range pendingUsers {
gap.Nx, replyToken, err := CreateReplyToken(event.ID, uint(pendingUser))
pendingUsers, if err != nil {
pushkit.Notification{ log.Warn().Err(err).Msg("An error occurred when trying create reply token.")
Topic: "messaging.message", continue
Title: displayTitle, }
Subtitle: displaySubtitle, metadata["reply_token"] = replyToken
Body: displayText, err = authkit.NotifyUser(
Metadata: metadata, gap.Nx,
Priority: 5, pendingUser,
}, pushkit.Notification{
true, Topic: "messaging.message",
) Title: displayTitle,
if err != nil { Subtitle: displaySubtitle,
log.Warn().Err(err).Msg("An error occurred when trying notify user.") Body: displayText,
Metadata: metadata,
Priority: 10,
},
true,
)
if err != nil {
log.Warn().Err(err).Msg("An error occurred when trying notify user.")
}
} }
} }
@ -230,21 +236,29 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
Int("count", len(mentionedUsers)). Int("count", len(mentionedUsers)).
Msg("Notifying new event...") Msg("Notifying new event...")
err := authkit.NotifyUserBatch( for _, mentionedUser := range mentionedUsers {
gap.Nx, replyToken, err := CreateReplyToken(event.ID, uint(mentionedUser))
mentionedUsers, if err != nil {
pushkit.Notification{ log.Warn().Err(err).Msg("An error occurred when trying create reply token.")
Topic: "messaging.message", continue
Title: displayTitle, }
Subtitle: displaySubtitle, metadata["reply_token"] = replyToken
Body: displayText, err = authkit.NotifyUser(
Metadata: metadata, gap.Nx,
Priority: 5, mentionedUser,
}, pushkit.Notification{
true, Topic: "messaging.message",
) Title: displayTitle,
if err != nil { Subtitle: displaySubtitle,
log.Warn().Err(err).Msg("An error occurred when trying notify user.") Body: displayText,
Metadata: metadata,
Priority: 10,
},
true,
)
if err != nil {
log.Warn().Err(err).Msg("An error occurred when trying notify user.")
}
} }
} }
} }