Notifying

This commit is contained in:
2024-03-31 21:37:13 +08:00
parent 3956547619
commit 9c7d0a167d
4 changed files with 7 additions and 3 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/viper"
)
func NotifyAccount(user models.Account, subject, content string, links ...*proto.NotifyLink) error {
func NotifyAccount(user models.Account, subject, content string, realtime bool, links ...*proto.NotifyLink) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
@ -21,6 +21,7 @@ func NotifyAccount(user models.Account, subject, content string, links ...*proto
Content: content,
Links: links,
RecipientId: uint64(user.ID),
IsRealtime: realtime,
IsImportant: false,
})

View File

@ -75,8 +75,9 @@ func NewMessage(message models.Message) (models.Message, error) {
return message, err
} else if err = database.C.Where(models.ChannelMember{
ChannelID: message.ChannelID,
}).Find(&members).Error; err == nil {
}).Preload("Account").Find(&members).Error; err == nil {
for _, member := range members {
_ = NotifyAccount(member.Account, "New message at "+message.Channel.Name, message.Content, true)
message, _ = GetMessage(message.Channel, message.ID)
PushCommand(member.AccountID, models.UnifiedCommand{
Action: "messages.new",