2024-02-06 04:28:12 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.smartsheep.studio/hydrogen/passport/pkg/database"
|
|
|
|
"code.smartsheep.studio/hydrogen/passport/pkg/models"
|
|
|
|
)
|
|
|
|
|
2024-02-07 15:15:16 +00:00
|
|
|
func AddNotifySubscriber(user models.Account, provider, device, ua string) (models.NotificationSubscriber, error) {
|
|
|
|
subscriber := models.NotificationSubscriber{
|
|
|
|
UserAgent: ua,
|
|
|
|
Provider: provider,
|
|
|
|
DeviceID: ua,
|
|
|
|
AccountID: user.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := database.C.Save(&subscriber).Error
|
|
|
|
|
|
|
|
return subscriber, err
|
|
|
|
}
|
|
|
|
|
2024-02-06 04:28:12 +00:00
|
|
|
func NewNotification(user models.ThirdClient, target models.Account, subject, content string, important bool) error {
|
|
|
|
notification := models.Notification{
|
|
|
|
Subject: subject,
|
|
|
|
Content: content,
|
|
|
|
IsImportant: important,
|
|
|
|
ReadAt: nil,
|
|
|
|
SenderID: &user.ID,
|
|
|
|
RecipientID: target.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := database.C.Save(¬ification).Error; err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Notify all the listeners
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|