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,12 +123,23 @@ 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 {
tag := &model.Tag{
UserID: userID,
Tag: t,
}
if _, err := ds.CreateTag(tag); err != nil {
return nil, err
}
}
// 创建用户消息提醒 // 创建用户消息提醒
for _, u := range param.Users { for _, u := range param.Users {
user, err := ds.GetUserByUsername(u) user, err := ds.GetUserByUsername(u)
@ -141,6 +148,7 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
} }
// 创建消息提醒 // 创建消息提醒
// TODO: 优化消息提醒处理机制
go ds.CreateMessage(&model.Message{ go ds.CreateMessage(&model.Message{
SenderUserID: userID, SenderUserID: userID,
ReceiverUserID: user.ID, ReceiverUserID: user.ID,
@ -149,6 +157,10 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
PostID: post.ID, PostID: post.ID,
}) })
} }
// 推送Search
// TODO: 优化推送文章到搜索的处理机制最好使用通道channel传递文章可以省goroutine
go PushPostToSearch(post)
}
return post, nil return post, nil
} }

Loading…
Cancel
Save