From 50f2d88abc68aaa8473a88928bef156a2e9389ed Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 6 Apr 2024 23:04:53 +0800 Subject: [PATCH] :bug: Fix notify and others --- pkg/server/calls_api.go | 2 +- pkg/services/calls.go | 7 ++++--- pkg/services/messages.go | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/server/calls_api.go b/pkg/server/calls_api.go index 190b41f..fd280b4 100644 --- a/pkg/server/calls_api.go +++ b/pkg/server/calls_api.go @@ -130,7 +130,7 @@ func exchangeCallToken(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusNotFound, err.Error()) } - tk, err := services.EncodeCallToken(call, user) + tk, err := services.EncodeCallToken(user) if err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } else { diff --git a/pkg/services/calls.go b/pkg/services/calls.go index 6bad367..2ed1e9a 100644 --- a/pkg/services/calls.go +++ b/pkg/services/calls.go @@ -83,12 +83,13 @@ func NewCall(channel models.Channel, founder models.ChannelMember) (models.Call, } else if err = database.C.Where(models.ChannelMember{ ChannelID: call.ChannelID, }).Preload("Account").Find(&members).Error; err == nil { + channel := call.Channel 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", call.Channel.Alias), + fmt.Sprintf("New Call #%s", channel.Alias), fmt.Sprintf("%s starts a new call", call.Founder.Account.Name), false, ) @@ -128,7 +129,7 @@ func EndCall(call models.Call) (models.Call, error) { return call, nil } -func EncodeCallToken(call models.Call, user models.Account) (string, error) { +func EncodeCallToken(user models.Account) (string, error) { // Jitsi requires HS256 as algorithm, so we cannot use HS512 tk := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ "context": jwt.MapClaims{ @@ -140,7 +141,7 @@ func EncodeCallToken(call models.Call, user models.Account) (string, error) { "aud": viper.GetString("meeting.client_id"), "iss": viper.GetString("domain"), "sub": "meet.jitsi", - "room": call.ExternalID, + "room": "*", }) return tk.SignedString([]byte(viper.GetString("meeting.client_secret"))) diff --git a/pkg/services/messages.go b/pkg/services/messages.go index d412e7b..9d98e2e 100644 --- a/pkg/services/messages.go +++ b/pkg/services/messages.go @@ -82,13 +82,14 @@ func NewMessage(message models.Message) (models.Message, error) { } else if err = database.C.Where(models.ChannelMember{ ChannelID: message.ChannelID, }).Preload("Account").Find(&members).Error; err == nil { + channel := message.Channel + message, _ = GetMessage(message.Channel, message.ID) for _, member := range members { - message, _ = GetMessage(message.Channel, message.ID) if member.ID != message.Sender.ID { // TODO Check the mentioned status if member.Notify == models.NotifyLevelAll { err = NotifyAccount(member.Account, - fmt.Sprintf("New Message #%s", message.Channel.Alias), + fmt.Sprintf("New Message #%s", channel.Alias), fmt.Sprintf("%s: %s", message.Sender.Account.Name, message.Content), true, )