好友关系与黑名单 (Friendship & Blacklist)
好友关系模块支持好友列表查询、关键字搜索、添加好友、审批好友请求、修改备注、设置星标置顶好友以及黑名单管理。
1. 查询、搜索与校验好友
let client = QXJIMClient.shared
// 1. 获取全 部好友列表(filterBlack = true 自动过滤已拉黑用户)
let friends = try await client.getFriendList(filterBlack: true)
// 2. 分页获取好友列表
let pagedFriends = try await client.getFriendListPage(offset: 0, count: 50, filterBlack: true)
// 3. 获取指定 UserID 列表的好友信息
let specifiedFriends = try await client.getSpecifiedFriendsInfo(userIDs: ["u_1002", "u_1003"])
// 4. 本地搜索好友(按昵称、备注或 UserID)
let searchItems = try await client.searchFriends(
param: IMSearchFriendsParam(
keywordList: ["张"],
isSearchUserID: true,
isSearchNickname: true,
isSearchRemark: true
)
)
// 5. 批量检验是否为双向好友
let checkResults = try await client.checkFriend(userIDs: ["u_1002", "u_9999"])
for item in checkResults {
print("用户 \(item.userID) 是否为好友: \(item.isFriend)")
}
2. 添加好友与处理好友申请
// 1. 发起添加好友请求
try await client.addFriend(
request: IMAddFriendRequest(
toUserID: "u_2001",
reqMsg: "你好,我是王五"
)
)
// 2. 获取收到的好友申请列表 & 我发出的好友申请列表
let incomingRequests = try await client.getFriendApplicationListAsRecipient()
let outgoingRequests = try await client.getFriendApplicationListAsApplicant()
// 3. 同意或拒绝好友申请
try await client.acceptFriendApplication(toUserID: "u_2001", handleMsg: "很高兴认识你")
try await client.refuseFriendApplication(toUserID: "u_2002", handleMsg: "抱歉不认识")
3. 修改好友备注、置顶与删除好友
// 1. 修改好友备注
try await client.setFriendRemark(userID: "u_1002", remark: "张经理")
// 2. 设置星标/置顶好友
try await client.setFriendsPinned(userIDs: ["u_1002"], isPinned: true)
// 3. 删除好友
try await client.deleteFriend(friendUserID: "u_1002")
4. 黑名单管理
// 1. 将用户加入黑名单
try await client.addBlack(blackUserID: "u_3001")
// 2. 获取黑名单列表
let blackList = try await client.getBlackList()
// 3. 将用户移出黑名单
try await client.removeBlack(removeUserID: "u_3001")