|
|
|
@ -39,12 +39,41 @@ const ( |
|
|
|
|
NotificationCertRejected = "cert_rejected" |
|
|
|
|
NotificationCertApproved = "cert_approved" |
|
|
|
|
NotificationPrivatePhoto = "private_photo" |
|
|
|
|
NotificationNewPhoto = "new_photo" |
|
|
|
|
NotificationCustom = "custom" // custom message pushed
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// CreateNotification
|
|
|
|
|
func CreateNotification(n *Notification) error { |
|
|
|
|
return DB.Create(n).Error |
|
|
|
|
// Insert via raw SQL query, reasoning:
|
|
|
|
|
// the AboutUser relationship has gorm do way too much work:
|
|
|
|
|
// - Upsert the user profile photo
|
|
|
|
|
// - Upsert the user profile fields
|
|
|
|
|
// - Upsert the user row itself
|
|
|
|
|
// .. and if we notify all your friends, all these wasteful queries ran
|
|
|
|
|
// for every single notification created!
|
|
|
|
|
if n.AboutUserID == nil && n.AboutUser.ID > 0 { |
|
|
|
|
n.AboutUserID = &n.AboutUser.ID |
|
|
|
|
} |
|
|
|
|
return DB.Exec( |
|
|
|
|
` |
|
|
|
|
INSERT INTO notifications |
|
|
|
|
(user_id, about_user_id, type, read, table_name, table_id, message, link, created_at, updated_at) |
|
|
|
|
VALUES |
|
|
|
|
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
|
|
|
|
`, |
|
|
|
|
n.UserID, |
|
|
|
|
n.AboutUserID, |
|
|
|
|
n.Type, |
|
|
|
|
false, |
|
|
|
|
n.TableName, |
|
|
|
|
n.TableID, |
|
|
|
|
n.Message, |
|
|
|
|
n.Link, |
|
|
|
|
time.Now(), |
|
|
|
|
time.Now(), |
|
|
|
|
).Error |
|
|
|
|
// return DB.Create(n).Error
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetNotification by ID.
|
|
|
|
|