diable create tags and new private message to other when post is private visibility

pull/106/head
alimy 3 years ago
parent 019304dea0
commit e6cbb15735

@ -84,8 +84,13 @@ func (p *PostContentItem) Check() error {
return nil return nil
} }
// CreatePost 创建文章
// TODO: maybe have bug need optimize for use transaction to create post
func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Post, error) { func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Post, error) {
ip := c.ClientIP() ip := c.ClientIP()
if len(ip) == 0 {
ip = "未知"
}
post := &model.Post{ post := &model.Post{
UserID: userID, UserID: userID,
@ -100,15 +105,6 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
return nil, err return nil, err
} }
// 创建标签
for _, t := range param.Tags {
tag := &model.Tag{
UserID: userID,
Tag: t,
}
ds.CreateTag(tag)
}
for _, item := range param.Contents { for _, item := range param.Contents {
if err = item.Check(); err != nil { if err = item.Check(); err != nil {
// 属性非法 // 属性非法
@ -127,27 +123,43 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
Type: item.Type, Type: item.Type,
Sort: item.Sort, Sort: item.Sort,
} }
ds.CreatePostContent(postContent) if _, err := ds.CreatePostContent(postContent); err != nil {
return nil, err
}
} }
// 推送Search // TODO: 目前非私密文章才能有如下操作,后续再优化
go PushPostToSearch(post) if post.Visibility != model.PostVisitPrivate {
// 创建标签
// 创建用户消息提醒 for _, t := range param.Tags {
for _, u := range param.Users { tag := &model.Tag{
user, err := ds.GetUserByUsername(u) UserID: userID,
if err != nil || user.ID == userID { Tag: t,
continue }
if _, err := ds.CreateTag(tag); err != nil {
return nil, err
}
} }
// 创建用户消息提醒
for _, u := range param.Users {
user, err := ds.GetUserByUsername(u)
if err != nil || user.ID == userID {
continue
}
// 创建消息提醒 // 创建消息提醒
go ds.CreateMessage(&model.Message{ // TODO: 优化消息提醒处理机制
SenderUserID: userID, go ds.CreateMessage(&model.Message{
ReceiverUserID: user.ID, SenderUserID: userID,
Type: model.MESSAGE_POST, ReceiverUserID: user.ID,
Brief: "在新发布的泡泡动态中@了你", Type: model.MESSAGE_POST,
PostID: post.ID, Brief: "在新发布的泡泡动态中@了你",
}) PostID: post.ID,
})
}
// 推送Search
// TODO: 优化推送文章到搜索的处理机制最好使用通道channel传递文章可以省goroutine
go PushPostToSearch(post)
} }
return post, nil return post, nil

Loading…
Cancel
Save