fix: expose friend online status
This commit is contained in:
+14
-3
@@ -4463,7 +4463,7 @@ func serveIMFriends(wrt http.ResponseWriter, req *http.Request) {
|
||||
if item.Friendship.PeerID == principal.Uid {
|
||||
continue
|
||||
}
|
||||
payload = append(payload, friendListItemPayload(item))
|
||||
payload = append(payload, friendListItemPayload(principal.TenantID, principal.Uid, item))
|
||||
}
|
||||
writeIMSuccess(wrt, req, map[string]any{"items": payload, "next_cursor": nextCursor})
|
||||
}
|
||||
@@ -8967,13 +8967,20 @@ func friendRequestListItemPayload(item types.FriendRequestListItem) map[string]a
|
||||
return data
|
||||
}
|
||||
|
||||
func friendListItemPayload(item types.FriendListItem) map[string]any {
|
||||
func friendListItemPayload(tenantID types.TenantID, viewer types.Uid, item types.FriendListItem) map[string]any {
|
||||
online := false
|
||||
onlineVisibility := "hidden"
|
||||
if item.Friendship.Status == types.RelationshipFriend && imCanViewLastSeen(tenantID, viewer, item.Friendship.PeerID) {
|
||||
onlineVisibility = "visible"
|
||||
online = redisUserOnline(tenantID, item.Friendship.PeerID, false)
|
||||
}
|
||||
data := map[string]any{
|
||||
"user_id": item.Friendship.PeerID.UserId(),
|
||||
"relationship": item.Friendship.Status,
|
||||
"remark": item.Friendship.Remark,
|
||||
"topic": item.Friendship.Topic,
|
||||
"online_visibility": "unknown",
|
||||
"online": online,
|
||||
"online_visibility": onlineVisibility,
|
||||
"created_at": item.Friendship.CreatedAt.UTC().Format(time.RFC3339Nano),
|
||||
"updated_at": item.Friendship.UpdatedAt.UTC().Format(time.RFC3339Nano),
|
||||
"capabilities": map[string]any{"can_send": item.Friendship.Status == types.RelationshipFriend, "can_call": imCanCall(item.Friendship.Status == types.RelationshipFriend)},
|
||||
@@ -8990,6 +8997,10 @@ func friendListItemPayload(item types.FriendListItem) map[string]any {
|
||||
data[key] = value
|
||||
}
|
||||
}
|
||||
data["peer"] = userSummaryPayload(item.Peer, item.Friendship.Remark)
|
||||
if peer, ok := data["peer"].(map[string]any); ok {
|
||||
peer["online"] = online
|
||||
}
|
||||
}
|
||||
if item.Friendship.Remark == "" && data["display_name"] == data["user_id"] {
|
||||
data["display_name_source"] = "user_id"
|
||||
|
||||
Reference in New Issue
Block a user