mirror of https://github.com/sunface/rust-course
parent
af8c4e85bf
commit
0d3ef5505f
@ -0,0 +1,29 @@
|
|||||||
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/imdotdev/im.dev/server/pkg/db"
|
||||||
|
"github.com/imdotdev/im.dev/server/pkg/e"
|
||||||
|
"github.com/imdotdev/im.dev/server/pkg/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var logger = log.RootLogger.New("logger", "notification")
|
||||||
|
|
||||||
|
func Send(userID, orgID string, noType int, noID string, operatorID string) {
|
||||||
|
if userID != "" {
|
||||||
|
_, err := db.Conn.Exec("INSERT INTO user_notification (user_id,operator_id,notifiable_type,notifiable_id,created) VALUES (?,?,?,?,?)",
|
||||||
|
userID, operatorID, noType, noID, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
logger.Warn("send notification error", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if orgID != "" {
|
||||||
|
_, err := db.Conn.Exec("INSERT INTO org_notification (user_id,operator_id,notifiable_type,notifiable_id,created) VALUES (?,?,?,?,?)",
|
||||||
|
orgID, operatorID, noType, noID, time.Now())
|
||||||
|
if err != nil && !e.IsErrUniqueConstraint(err) {
|
||||||
|
logger.Warn("send notification error", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
const (
|
||||||
|
NotificationComment = 1
|
||||||
|
NotificationLike = 2
|
||||||
|
NotificationMention = 3
|
||||||
|
NotificationPublish = 4
|
||||||
|
NotificationFollow = 5
|
||||||
|
NotificationReply = 6
|
||||||
|
)
|
Loading…
Reference in new issue