324 lines
12 KiB
Dart
324 lines
12 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
|
import 'package:flutter_openim_sdk/src/models/set_channel_member_info.dart';
|
|
|
|
import '../listener/channel_listener.dart';
|
|
import '../models/channel_info.dart';
|
|
|
|
class ChannelManager {
|
|
MethodChannel _channel;
|
|
late OnChannelListener listener;
|
|
|
|
ChannelManager(this._channel);
|
|
|
|
/// Channel relationship listener
|
|
Future setChannelListener(OnChannelListener listener) {
|
|
this.listener = listener;
|
|
return _channel.invokeMethod('setChannelListener', _buildParam({}));
|
|
}
|
|
|
|
/// Query channel member information
|
|
/// [channelID] Channel ID
|
|
/// [userIDList] List of user IDs
|
|
Future<List<ChannelMembersInfo>> getChannelMembersInfo({
|
|
required String channelID,
|
|
required List<String> userIDList,
|
|
String? operationID,
|
|
}) =>
|
|
_channel
|
|
.invokeMethod(
|
|
'getChannelMembersInfo',
|
|
_buildParam({
|
|
'channelID': channelID,
|
|
'userIDList': userIDList,
|
|
"operationID": Utils.checkOperationID(operationID),
|
|
}))
|
|
.then((value) =>
|
|
Utils.toList(value, (map) => ChannelMembersInfo.fromJson(map)));
|
|
|
|
/// Paginate and retrieve the channel member list
|
|
/// [channelID] Channel ID
|
|
/// [filter] Member filter (0: All, 1: Channel owner, 2: Administrator, 3: Regular member, 4: Admin + Regular member, 5: Channel owner + Admin)
|
|
/// [offset] Starting index
|
|
/// [count] Total count
|
|
Future<List<ChannelMembersInfo>> getChannelMemberList({
|
|
required String channelID,
|
|
int filter = 0,
|
|
int offset = 0,
|
|
int count = 0,
|
|
String? operationID,
|
|
}) =>
|
|
_channel
|
|
.invokeMethod(
|
|
'getChannelMemberList',
|
|
_buildParam({
|
|
'channelID': channelID,
|
|
'filter': filter,
|
|
'offset': offset,
|
|
'count': count,
|
|
'operationID': Utils.checkOperationID(operationID),
|
|
}))
|
|
.then((value) =>
|
|
Utils.toList(value, (map) => ChannelMembersInfo.fromJson(map)));
|
|
|
|
// /// Paginate and retrieve the channel member list as a map
|
|
// /// [channelID] Channel ID
|
|
// /// [filter] Member filter (0: All, 1: Channel owner, 2: Administrator, 3: Regular member, 4: Admin + Regular member, 5: Channel owner + Admin)
|
|
// /// [offset] Starting index
|
|
// /// [count] Total count
|
|
// Future<List<dynamic>> getChannelMemberListMap({
|
|
// required String channelID,
|
|
// int filter = 0,
|
|
// int offset = 0,
|
|
// int count = 0,
|
|
// String? operationID,
|
|
// }) =>
|
|
// _channel
|
|
// .invokeMethod(
|
|
// 'getChannelMemberList',
|
|
// _buildParam({
|
|
// 'channelID': channelID,
|
|
// 'filter': filter,
|
|
// 'offset': offset,
|
|
// 'count': count,
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toListMap(value));
|
|
|
|
// /// Query the list of joined channels
|
|
// Future<List<ChannelInfo>> getJoinedChannelList({String? operationID}) => _channel
|
|
// .invokeMethod(
|
|
// 'getJoinedChannelList',
|
|
// _buildParam({
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toList(value, (map) => ChannelInfo.fromJson(map)));
|
|
//
|
|
// Future<List<ChannelInfo>> getJoinedChannelListPage({String? operationID, int offset = 0, int count = 40}) => _channel
|
|
// .invokeMethod(
|
|
// 'getJoinedChannelListPage',
|
|
// _buildParam({
|
|
// 'offset': offset,
|
|
// 'count': count,
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toList(value, (map) => ChannelInfo.fromJson(map)));
|
|
|
|
// /// Query the list of joined channels
|
|
// Future<List<dynamic>> getJoinedChannelListMap({String? operationID}) =>
|
|
// _channel
|
|
// .invokeMethod(
|
|
// 'getJoinedChannelList',
|
|
// _buildParam({
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toListMap(value));
|
|
|
|
/// Check if the user has joined a channel
|
|
/// [channelID] Channel ID
|
|
Future<bool> isJoinedChannel({
|
|
required String channelID,
|
|
String? operationID,
|
|
}) =>
|
|
_channel
|
|
.invokeMethod(
|
|
'isJoinChannel',
|
|
_buildParam({
|
|
'channelID': channelID,
|
|
'operationID': Utils.checkOperationID(operationID),
|
|
}))
|
|
.then((value) => value == 'true' ? true : false);
|
|
|
|
/// Query channel information
|
|
Future<List<ChannelInfo>> getChannelsInfo({
|
|
required List<String> channelIDList,
|
|
String? operationID,
|
|
}) =>
|
|
_channel
|
|
.invokeMethod(
|
|
'getChannelsInfo',
|
|
_buildParam({
|
|
'channelIDList': channelIDList,
|
|
'operationID': Utils.checkOperationID(operationID),
|
|
}))
|
|
.then((value) =>
|
|
Utils.toList(value, (map) => ChannelInfo.fromJson(map)));
|
|
|
|
/// Apply to join a channel, requiring approval from an administrator or the channel.
|
|
/// [joinSource] 2: Invited, 3: Searched, 4: Using a QR code
|
|
Future<dynamic> joinChannel(
|
|
{required String channelID,
|
|
String? reason,
|
|
String? operationID,
|
|
int joinSource = 3,
|
|
String? ex}) =>
|
|
_channel.invokeMethod(
|
|
'joinChannel',
|
|
_buildParam({
|
|
'channelID': channelID,
|
|
'reason': reason,
|
|
'joinSource': joinSource,
|
|
'ex': ex,
|
|
'operationID': Utils.checkOperationID(operationID),
|
|
}));
|
|
|
|
/// Exit a channel
|
|
Future<dynamic> quitChannel({
|
|
required String channelID,
|
|
String? operationID,
|
|
}) =>
|
|
_channel.invokeMethod(
|
|
'quitChannel',
|
|
_buildParam({
|
|
'channelID': channelID,
|
|
'operationID': Utils.checkOperationID(operationID),
|
|
}));
|
|
|
|
//
|
|
// /// Query a channel
|
|
// /// [keywordList] Search keywords; currently, only one keyword is supported, and it cannot be empty.
|
|
// /// [isSearchChannelID] Whether to search by channel ID (Note: cannot set both to false at the same time); defaults to false if not set.
|
|
// /// [isSearchChannelName] Whether to search by channel name; defaults to false if not set.
|
|
// Future<List<ChannelInfo>> searchChannels({
|
|
// List<String> keywordList = const [],
|
|
// bool isSearchChannelID = false,
|
|
// bool isSearchChannelName = false,
|
|
// String? operationID,
|
|
// }) =>
|
|
// _channel
|
|
// .invokeMethod(
|
|
// 'searchChannels',
|
|
// _buildParam({
|
|
// 'searchParam': {
|
|
// 'keywordList': keywordList,
|
|
// 'isSearchChannelID': isSearchChannelID,
|
|
// 'isSearchChannelName': isSearchChannelName,
|
|
// },
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toList(value, (map) => ChannelInfo.fromJson(map)));
|
|
|
|
// /// Get a channel member list based on join time
|
|
// Future<List<ChannelMembersInfo>> getChannelMemberListByJoinTime({
|
|
// required String channelID,
|
|
// int offset = 0,
|
|
// int count = 0,
|
|
// int joinTimeBegin = 0,
|
|
// int joinTimeEnd = 0,
|
|
// List<String> filterUserIDList = const [],
|
|
// String? operationID,
|
|
// }) =>
|
|
// _channel
|
|
// .invokeMethod(
|
|
// 'getChannelMemberListByJoinTimeFilter',
|
|
// _buildParam({
|
|
// 'channelID': channelID,
|
|
// 'offset': offset,
|
|
// 'count': count,
|
|
// 'joinTimeBegin': joinTimeBegin,
|
|
// 'joinTimeEnd': joinTimeEnd,
|
|
// 'excludeUserIDList': filterUserIDList,
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toList(value, (map) => ChannelMembersInfo.fromJson(map)));
|
|
|
|
// /// Search for channel members
|
|
// /// [channelID] Channel ID
|
|
// /// [keywordList] Search keywords; currently, only one keyword is supported, and it cannot be empty.
|
|
// /// [isSearchUserID] Whether to search by member ID
|
|
// /// [isSearchMemberNickname] Whether to search by member nickname
|
|
// /// [offset] Start index
|
|
// /// [count] Total count to retrieve
|
|
// Future<List<ChannelMembersInfo>> searchChannelMembers({
|
|
// required String channelID,
|
|
// List<String> keywordList = const [],
|
|
// bool isSearchUserID = false,
|
|
// bool isSearchMemberNickname = false,
|
|
// int offset = 0,
|
|
// int count = 40,
|
|
// String? operationID,
|
|
// }) =>
|
|
// _channel
|
|
// .invokeMethod(
|
|
// 'searchChannelMembers',
|
|
// _buildParam({
|
|
// 'searchParam': {
|
|
// 'channelID': channelID,
|
|
// 'keywordList': keywordList,
|
|
// 'isSearchUserID': isSearchUserID,
|
|
// 'isSearchMemberNickname': isSearchMemberNickname,
|
|
// 'offset': offset,
|
|
// 'count': count,
|
|
// },
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toList(value, (map) => ChannelMembersInfo.fromJson(map)));
|
|
|
|
// /// Query a channel
|
|
// /// [channelID] Channel ID
|
|
// /// [keywordList] Search keyword, currently only supports searching with one keyword, and it cannot be empty
|
|
// /// [isSearchUserID] Whether to search member IDs with the keyword
|
|
// /// [isSearchMemberNickname] Whether to search member nicknames with the keyword
|
|
// /// [offset] Starting index
|
|
// /// [count] Total number to retrieve each time
|
|
// Future<List<dynamic>> searchChannelMembersListMap({
|
|
// required String channelID,
|
|
// List<String> keywordList = const [],
|
|
// bool isSearchUserID = false,
|
|
// bool isSearchMemberNickname = false,
|
|
// int offset = 0,
|
|
// int count = 40,
|
|
// String? operationID,
|
|
// }) =>
|
|
// _channel
|
|
// .invokeMethod(
|
|
// 'searchChannelMembers',
|
|
// _buildParam({
|
|
// 'searchParam': {
|
|
// 'channelID': channelID,
|
|
// 'keywordList': keywordList,
|
|
// 'isSearchUserID': isSearchUserID,
|
|
// 'isSearchMemberNickname': isSearchMemberNickname,
|
|
// 'offset': offset,
|
|
// 'count': count,
|
|
// },
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }))
|
|
// .then((value) => Utils.toListMap(value));
|
|
//
|
|
// /// Modify the ChannelMemberInfo ex field
|
|
// Future<dynamic> setChannelMemberInfo({
|
|
// required SetChannelMemberInfo channelMembersInfo,
|
|
// String? operationID,
|
|
// }) =>
|
|
// _channel.invokeMethod(
|
|
// 'setChannelMemberInfo',
|
|
// _buildParam({
|
|
// 'info': channelMembersInfo.toJson(),
|
|
// 'operationID': Utils.checkOperationID(operationID),
|
|
// }));
|
|
|
|
Future<dynamic> getUsersInChannel(
|
|
String channelID,
|
|
List<String> userIDs, {
|
|
String? operationID,
|
|
}) =>
|
|
_channel.invokeMethod(
|
|
'getUsersInChannel',
|
|
_buildParam({
|
|
'channelID': channelID,
|
|
'userIDs': userIDs,
|
|
'operationID': Utils.checkOperationID(operationID),
|
|
}));
|
|
|
|
static Map _buildParam(Map<String, dynamic> param) {
|
|
param["ManagerName"] = "channelManager";
|
|
param = Utils.cleanMap(param);
|
|
log('param: $param');
|
|
|
|
return param;
|
|
}
|
|
}
|