@@ -47,6 +47,24 @@ func MySelfList(c *gin.Context) { | |||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
return | return | ||||
} | } | ||||
imUserIds := make([]int64, len(resp.List)) | |||||
for i, friendCircle := range resp.List { | |||||
imUserIds[i] = friendCircle.ImUid | |||||
} | |||||
nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
for _, friendCircle := range resp.List { | |||||
val, ok := nicknameAndAvatarMap[friendCircle.ImUid] | |||||
if ok { | |||||
friendCircle.ImNickname = val.NickName | |||||
friendCircle.ImAvatar = val.Avatar | |||||
} | |||||
} | |||||
resp.Page = args.Page | resp.Page = args.Page | ||||
resp.PageSize = args.PageSize | resp.PageSize = args.PageSize | ||||
e.OutSuc(c, resp, nil) | e.OutSuc(c, resp, nil) | ||||
@@ -189,6 +207,24 @@ func RecommendList(c *gin.Context) { | |||||
e.OutErr(c, e.ERR, err.Error()) | e.OutErr(c, e.ERR, err.Error()) | ||||
return | return | ||||
} | } | ||||
imUserIds := make([]int64, len(resp.List)) | |||||
for i, friendCircle := range resp.List { | |||||
imUserIds[i] = friendCircle.ImUid | |||||
} | |||||
nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
for _, friendCircle := range resp.List { | |||||
val, ok := nicknameAndAvatarMap[friendCircle.ImUid] | |||||
if ok { | |||||
friendCircle.ImNickname = val.NickName | |||||
friendCircle.ImAvatar = val.Avatar | |||||
} | |||||
} | |||||
e.OutSuc(c, resp, nil) | e.OutSuc(c, resp, nil) | ||||
} | } | ||||
@@ -6,10 +6,10 @@ type RecommendListReq struct { | |||||
} | } | ||||
type RecommendListResp struct { | type RecommendListResp struct { | ||||
Page int `json:"page"` // 页码 | |||||
PageSize int `json:"page_size"` // 每页数量 | |||||
Total int64 `json:"total"` // 总量 | |||||
List []EggFriendCircleEsStruct `json:"list"` | |||||
Page int `json:"page"` // 页码 | |||||
PageSize int `json:"page_size"` // 每页数量 | |||||
Total int64 `json:"total"` // 总量 | |||||
List []*EggFriendCircleEsStruct `json:"list"` | |||||
} | } | ||||
type CommentListReq struct { | type CommentListReq struct { | ||||
@@ -32,16 +32,18 @@ type MySelfListReq struct { | |||||
PageSize int `json:"page_size"` // 每页数量 | PageSize int `json:"page_size"` // 每页数量 | ||||
} | } | ||||
type MySelfListResp struct { | type MySelfListResp struct { | ||||
Page int `json:"page"` // 页码 | |||||
PageSize int `json:"page_size"` // 每页数量 | |||||
Total int64 `json:"total"` // 总量 | |||||
List []EggFriendCircleEsStruct `json:"list"` | |||||
Page int `json:"page"` // 页码 | |||||
PageSize int `json:"page_size"` // 每页数量 | |||||
Total int64 `json:"total"` // 总量 | |||||
List []*EggFriendCircleEsStruct `json:"list"` | |||||
} | } | ||||
type EggFriendCircleEsStruct struct { | type EggFriendCircleEsStruct struct { | ||||
CircleIndexId string `json:"circle_index_id"` //朋友圈文档记录 | CircleIndexId string `json:"circle_index_id"` //朋友圈文档记录 | ||||
Uid int64 `json:"uid" label:"uid"` | Uid int64 `json:"uid" label:"uid"` | ||||
ImUid int64 `json:"im_uid" label:"im_uid"` | ImUid int64 `json:"im_uid" label:"im_uid"` | ||||
ImNickname string `json:"im_nickname" label:"im_nickname"` | |||||
ImAvatar string `json:"im_avatar" label:"im_avatar"` | |||||
Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"` //类型(1:普通 2:官方) | Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"` //类型(1:普通 2:官方) | ||||
Content string `json:"content" label:"文本内容"` //文本内容 | Content string `json:"content" label:"文本内容"` //文本内容 | ||||
Image string `json:"image" label:"图片"` //图片 | Image string `json:"image" label:"图片"` //图片 | ||||
@@ -107,3 +109,8 @@ type EggFriendCircleLikeReq struct { | |||||
type EggFriendCircleCancelLikeReq struct { | type EggFriendCircleCancelLikeReq struct { | ||||
CircleIndexId string `json:"circle_index_id"` // 文章索引 | CircleIndexId string `json:"circle_index_id"` // 文章索引 | ||||
} | } | ||||
type ImUserNicknameAndAvatar struct { | |||||
NickName string `json:"nickname"` | |||||
Avatar string `json:"avatar"` | |||||
} |
@@ -130,7 +130,7 @@ func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_c | |||||
if likeDoc != nil && likeDoc.Found { // 表示已点赞 | if likeDoc != nil && likeDoc.Found { // 表示已点赞 | ||||
doc.IsLike = true | doc.IsLike = true | ||||
} | } | ||||
resp.List = append(resp.List, doc) | |||||
resp.List = append(resp.List, &doc) | |||||
} | } | ||||
resp.Total = searchResult.TotalHits() | resp.Total = searchResult.TotalHits() | ||||
@@ -170,7 +170,7 @@ func GetRecommendList(req friend_circles.RecommendListReq) (resp friend_circles. | |||||
return | return | ||||
} | } | ||||
doc.CircleIndexId = hit.Id | doc.CircleIndexId = hit.Id | ||||
resp.List = append(resp.List, doc) | |||||
resp.List = append(resp.List, &doc) | |||||
} | } | ||||
resp.Total = searchResult.TotalHits() | resp.Total = searchResult.TotalHits() | ||||
@@ -333,3 +333,22 @@ func DelFriendCircleComment(circleId string) (err error) { | |||||
} | } | ||||
return | return | ||||
} | } | ||||
func GetImUserNicknameAndAvatar(imUserIds []int64) (map[int64]friend_circles.ImUserNicknameAndAvatar, error) { | |||||
var imUsers []model.User | |||||
err := db.DbIm.In("id", imUserIds).Find(&imUsers) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
scheme, domain := svc.ImageBucket(db.Db) | |||||
info := make(map[int64]friend_circles.ImUserNicknameAndAvatar, len(imUsers)) | |||||
for _, user := range imUsers { | |||||
tempUrl := svc.ImageFormatWithBucket(scheme, domain, user.AvatarUrl) | |||||
temp := friend_circles.ImUserNicknameAndAvatar{ | |||||
NickName: user.Nickname, | |||||
Avatar: tempUrl, | |||||
} | |||||
info[user.Id] = temp | |||||
} | |||||
return info, nil | |||||
} |