Browse Source

fix: Compatibility missing IM account when return friend circle nickname and avatar

master
shenjiachi 2 days ago
parent
commit
d466a09dc3
3 changed files with 103 additions and 15 deletions
  1. +74
    -9
      app/hdl/friend_circle/hdl_friend_circle.go
  2. +1
    -1
      app/md/friend_circles/md_friend_circle.go
  3. +28
    -5
      app/svc/friend_circle/svc_firend_circle.go

+ 74
- 9
app/hdl/friend_circle/hdl_friend_circle.go View File

@@ -80,20 +80,43 @@ func MySelfList(c *gin.Context) {
return
}
imUserIds := make([]int64, len(resp.List))
var userIds []int64
for i, friendCircle := range resp.List {
imUserIds[i] = friendCircle.ImUid
if friendCircle.ImUid != 0 {
imUserIds[i] = friendCircle.ImUid
} else {
userIds[i] = friendCircle.Uid
}

}

nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
imNicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
// IM 未上线兼容朋友圈头像及昵称 使用 app 昵称头像替代
appNicknameAndAvatarMap := make(map[int64]friend_circles.FriendCircleNicknameAndAvatar)
if len(userIds) > 0 {
appNicknameAndAvatarMap, err = svc2.GetAppUserNickNameAndAvatar(userIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
}

for _, friendCircle := range resp.List {
val, ok := nicknameAndAvatarMap[friendCircle.ImUid]
val, ok := imNicknameAndAvatarMap[friendCircle.ImUid]
if ok {
friendCircle.ImNickname = val.NickName
friendCircle.ImAvatar = val.Avatar
} else {
// 获取不到就尝试获取 app 的昵称和头像
appVal, appOk := appNicknameAndAvatarMap[friendCircle.Uid]
if appOk {
friendCircle.ImNickname = appVal.NickName
friendCircle.ImAvatar = appVal.Avatar
}
}
}

@@ -168,6 +191,7 @@ func FriendCircleLikeList(c *gin.Context) {
}

var docs []*md.EggFriendCircleLikeEs
var docImUserIds []int64
var docUserIds []int64
var total int64
// 检查是否有结果
@@ -180,16 +204,29 @@ func FriendCircleLikeList(c *gin.Context) {
if err != nil {
return
}
docUserIds = append(docUserIds, like.ImUid)
if like.ImUid != 0 {
docImUserIds = append(docImUserIds, like.ImUid)
} else {
docUserIds = append(docUserIds, like.Uid)
}
docs = append(docs, &like)
}
}

nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(docUserIds)
imNicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(docImUserIds)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
// IM 未上线兼容朋友圈头像及昵称 使用 app 昵称头像替代
appNicknameAndAvatarMap := make(map[int64]friend_circles.FriendCircleNicknameAndAvatar)
if len(docUserIds) > 0 {
appNicknameAndAvatarMap, err = svc2.GetAppUserNickNameAndAvatar(docUserIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
}
var list []*friend_circles.FriendCircleLikeEsStruct
for _, like := range docs {
temp := friend_circles.FriendCircleLikeEsStruct{
@@ -197,10 +234,17 @@ func FriendCircleLikeList(c *gin.Context) {
ImUid: like.ImUid,
CircleId: like.CircleId,
}
val, ok := nicknameAndAvatarMap[like.ImUid]
val, ok := imNicknameAndAvatarMap[like.ImUid]
if ok {
temp.ImNickname = val.NickName
temp.ImAvatar = val.Avatar
} else {
// 获取不到就尝试获取 app 的昵称和头像
appVal, appOk := appNicknameAndAvatarMap[temp.Uid]
if appOk {
temp.ImNickname = appVal.NickName
temp.ImAvatar = appVal.Avatar
}
}
list = append(list, &temp)
}
@@ -314,20 +358,41 @@ func RecommendList(c *gin.Context) {
}

imUserIds := make([]int64, len(resp.List))
var userIds []int64
for i, friendCircle := range resp.List {
imUserIds[i] = friendCircle.ImUid
if friendCircle.ImUid != 0 {
imUserIds[i] = friendCircle.ImUid
} else {
userIds[i] = friendCircle.Uid
}
}

nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
imNicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
// IM 未上线兼容朋友圈头像及昵称 使用 app 昵称头像替代
appNicknameAndAvatarMap := make(map[int64]friend_circles.FriendCircleNicknameAndAvatar)
if len(userIds) > 0 {
appNicknameAndAvatarMap, err = svc2.GetAppUserNickNameAndAvatar(userIds)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
}
for _, friendCircle := range resp.List {
val, ok := nicknameAndAvatarMap[friendCircle.ImUid]
val, ok := imNicknameAndAvatarMap[friendCircle.ImUid]
if ok {
friendCircle.ImNickname = val.NickName
friendCircle.ImAvatar = val.Avatar
} else {
// 获取不到就尝试获取 app 的昵称和头像
appVal, appOk := appNicknameAndAvatarMap[friendCircle.Uid]
if appOk {
friendCircle.ImNickname = appVal.NickName
friendCircle.ImAvatar = appVal.Avatar
}
}
}
e.OutSuc(c, resp, nil)


+ 1
- 1
app/md/friend_circles/md_friend_circle.go View File

@@ -144,7 +144,7 @@ type EggFriendCircleCancelLikeReq struct {
CircleIndexId string `json:"circle_index_id"` // 文章索引
}

type ImUserNicknameAndAvatar struct {
type FriendCircleNicknameAndAvatar struct {
NickName string `json:"nickname"`
Avatar string `json:"avatar"`
}


+ 28
- 5
app/svc/friend_circle/svc_firend_circle.go View File

@@ -417,17 +417,40 @@ func DelFriendCircleComment(circleId string) (err error) {
return
}

func GetImUserNicknameAndAvatar(imUserIds []int64) (map[int64]friend_circles.ImUserNicknameAndAvatar, error) {
func GetImUserNicknameAndAvatar(imUserIds []int64) (map[int64]friend_circles.FriendCircleNicknameAndAvatar, 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{
info := make(map[int64]friend_circles.FriendCircleNicknameAndAvatar, len(imUsers))

for _, imUser := range imUsers {
tempUrl := svc.ImageFormatWithBucket(scheme, domain, imUser.AvatarUrl)
temp := friend_circles.FriendCircleNicknameAndAvatar{
NickName: imUser.Nickname,
Avatar: tempUrl,
}
info[imUser.Id] = temp
}
return info, nil
}

func GetAppUserNickNameAndAvatar(userIds []int64) (map[int64]friend_circles.FriendCircleNicknameAndAvatar, error) {
userDb := implement.NewUserDb(db.Db)
users, err := userDb.UserFindByParams(map[string]interface{}{
"key": "id",
"value": userIds,
})
if err != nil {
return nil, err
}
scheme, domain := svc.ImageBucket(db.Db)
info := make(map[int64]friend_circles.FriendCircleNicknameAndAvatar, len(users))
for _, user := range users {
tempUrl := svc.ImageFormatWithBucket(scheme, domain, user.Avatar)
temp := friend_circles.FriendCircleNicknameAndAvatar{
NickName: user.Nickname,
Avatar: tempUrl,
}


Loading…
Cancel
Save