2024-02-01 07:08:40 +00:00
|
|
|
package models
|
|
|
|
|
2024-02-07 15:40:43 +00:00
|
|
|
import (
|
2024-10-31 13:26:25 +00:00
|
|
|
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
2024-06-02 12:15:04 +00:00
|
|
|
"gorm.io/datatypes"
|
2024-10-13 05:00:51 +00:00
|
|
|
"time"
|
2024-02-07 15:40:43 +00:00
|
|
|
)
|
2024-02-01 07:08:40 +00:00
|
|
|
|
|
|
|
type Notification struct {
|
|
|
|
BaseModel
|
|
|
|
|
2024-08-24 07:17:26 +00:00
|
|
|
Topic string `json:"topic"`
|
|
|
|
Title string `json:"title"`
|
2024-10-26 16:06:23 +00:00
|
|
|
Subtitle string `json:"subtitle"`
|
2024-08-24 07:17:26 +00:00
|
|
|
Body string `json:"body"`
|
|
|
|
Metadata datatypes.JSONMap `json:"metadata"`
|
2024-10-26 16:06:23 +00:00
|
|
|
Priority int `json:"priority"`
|
2024-08-24 07:17:26 +00:00
|
|
|
SenderID *uint `json:"sender_id"`
|
|
|
|
|
|
|
|
Account Account `json:"account"`
|
|
|
|
AccountID uint `json:"account_id"`
|
2024-07-15 16:02:28 +00:00
|
|
|
|
2024-10-13 05:00:51 +00:00
|
|
|
ReadAt *time.Time `json:"read_at"`
|
2024-10-31 13:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v Notification) EncodeToPushkit() pushkit.Notification {
|
|
|
|
return pushkit.Notification{
|
|
|
|
Topic: v.Topic,
|
|
|
|
Title: v.Title,
|
|
|
|
Subtitle: v.Subtitle,
|
|
|
|
Body: v.Body,
|
|
|
|
Metadata: v.Metadata,
|
|
|
|
Priority: v.Priority,
|
|
|
|
}
|
|
|
|
}
|
2024-10-13 05:00:51 +00:00
|
|
|
|
2024-10-31 13:26:25 +00:00
|
|
|
func NewNotificationFromPushkit(pk pushkit.Notification) Notification {
|
|
|
|
return Notification{
|
|
|
|
Topic: pk.Topic,
|
|
|
|
Title: pk.Title,
|
|
|
|
Subtitle: pk.Subtitle,
|
|
|
|
Body: pk.Body,
|
|
|
|
Metadata: pk.Metadata,
|
|
|
|
Priority: pk.Priority,
|
|
|
|
SenderID: nil,
|
|
|
|
}
|
2024-02-07 15:40:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-07 15:15:16 +00:00
|
|
|
const (
|
2024-06-06 14:48:43 +00:00
|
|
|
NotifySubscriberFirebase = "firebase"
|
2024-06-06 16:15:43 +00:00
|
|
|
NotifySubscriberAPNs = "apple"
|
2024-02-07 15:15:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type NotificationSubscriber struct {
|
|
|
|
BaseModel
|
|
|
|
|
2024-05-07 13:00:20 +00:00
|
|
|
UserAgent string `json:"user_agent"`
|
|
|
|
Provider string `json:"provider"`
|
|
|
|
DeviceID string `json:"device_id" gorm:"uniqueIndex"`
|
|
|
|
DeviceToken string `json:"device_token"`
|
2024-08-24 07:17:26 +00:00
|
|
|
|
|
|
|
Account Account `json:"account"`
|
|
|
|
AccountID uint `json:"account_id"`
|
2024-02-07 15:15:16 +00:00
|
|
|
}
|