🐛 Fix every use got same reply token
This commit is contained in:
parent
5fae613da5
commit
3d1c7e1bda
@ -105,7 +105,7 @@ func NewEvent(event models.Event) (models.Event, error) {
|
||||
event.Channel.Realm = &realm
|
||||
}
|
||||
}
|
||||
NotifyMessageEvent(members, event)
|
||||
go NotifyMessageEvent(members, event)
|
||||
}
|
||||
|
||||
return event, nil
|
||||
@ -180,7 +180,6 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
|
||||
}
|
||||
|
||||
displayTitle := fmt.Sprintf("%s (%s)", event.Sender.Nick, event.Channel.DisplayText())
|
||||
replyToken, err := CreateReplyToken(event.ID, event.Sender.AccountID)
|
||||
|
||||
metadata := map[string]any{
|
||||
"avatar": event.Sender.Avatar,
|
||||
@ -189,7 +188,6 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
|
||||
"user_nick": event.Sender.Nick,
|
||||
"channel_id": event.ChannelID,
|
||||
"event_id": event.ID,
|
||||
"reply_token": replyToken,
|
||||
}
|
||||
|
||||
if len(pendingUsers) > 0 {
|
||||
@ -199,16 +197,23 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
|
||||
Int("count", len(pendingUsers)).
|
||||
Msg("Notifying new event...")
|
||||
|
||||
err := authkit.NotifyUserBatch(
|
||||
for _, pendingUser := range pendingUsers {
|
||||
replyToken, err := CreateReplyToken(event.ID, uint(pendingUser))
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("An error occurred when trying create reply token.")
|
||||
continue
|
||||
}
|
||||
metadata["reply_token"] = replyToken
|
||||
err = authkit.NotifyUser(
|
||||
gap.Nx,
|
||||
pendingUsers,
|
||||
pendingUser,
|
||||
pushkit.Notification{
|
||||
Topic: "messaging.message",
|
||||
Title: displayTitle,
|
||||
Subtitle: displaySubtitle,
|
||||
Body: displayText,
|
||||
Metadata: metadata,
|
||||
Priority: 5,
|
||||
Priority: 10,
|
||||
},
|
||||
true,
|
||||
)
|
||||
@ -216,6 +221,7 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
|
||||
log.Warn().Err(err).Msg("An error occurred when trying notify user.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(mentionedUsers) > 0 {
|
||||
if len(displaySubtitle) > 0 {
|
||||
@ -230,16 +236,23 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
|
||||
Int("count", len(mentionedUsers)).
|
||||
Msg("Notifying new event...")
|
||||
|
||||
err := authkit.NotifyUserBatch(
|
||||
for _, mentionedUser := range mentionedUsers {
|
||||
replyToken, err := CreateReplyToken(event.ID, uint(mentionedUser))
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("An error occurred when trying create reply token.")
|
||||
continue
|
||||
}
|
||||
metadata["reply_token"] = replyToken
|
||||
err = authkit.NotifyUser(
|
||||
gap.Nx,
|
||||
mentionedUsers,
|
||||
mentionedUser,
|
||||
pushkit.Notification{
|
||||
Topic: "messaging.message",
|
||||
Title: displayTitle,
|
||||
Subtitle: displaySubtitle,
|
||||
Body: displayText,
|
||||
Metadata: metadata,
|
||||
Priority: 5,
|
||||
Priority: 10,
|
||||
},
|
||||
true,
|
||||
)
|
||||
@ -248,6 +261,7 @@ func NotifyMessageEvent(members []models.ChannelMember, event models.Event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func EditEvent(event models.Event) (models.Event, error) {
|
||||
if err := database.C.Save(&event).Error; err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user