import 'package:flutter/services.dart'; import 'package:flutter_openim_sdk/flutter_openim_sdk.dart'; class FriendshipManager { MethodChannel _channel; late OnFriendshipListener friendshipListener; FriendshipManager(this._channel); /// Set up a friend relationship listener /// 好友关系监听 Future setFriendshipListener(OnFriendshipListener listener) { this.friendshipListener = listener; return _channel.invokeMethod('setFriendListener', _buildParam({})); } /// Get friend info by user id /// 查询好友信息 Future> getFriendsInfo({ required List uidList, String? operationID, }) => _channel .invokeMethod( 'getFriendsInfo', _buildParam({ "uidList": uidList, "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v))); /// Send an friend application /// 发送一个好友请求 Future addFriend({ required String uid, String? reason, String? operationID, }) => _channel.invokeMethod( 'addFriend', _buildParam({ "toUserID": uid, "reqMsg": reason, "operationID": Utils.checkOperationID(operationID), })); /// Get someone's request to add me as a friend /// 获取别人加我为好友的申请 Future> getRecvFriendApplicationList( {String? operationID}) => _channel .invokeMethod( 'getRecvFriendApplicationList', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v))); /// Get friend requests from me /// 获取我发出的好友申请 Future> getSendFriendApplicationList( {String? operationID}) => _channel .invokeMethod( 'getSendFriendApplicationList', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v))); /// Find all friends including those who have been added to the blacklist /// 获取好友列表包含已拉入黑名单的好友 Future> getFriendList({String? operationID}) => _channel .invokeMethod( 'getFriendList', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v))); /// Find all friends including those who have been added to the blacklist /// 获取好友列表 Future> getFriendListMap({String? operationID}) => _channel .invokeMethod( 'getFriendList', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toListMap(value)); /// Modify friend remark name /// 设置好友备注 Future setFriendRemark({ required String uid, required String remark, String? operationID, }) => _channel.invokeMethod( 'setFriendRemark', _buildParam({ 'toUserID': uid, 'remark': remark, "operationID": Utils.checkOperationID(operationID), })); /// Add friends to blacklist /// 加入黑名单 Future addBlacklist({ required String uid, String? operationID, }) => _channel.invokeMethod( 'addBlacklist', _buildParam({ "uid": uid, "operationID": Utils.checkOperationID(operationID), })); /// Find all blacklist /// 获取黑名单列表 Future> getBlacklist({String? operationID}) => _channel .invokeMethod( 'getBlacklist', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v))); /// Remove from blacklist /// 从黑名单移除 Future removeBlacklist({ required String uid, String? operationID, }) => _channel.invokeMethod( 'removeBlacklist', _buildParam({ "uid": uid, "operationID": Utils.checkOperationID(operationID), })); /// Determine if there is a friendship by userId /// 检查友好关系 Future> checkFriend({ required List uidList, String? operationID, }) => _channel .invokeMethod( 'checkFriend', _buildParam({ 'uidList': uidList, "operationID": Utils.checkOperationID(operationID), })) .then((value) => Utils.toList(value, (v) => FriendshipInfo.fromJson(v))); /// Dissolve friendship from friend list /// 删除好友 Future deleteFriend({ required String uid, String? operationID, }) => _channel.invokeMethod( 'deleteFriend', _buildParam({ "uid": uid, "operationID": Utils.checkOperationID(operationID), })); /// Accept application of be friend /// 接受好友请求 Future acceptFriendApplication({ required String uid, String? handleMsg, String? operationID, }) => _channel.invokeMethod( 'acceptFriendApplication', _buildParam({ "toUserID": uid, "handleMsg": handleMsg, "operationID": Utils.checkOperationID(operationID), })); /// Refuse application of be friend /// 拒绝好友请求 Future refuseFriendApplication({ required String uid, String? handleMsg, String? operationID, }) => _channel.invokeMethod( 'refuseFriendApplication', _buildParam({ "toUserID": uid, "handleMsg": handleMsg, "operationID": Utils.checkOperationID(operationID), })); static Map _buildParam(Map param) { param["ManagerName"] = "friendshipManager"; return param; } }