|
|
@ -772,14 +772,14 @@ func (s *privSrv) createPostPreHandler(commentID int64, userID, atUserID int64)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Error) {
|
|
|
|
func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Error) {
|
|
|
|
// 加载Post
|
|
|
|
|
|
|
|
post, err := s.Ds.GetPostByID(postID)
|
|
|
|
post, err := s.Ds.GetPostByID(postID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerror.ServerError
|
|
|
|
return nil, xerror.ServerError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 私密post不可操作
|
|
|
|
// 私密post不可操作
|
|
|
|
if post.Visibility == core.PostVisitPrivate {
|
|
|
|
// TODO: 使用统一的permission checker来检查权限问题,这里好友可见post就没处理,是bug
|
|
|
|
|
|
|
|
if post.Visibility == core.PostVisitPrivate && post.UserID != userID {
|
|
|
|
return nil, _errNoPermission
|
|
|
|
return nil, _errNoPermission
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -794,45 +794,43 @@ func (s *privSrv) createPostStar(postID, userID int64) (*core.PostStar, mir.Erro
|
|
|
|
|
|
|
|
|
|
|
|
// 更新索引
|
|
|
|
// 更新索引
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
|
|
|
|
|
|
|
|
return star, nil
|
|
|
|
return star, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error {
|
|
|
|
func (s *privSrv) deletePostStar(star *core.PostStar) mir.Error {
|
|
|
|
err := s.Ds.DeletePostStar(star)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return xerror.ServerError
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 加载Post
|
|
|
|
|
|
|
|
post, err := s.Ds.GetPostByID(star.PostID)
|
|
|
|
post, err := s.Ds.GetPostByID(star.PostID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return xerror.ServerError
|
|
|
|
return xerror.ServerError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 私密post不可操作
|
|
|
|
// 私密post特殊处理
|
|
|
|
if post.Visibility == core.PostVisitPrivate {
|
|
|
|
// TODO: 使用统一的permission checker来检查权限问题,这里好友可见post就没处理,是bug
|
|
|
|
|
|
|
|
if post.Visibility == core.PostVisitPrivate && post.UserID != star.UserID {
|
|
|
|
return _errNoPermission
|
|
|
|
return _errNoPermission
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = s.Ds.DeletePostStar(star); err != nil {
|
|
|
|
|
|
|
|
return xerror.ServerError
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新Post点赞数
|
|
|
|
// 更新Post点赞数
|
|
|
|
post.UpvoteCount--
|
|
|
|
post.UpvoteCount--
|
|
|
|
s.Ds.UpdatePost(post)
|
|
|
|
s.Ds.UpdatePost(post)
|
|
|
|
|
|
|
|
|
|
|
|
// 更新索引
|
|
|
|
// 更新索引
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollection, mir.Error) {
|
|
|
|
func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollection, mir.Error) {
|
|
|
|
// 加载Post
|
|
|
|
|
|
|
|
post, err := s.Ds.GetPostByID(postID)
|
|
|
|
post, err := s.Ds.GetPostByID(postID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerror.ServerError
|
|
|
|
return nil, xerror.ServerError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 私密post不可操作
|
|
|
|
// 私密post特殊处理
|
|
|
|
if post.Visibility == core.PostVisitPrivate {
|
|
|
|
// TODO: 使用统一的permission checker来检查权限问题,这里好友可见post就没处理,是bug
|
|
|
|
|
|
|
|
if post.Visibility == core.PostVisitPrivate && post.UserID != userID {
|
|
|
|
return nil, _errNoPermission
|
|
|
|
return nil, _errNoPermission
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -847,25 +845,23 @@ func (s *privSrv) createPostCollection(postID, userID int64) (*core.PostCollecti
|
|
|
|
|
|
|
|
|
|
|
|
// 更新索引
|
|
|
|
// 更新索引
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
|
|
|
|
|
|
|
|
return collection, nil
|
|
|
|
return collection, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *privSrv) deletePostCollection(collection *core.PostCollection) mir.Error {
|
|
|
|
func (s *privSrv) deletePostCollection(collection *core.PostCollection) mir.Error {
|
|
|
|
err := s.Ds.DeletePostCollection(collection)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return xerror.ServerError
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 加载Post
|
|
|
|
|
|
|
|
post, err := s.Ds.GetPostByID(collection.PostID)
|
|
|
|
post, err := s.Ds.GetPostByID(collection.PostID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return xerror.ServerError
|
|
|
|
return xerror.ServerError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 私密post不可操作
|
|
|
|
// 私密post特殊处理
|
|
|
|
if post.Visibility == core.PostVisitPrivate {
|
|
|
|
// TODO: 使用统一的permission checker来检查权限问题,这里好友可见post就没处理,是bug
|
|
|
|
|
|
|
|
if post.Visibility == core.PostVisitPrivate && post.UserID != collection.UserID {
|
|
|
|
return _errNoPermission
|
|
|
|
return _errNoPermission
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = s.Ds.DeletePostCollection(collection); err != nil {
|
|
|
|
|
|
|
|
return xerror.ServerError
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新Post点赞数
|
|
|
|
// 更新Post点赞数
|
|
|
|
post.CollectionCount--
|
|
|
|
post.CollectionCount--
|
|
|
@ -873,7 +869,6 @@ func (s *privSrv) deletePostCollection(collection *core.PostCollection) mir.Erro
|
|
|
|
|
|
|
|
|
|
|
|
// 更新索引
|
|
|
|
// 更新索引
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
s.PushPostToSearch(post)
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|