pull/54/head
sunface 4 years ago
parent 78f037f813
commit 9ac83c4292

@ -15,6 +15,7 @@ import Notifications from "components/notifications"
const filters = [ const filters = [
{icon: 'bell',label:'All',type: 0}, {icon: 'bell',label:'All',type: 0},
{icon: 'comments',label:'System',type: 7},
{icon: 'comments',label:'Comments',type: 1}, {icon: 'comments',label:'Comments',type: 1},
{icon: 'favorites',label:'Likes', type: 2}, {icon: 'favorites',label:'Likes', type: 2},
{icon: 'follow',label:'Follows', type: 5}, {icon: 'follow',label:'Follows', type: 5},

@ -6,6 +6,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/imdotdev/im.dev/server/internal/interaction" "github.com/imdotdev/im.dev/server/internal/interaction"
"github.com/imdotdev/im.dev/server/internal/notification"
"github.com/imdotdev/im.dev/server/internal/story"
"github.com/imdotdev/im.dev/server/internal/tags" "github.com/imdotdev/im.dev/server/internal/tags"
"github.com/imdotdev/im.dev/server/internal/user" "github.com/imdotdev/im.dev/server/internal/user"
"github.com/imdotdev/im.dev/server/pkg/common" "github.com/imdotdev/im.dev/server/pkg/common"
@ -210,6 +212,14 @@ func RemoveTagStory(c *gin.Context) {
return return
} }
s, err := story.GetStory(storyID, "")
if err == nil {
t, err := tags.GetTag(tagID, "")
if err == nil {
notification.Send(s.CreatorID, "", models.NotificationSystem, storyID, " delete your story from tag "+t.Name, user.ID)
}
}
c.JSON(http.StatusOK, common.RespSuccess(nil)) c.JSON(http.StatusOK, common.RespSuccess(nil))
} }

@ -66,9 +66,9 @@ func Follow(targetID string, userId string) *e.Error {
if !followed { if !followed {
if models.GetIDType(targetID) == models.IDTypeUser { if models.GetIDType(targetID) == models.IDTypeUser {
notification.Send(targetID, "", models.NotificationFollow, targetID, userId) notification.Send(targetID, "", models.NotificationFollow, targetID, " started following you", userId)
} else { } else {
notification.Send("", targetID, models.NotificationFollow, targetID, userId) notification.Send("", targetID, models.NotificationFollow, targetID, " started following you", userId)
} }
} }

@ -76,7 +76,13 @@ func Like(storyID string, userId string) *e.Error {
// send notification to story creator and owner // send notification to story creator and owner
creator, owner := models.GetStoryCreatorAndOrg(storyID) creator, owner := models.GetStoryCreatorAndOrg(storyID)
if creator != "" { if creator != "" {
notification.Send(creator, owner, models.NotificationLike, storyID, userId) var t string
if models.GetIDType(storyID) == models.IDTypeComment {
t = " liked your comment"
} else {
t = " liked your story"
}
notification.Send(creator, owner, models.NotificationLike, storyID, t, userId)
} }
} }
return nil return nil

@ -13,18 +13,18 @@ import (
var logger = log.RootLogger.New("logger", "notification") var logger = log.RootLogger.New("logger", "notification")
func Send(userID, orgID string, noType int, noID string, operatorID string) { func Send(userID, orgID string, noType int, noID string, noTitle string, operatorID string) {
if userID != "" { if userID != "" {
_, err := db.Conn.Exec("INSERT INTO user_notification (user_id,operator_id,notifiable_type,notifiable_id,created) VALUES (?,?,?,?,?)", _, err := db.Conn.Exec("INSERT INTO user_notification (user_id,operator_id,notifiable_type,notifiable_id,no_title,created) VALUES (?,?,?,?,?,?)",
userID, operatorID, noType, noID, time.Now()) userID, operatorID, noType, noID, noTitle, time.Now())
if err != nil { if err != nil {
logger.Warn("send notification error", "error", err) logger.Warn("send notification error", "error", err)
} }
} }
if orgID != "" { if orgID != "" {
_, err := db.Conn.Exec("INSERT INTO org_notification (user_id,operator_id,notifiable_type,notifiable_id,created) VALUES (?,?,?,?,?)", _, err := db.Conn.Exec("INSERT INTO org_notification (user_id,operator_id,notifiable_type,notifiable_id,no_title,created) VALUES (?,?,?,?,?,?)",
orgID, operatorID, noType, noID, time.Now()) orgID, operatorID, noType, noID, noTitle, time.Now())
if err != nil && !e.IsErrUniqueConstraint(err) { if err != nil && !e.IsErrUniqueConstraint(err) {
logger.Warn("send notification error", "error", err) logger.Warn("send notification error", "error", err)
} }
@ -37,11 +37,11 @@ func Query(user *models.User, tp int, page int) ([]*models.Notification, *e.Erro
var rows *sql.Rows var rows *sql.Rows
var err error var err error
if tp == 0 { if tp == 0 {
rows, err = db.Conn.Query("SELECT operator_id,notifiable_type,notifiable_id,read,created FROM user_notification WHERE user_id=? ORDER BY created DESC LIMIT ?,?", user.ID, (page-1)*perPage, page*perPage) rows, err = db.Conn.Query("SELECT operator_id,notifiable_type,notifiable_id,no_title,read,created FROM user_notification WHERE user_id=? ORDER BY created DESC LIMIT ?,?", user.ID, (page-1)*perPage, page*perPage)
} else if tp == models.NotificationComment { } else if tp == models.NotificationComment {
rows, err = db.Conn.Query("SELECT operator_id,notifiable_type,notifiable_id,read,created FROM user_notification WHERE user_id=? and notifiable_type in ('1','6') ORDER BY created DESC LIMIT ?,?", user.ID, (page-1)*perPage, page*perPage) rows, err = db.Conn.Query("SELECT operator_id,notifiable_type,notifiable_id,no_title,read,created FROM user_notification WHERE user_id=? and notifiable_type in ('1','6') ORDER BY created DESC LIMIT ?,?", user.ID, (page-1)*perPage, page*perPage)
} else { } else {
rows, err = db.Conn.Query("SELECT operator_id,notifiable_type,notifiable_id,read,created FROM user_notification WHERE user_id=? and notifiable_type=? ORDER BY created DESC LIMIT ?,?", user.ID, tp, (page-1)*perPage, page*perPage) rows, err = db.Conn.Query("SELECT operator_id,notifiable_type,notifiable_id,no_title,read,created FROM user_notification WHERE user_id=? and notifiable_type=? ORDER BY created DESC LIMIT ?,?", user.ID, tp, (page-1)*perPage, page*perPage)
} }
if err != nil { if err != nil {
@ -56,7 +56,8 @@ func Query(user *models.User, tp int, page int) ([]*models.Notification, *e.Erro
var noID string var noID string
var read bool var read bool
var created time.Time var created time.Time
err := rows.Scan(&operatorID, &noType, &noID, &read, &created) var title string
err := rows.Scan(&operatorID, &noType, &noID, &title, &read, &created)
if err != nil { if err != nil {
logger.Warn("scan notification", "error", err) logger.Warn("scan notification", "error", err)
continue continue
@ -65,34 +66,27 @@ func Query(user *models.User, tp int, page int) ([]*models.Notification, *e.Erro
operator := &models.UserSimple{ID: operatorID} operator := &models.UserSimple{ID: operatorID}
err = operator.Query() err = operator.Query()
no := &models.Notification{Created: created, Type: noType, User: operator, Read: read} no := &models.Notification{Created: created, Type: noType, User: operator, Read: read, Title: title}
switch no.Type { switch no.Type {
case models.NotificationComment: case models.NotificationComment, models.NotificationSystem:
no.Title = " commented on your story"
no.SubTitle = models.GetStoryTitle(noID) no.SubTitle = models.GetStoryTitle(noID)
no.StoryID = noID no.StoryID = noID
case models.NotificationReply: case models.NotificationReply:
no.Title = " replied to your comment"
no.SubTitle = models.GetStoryTitle(noID) no.SubTitle = models.GetStoryTitle(noID)
no.StoryID = noID no.StoryID = noID
case models.NotificationLike: case models.NotificationLike:
if models.GetIDType(noID) == models.IDTypeComment { if models.GetIDType(noID) == models.IDTypeComment {
no.Title = " liked your comment"
id := models.GetCommentStoryID(noID) id := models.GetCommentStoryID(noID)
if id != "" { if id != "" {
no.SubTitle = models.GetStoryTitle(id) no.SubTitle = models.GetStoryTitle(id)
no.StoryID = id no.StoryID = id
} }
} else { } else {
no.Title = " liked your story"
no.SubTitle = models.GetStoryTitle(noID) no.SubTitle = models.GetStoryTitle(noID)
no.StoryID = noID no.StoryID = noID
} }
case models.NotificationFollow:
no.Title = " started following you"
case models.NotificationPublish: case models.NotificationPublish:
no.Title = " published a new story"
no.SubTitle = models.GetStoryTitle(noID) no.SubTitle = models.GetStoryTitle(noID)
no.StoryID = noID no.StoryID = noID
} }

@ -264,6 +264,7 @@ var sqlTables = map[string]string{
operator_id VARCHAR(255), operator_id VARCHAR(255),
notifiable_type TINYINT, notifiable_type TINYINT,
notifiable_id VARCHAR(255), notifiable_id VARCHAR(255),
no_title VARCHAR(255),
read BOOL DEFAULT false, read BOOL DEFAULT false,
created DATETIME NOT NULL created DATETIME NOT NULL
); );
@ -277,6 +278,7 @@ var sqlTables = map[string]string{
operator_id VARCHAR(255), operator_id VARCHAR(255),
notifiable_type TINYINT, notifiable_type TINYINT,
notifiable_id VARCHAR(255), notifiable_id VARCHAR(255),
no_title VARCHAR(255),
read BOOL DEFAULT false, read BOOL DEFAULT false,
created DATETIME NOT NULL created DATETIME NOT NULL
); );

@ -63,10 +63,10 @@ func AddComment(c *models.Comment) *e.Error {
if creator != "" && creator != c.CreatorID { if creator != "" && creator != c.CreatorID {
if models.GetIDType(c.TargetID) == models.IDTypeComment { if models.GetIDType(c.TargetID) == models.IDTypeComment {
// reply // reply
notification.Send(creator, owner, models.NotificationReply, storyID, c.CreatorID) notification.Send(creator, owner, models.NotificationReply, storyID, " replied to your comment", c.CreatorID)
} else { } else {
// comment // comment
notification.Send(creator, owner, models.NotificationComment, storyID, c.CreatorID) notification.Send(creator, owner, models.NotificationComment, storyID, " commented on your story", c.CreatorID)
} }
} }

@ -127,7 +127,7 @@ func SubmitStory(c *gin.Context) (map[string]string, *e.Error) {
followers, err1 := interaction.GetFollowerIDs(post.CreatorID) followers, err1 := interaction.GetFollowerIDs(post.CreatorID)
if err1 == nil { if err1 == nil {
for _, f := range followers { for _, f := range followers {
notification.Send(f, "", models.NotificationPublish, post.ID, post.CreatorID) notification.Send(f, "", models.NotificationPublish, post.ID, " published a new story", post.CreatorID)
} }
} }
@ -135,7 +135,7 @@ func SubmitStory(c *gin.Context) (map[string]string, *e.Error) {
followers, err1 = interaction.GetFollowerIDs(post.OwnerID) followers, err1 = interaction.GetFollowerIDs(post.OwnerID)
if err1 == nil { if err1 == nil {
for _, f := range followers { for _, f := range followers {
notification.Send("", f, models.NotificationPublish, post.ID, post.CreatorID) notification.Send("", f, models.NotificationPublish, post.ID, " published a new story", post.CreatorID)
} }
} }
} }

@ -9,6 +9,7 @@ const (
NotificationPublish = 4 NotificationPublish = 4
NotificationFollow = 5 NotificationFollow = 5
NotificationReply = 6 NotificationReply = 6
NotificationSystem = 7
) )
type Notification struct { type Notification struct {

Loading…
Cancel
Save