err = NotifyAccountMessager(member.Account,fmt.Sprintf("%s started a new cal⬆️ Upgrade the Passport notify module

fmt.Sprintf("Call in #%s", channel.Alias),false,)if err != nil {
This commit is contained in:
2024-06-08 12:49:26 +08:00
parent 23450c0690
commit f29df2e531
5 changed files with 44 additions and 28 deletions

View File

@ -31,19 +31,20 @@ func GetAccountFriend(userId, relatedId uint, status int) (*proto.FriendshipResp
})
}
func NotifyAccount(user models.Account, subject, content string, realtime bool, links ...*proto.NotifyLink) error {
func NotifyAccountMessager(user models.Account, subject, content string, realtime bool, forcePush bool, links ...*proto.NotifyLink) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
_, err := grpc.Notify.NotifyUser(ctx, &proto.NotifyRequest{
ClientId: viper.GetString("identity.client_id"),
ClientSecret: viper.GetString("identity.client_secret"),
ClientId: viper.GetString("passport.client_id"),
ClientSecret: viper.GetString("passport.client_secret"),
Type: "notifications.messaging",
Subject: subject,
Content: content,
Links: links,
RecipientId: uint64(user.ExternalID),
IsRealtime: realtime,
IsImportant: false,
IsForcePush: forcePush,
})
return err

View File

@ -99,15 +99,14 @@ func NewCall(channel models.Channel, founder models.ChannelMember) (models.Call,
call, _ = GetCall(call.Channel, call.ID)
for _, member := range members {
if member.ID != call.Founder.ID {
if member.Notify == models.NotifyLevelAll {
err = NotifyAccount(member.Account,
fmt.Sprintf("New Call #%s", channel.Alias),
fmt.Sprintf("%s starts a new call", call.Founder.Account.Name),
false,
)
if err != nil {
log.Warn().Err(err).Msg("An error occurred when trying notify user.")
}
err = NotifyAccountMessager(member.Account,
fmt.Sprintf("Call in #%s", channel.Alias),
fmt.Sprintf("%s started a new call", call.Founder.Account.Name),
false,
true,
)
if err != nil {
log.Warn().Err(err).Msg("An error occurred when trying notify user.")
}
}
PushCommand(member.AccountID, models.UnifiedCommand{

View File

@ -90,15 +90,19 @@ func NewMessage(message models.Message) (models.Message, error) {
case models.NotifyLevelNone:
continue
case models.NotifyLevelMentioned:
if val, ok := message.Content["metioned_users"]; ok {
if member.ID == message.ReplyTo.SenderID {
break
}
if val, ok := message.Content["mentioned_users"]; ok {
if usernames, ok := val.([]string); ok {
if lo.Contains(usernames, member.Account.Name) {
break
}
}
}
continue
default:
break
}
var displayText string
@ -112,10 +116,11 @@ func NewMessage(message models.Message) (models.Message, error) {
displayText = fmt.Sprintf("%d attachment(s)", len(message.Attachments))
}
err = NotifyAccount(member.Account,
fmt.Sprintf("New Message #%s", channel.Alias),
fmt.Sprintf("%s: %s", message.Sender.Account.Name, displayText),
err = NotifyAccountMessager(member.Account,
fmt.Sprintf("%s in #%s", message.Sender.Account.Nick, channel.Alias),
fmt.Sprintf("%s", displayText),
true,
false,
)
if err != nil {
log.Warn().Err(err).Msg("An error occurred when trying notify user.")