@@ -0,0 +1,118 @@
|
||||
package commentser
|
||||
|
||||
import (
|
||||
"91porn-server/app/service/searcher"
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models/v/cmtmod"
|
||||
"91porn-server/models/v/usermod"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type VideoRes = searcher.VideoRes
|
||||
|
||||
type UserBInfo = usermod.BaseInfo
|
||||
|
||||
type Comment = cmtmod.Comment
|
||||
|
||||
type ReplyInfo struct {
|
||||
RUID uint64 `json:"rUID"` //回复者UID
|
||||
RName string `json:"rName"` //回复者名字
|
||||
RPortrait string `json:"rPortrait"` //回复者头像
|
||||
RContent string `json:"rContent"` //回复内容
|
||||
RTime time.Time `json:"rTime"` //回复时间
|
||||
RType cmtmod.CmtType `json:"rType"` //回复类型
|
||||
Video VideoRes `json:"video"` //视屏信息
|
||||
}
|
||||
|
||||
type ReplyPage struct {
|
||||
HasNext bool `json:"hasNext"`
|
||||
List []ReplyInfo `json:"list"`
|
||||
}
|
||||
|
||||
func ReplyPages(uid uint64, skip, limit int64) (ReplyPage, error) {
|
||||
limitEx := limit + 1
|
||||
cmtList, err := cmtmod.ListByPublisherID(skip, limitEx, uid)
|
||||
if err != nil {
|
||||
return ReplyPage{}, err
|
||||
}
|
||||
hasNext := false
|
||||
if len(cmtList) > int(limit) {
|
||||
hasNext = true
|
||||
cmtList = cmtList[:limit]
|
||||
}
|
||||
vids := make([]ObjectID, 0, len(cmtList))
|
||||
uids := make([]uint64, 0, len(cmtList))
|
||||
for _, v := range cmtList {
|
||||
vids = append(vids, v.ObjID) //视屏ID
|
||||
uids = append(uids, v.UserID)
|
||||
}
|
||||
var (
|
||||
wg = sync.WaitGroup{}
|
||||
videoResList []VideoRes
|
||||
userInfos []*UserBInfo
|
||||
)
|
||||
wg.Add(2)
|
||||
common.Go(func() {
|
||||
defer wg.Done()
|
||||
list, err := searcher.GetVideoResList(uid, vids)
|
||||
if err != nil {
|
||||
log.Error("commentser GetVideoResList faild", log.E(err))
|
||||
}
|
||||
videoResList = list
|
||||
})
|
||||
common.Go(func() {
|
||||
defer wg.Done()
|
||||
list, err := usermod.GetUsersBaseInfo(uids)
|
||||
if err != nil {
|
||||
log.Error("commentser GetUsersBaseInfo faild", log.E(err))
|
||||
}
|
||||
userInfos = list
|
||||
})
|
||||
wg.Wait()
|
||||
videoResMap := make(map[ObjectID]VideoRes, len(videoResList))
|
||||
for _, v := range videoResList {
|
||||
vidp := v.VideoInfo.ID
|
||||
if vidp != nil {
|
||||
videoResMap[*vidp] = v
|
||||
}
|
||||
}
|
||||
userInfoMap := make(map[uint64]*usermod.BaseInfo, len(userInfos))
|
||||
for _, v := range userInfos {
|
||||
userInfoMap[v.UID] = v
|
||||
}
|
||||
replyInfos := toReplyInfoList(cmtList, videoResMap, userInfoMap)
|
||||
return ReplyPage{
|
||||
hasNext,
|
||||
replyInfos,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toReplyInfoList(cmtList []Comment,
|
||||
videoResMap map[ObjectID]VideoRes,
|
||||
userInfoMap map[uint64]*usermod.BaseInfo,
|
||||
) []ReplyInfo {
|
||||
replyInfos := make([]ReplyInfo, 0, len(cmtList))
|
||||
for _, v := range cmtList {
|
||||
userInfo, ok := userInfoMap[v.UserID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
videoRes, ok := videoResMap[v.ObjID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
replyInfo := ReplyInfo{
|
||||
RUID: userInfo.UID,
|
||||
RName: userInfo.Name,
|
||||
RPortrait: userInfo.Portrait,
|
||||
RContent: v.Content,
|
||||
RType: v.Type,
|
||||
RTime: v.CreatedAt,
|
||||
Video: videoRes,
|
||||
}
|
||||
replyInfos = append(replyInfos, replyInfo)
|
||||
}
|
||||
return replyInfos
|
||||
}
|
||||
Reference in New Issue
Block a user