add get highlight user tweets support

pull/354/head
Michael Li 1 year ago
parent 2bc16b232d
commit 2a7103abf0
No known key found for this signature in database

@ -414,28 +414,15 @@ func (s *tweetSrv) GetUserPostStars(userID int64, limit int, offset int) ([]*ms.
}
func (s *tweetSrv) ListUserStarTweets(user *cs.VistUser, limit int, offset int) (res []*ms.PostStar, total int64, err error) {
var userId int64
typ := user.RelTyp
if typ == cs.RelationSelf {
userId = user.UserId
} else {
user := &dbr.User{
Username: user.Username,
}
if user, err = user.Get(s.db); err != nil {
return
}
userId = user.ID
}
star := &dbr.PostStar{
UserID: userId,
UserID: user.UserId,
}
if total, err = star.Count(s.db, typ, &dbr.ConditionsT{}); err != nil {
if total, err = star.Count(s.db, user.RelTyp, &dbr.ConditionsT{}); err != nil {
return
}
res, err = star.List(s.db, &dbr.ConditionsT{
"ORDER": s.db.NamingStrategy.TableName("PostStar") + ".id DESC",
}, typ, limit, offset)
}, user.RelTyp, limit, offset)
return
}

@ -275,18 +275,35 @@ func (s *DaoServant) GetTweetList(conditions ms.ConditionsT, offset, limit int)
return posts, postFormated, err
}
func (s *DaoServant) RelationTypFrom(me *ms.User, username string) cs.RelationTyp {
func (s *DaoServant) RelationTypFrom(me *ms.User, username string) (res *cs.VistUser, err error) {
res = &cs.VistUser{
RelTyp: cs.RelationSelf,
Username: username,
}
// visit by self
if me != nil && me.Username == username {
res.UserId = me.ID
return
}
he, xerr := s.Ds.GetUserByUsername(username)
if xerr != nil || (he.Model != nil && he.ID <= 0) {
return nil, errors.New("get user failed with username: " + username)
}
res.UserId = he.ID
// visit by guest
if me == nil {
return cs.RelationGuest
res.RelTyp = cs.RelationGuest
return
}
// visit by admin/friend/other
if me.IsAdmin {
return cs.RelationAdmin
} else if me.Username == username {
return cs.RelationSelf
res.RelTyp = cs.RelationAdmin
} else if s.Ds.IsFriend(me.ID, he.ID) {
res.RelTyp = cs.RelationFriend
} else {
res.RelTyp = cs.RelationGuest
}
// TODO: other releation detect logic
// but return guest to all for now
return cs.RelationGuest
return
}
func NewBindAnyFn() func(c *gin.Context, obj any) mir.Error {

@ -62,43 +62,41 @@ func (s *looseSrv) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error)
}
func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (res *web.GetUserTweetsResp, err mir.Error) {
relTyp := s.RelationTypFrom(req.User, req.Username)
user, xerr := s.RelationTypFrom(req.User, req.Username)
if xerr != nil {
return nil, err
}
switch req.Style {
case web.UserPostsStyleComment:
res, err = s.getUserCommentTweets(req, relTyp)
res, err = s.getUserCommentTweets(req, user)
case web.UserPostsStyleHighlight:
res, err = s.getUserHighlightTweets(req, relTyp)
res, err = s.getUserPostTweets(req, user, true)
case web.UserPostsStyleMedia:
res, err = s.getUserMediaTweets(req, relTyp)
res, err = s.getUserMediaTweets(req, user)
case web.UserPostsStyleStar:
res, err = s.getUserStarTweets(req, relTyp)
res, err = s.getUserStarTweets(req, user)
case web.UserPostsStylePost:
fallthrough
default:
res, err = s.getUserPostTweets(req)
res, err = s.getUserPostTweets(req, user, false)
}
return
}
func (s *looseSrv) getUserCommentTweets(req *web.GetUserTweetsReq, relTyp cs.RelationTyp) (*web.GetUserTweetsResp, mir.Error) {
func (s *looseSrv) getUserCommentTweets(req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}
func (s *looseSrv) getUserHighlightTweets(req *web.GetUserTweetsReq, relTyp cs.RelationTyp) (*web.GetUserTweetsResp, mir.Error) {
func (s *looseSrv) getUserHighlightTweets(req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}
func (s *looseSrv) getUserMediaTweets(req *web.GetUserTweetsReq, relTyp cs.RelationTyp) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}
func (s *looseSrv) getSelfCommentTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
func (s *looseSrv) getUserMediaTweets(req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
@ -110,14 +108,7 @@ func (s *looseSrv) getSelfMediaTweets(req *web.GetUserTweetsReq) (*web.GetUserTw
return (*web.GetUserTweetsResp)(resp), nil
}
func (s *looseSrv) getUserStarTweets(req *web.GetUserTweetsReq, relTyp cs.RelationTyp) (*web.GetUserTweetsResp, mir.Error) {
user := &cs.VistUser{
Username: req.Username,
RelTyp: relTyp,
}
if relTyp == cs.RelationSelf {
user.UserId = req.User.ID
}
func (s *looseSrv) getUserStarTweets(req *web.GetUserTweetsReq, user *cs.VistUser) (*web.GetUserTweetsResp, mir.Error) {
stars, totalRows, err := s.Ds.ListUserStarTweets(user, req.PageSize, (req.Page-1)*req.PageSize)
if err != nil {
logrus.Errorf("Ds.GetUserPostStars err: %s", err)
@ -138,28 +129,26 @@ func (s *looseSrv) getUserStarTweets(req *web.GetUserTweetsReq, relTyp cs.Relati
return (*web.GetUserTweetsResp)(resp), nil
}
func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
other, xerr := s.GetUserProfile(&web.GetUserProfileReq{
BaseInfo: req.BaseInfo,
Username: req.Username,
})
if xerr != nil {
return nil, xerr
}
func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq, user *cs.VistUser, isHighlight bool) (*web.GetUserTweetsResp, mir.Error) {
visibilities := []core.PostVisibleT{core.PostVisitPublic}
if req.User != nil {
if req.User.ID == other.ID || req.User.IsAdmin {
switch user.RelTyp {
case cs.RelationAdmin, cs.RelationSelf:
visibilities = append(visibilities, core.PostVisitPrivate, core.PostVisitFriend)
} else if other.IsFriend {
case cs.RelationFriend:
visibilities = append(visibilities, core.PostVisitFriend)
}
case cs.RelationGuest:
fallthrough
default:
// nothing
}
conditions := ms.ConditionsT{
"user_id": other.ID,
"user_id": user.UserId,
"visibility IN ?": visibilities,
"ORDER": "latest_replied_on DESC",
}
if isHighlight {
conditions["is_essence"] = 1
}
_, posts, err := s.GetTweetList(conditions, (req.Page-1)*req.PageSize, req.PageSize)
if err != nil {
logrus.Errorf("s.GetTweetList err: %s", err)
@ -170,7 +159,6 @@ func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq) (*web.GetUserTwe
logrus.Errorf("s.GetPostCount err: %s", err)
return nil, web.ErrGetPostsFailed
}
resp := base.PageRespFrom(posts, req.Page, req.PageSize, totalRows)
return (*web.GetUserTweetsResp)(resp), nil
}

Loading…
Cancel
Save