new version sdk
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
|
||||
///
|
||||
///
|
||||
class ConversationManager {
|
||||
MethodChannel _channel;
|
||||
late ConversationListener conversationListener;
|
||||
@@ -26,9 +22,10 @@ class ConversationManager {
|
||||
.invokeMethod(
|
||||
'getAllConversationList',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value));
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => ConversationInfo.fromJson(map)));
|
||||
|
||||
/// Paging to get conversation
|
||||
/// 分页获取会话
|
||||
@@ -43,9 +40,10 @@ class ConversationManager {
|
||||
_buildParam({
|
||||
'offset': offset,
|
||||
'count': count,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value));
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => ConversationInfo.fromJson(map)));
|
||||
|
||||
/// Get a conversation, if it doesn't exist it will be created automatically
|
||||
/// [sourceID] if it is a single chat, Its value is userID. if it is a group chat, Its value is groupID
|
||||
@@ -64,9 +62,10 @@ class ConversationManager {
|
||||
_buildParam({
|
||||
"sourceID": sourceID,
|
||||
"sessionType": sessionType,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) =>
|
||||
Utils.toObj(value, (map) => ConversationInfo.fromJson(map)));
|
||||
|
||||
/// Get conversation list by id list
|
||||
/// 获取多个会话
|
||||
@@ -79,9 +78,10 @@ class ConversationManager {
|
||||
'getMultipleConversation',
|
||||
_buildParam({
|
||||
"conversationIDList": conversationIDList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value));
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => ConversationInfo.fromJson(map)));
|
||||
|
||||
/// Delete conversation by id
|
||||
/// 删除会话
|
||||
@@ -89,14 +89,12 @@ class ConversationManager {
|
||||
required String conversationID,
|
||||
String? operationID,
|
||||
}) =>
|
||||
_channel
|
||||
.invokeMethod(
|
||||
'deleteConversation',
|
||||
_buildParam({
|
||||
"conversationID": conversationID,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _printValue(value));
|
||||
_channel.invokeMethod(
|
||||
'deleteConversation',
|
||||
_buildParam({
|
||||
"conversationID": conversationID,
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Set draft
|
||||
/// 设置会话草稿
|
||||
@@ -105,15 +103,13 @@ class ConversationManager {
|
||||
required String draftText,
|
||||
String? operationID,
|
||||
}) =>
|
||||
_channel
|
||||
.invokeMethod(
|
||||
'setConversationDraft',
|
||||
_buildParam({
|
||||
"conversationID": conversationID,
|
||||
"draftText": draftText,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _printValue(value));
|
||||
_channel.invokeMethod(
|
||||
'setConversationDraft',
|
||||
_buildParam({
|
||||
"conversationID": conversationID,
|
||||
"draftText": draftText,
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Pinned conversation
|
||||
/// 置顶会话
|
||||
@@ -122,18 +118,14 @@ class ConversationManager {
|
||||
required bool isPinned,
|
||||
String? operationID,
|
||||
}) =>
|
||||
_channel
|
||||
.invokeMethod(
|
||||
'pinConversation',
|
||||
_buildParam({
|
||||
"conversationID": conversationID,
|
||||
"isPinned": isPinned,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _printValue(value));
|
||||
_channel.invokeMethod(
|
||||
'pinConversation',
|
||||
_buildParam({
|
||||
"conversationID": conversationID,
|
||||
"isPinned": isPinned,
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Mark single chat messages as read
|
||||
/// 标记单聊已读
|
||||
// Future<dynamic> markSingleMessageHasRead({required String userID}) =>
|
||||
// _channel.invokeMethod(
|
||||
// 'markSingleMessageHasRead', _buildParam({'userID': userID}));
|
||||
@@ -148,7 +140,7 @@ class ConversationManager {
|
||||
'markGroupMessageHasRead',
|
||||
_buildParam({
|
||||
'groupID': groupID,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Get the total number of unread messages
|
||||
@@ -159,7 +151,7 @@ class ConversationManager {
|
||||
_channel.invokeMethod(
|
||||
'getTotalUnreadMsgCount',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Query conversation id
|
||||
@@ -180,9 +172,9 @@ class ConversationManager {
|
||||
}));
|
||||
|
||||
/// Message Do Not Disturb
|
||||
/// [status] 1: Do not receive messages. 2: Do not notify when messages are received. 0: Normal.
|
||||
/// [status] 0: Normal. 1: Do not receive messages. 2: Do not notify when messages are received.
|
||||
/// 消息免打扰设置
|
||||
/// [status] 1:不接受消息;2:接受在线消息不接受离线消息;3:正常
|
||||
/// [status] 0:正常;1:不接受消息;2:接受在线消息不接受离线消息;
|
||||
Future<dynamic> setConversationRecvMessageOpt({
|
||||
required List<String> conversationIDList,
|
||||
required int status,
|
||||
@@ -193,7 +185,7 @@ class ConversationManager {
|
||||
_buildParam({
|
||||
"conversationIDList": conversationIDList,
|
||||
"status": status,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Message Do Not Disturb
|
||||
@@ -208,12 +200,12 @@ class ConversationManager {
|
||||
'getConversationRecvMessageOpt',
|
||||
_buildParam({
|
||||
"conversationIDList": conversationIDList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _formatJson(value));
|
||||
.then((value) => Utils.toListMap(value));
|
||||
|
||||
/// Custom sort for conversation list
|
||||
/// 会话列表自定义排序规则
|
||||
/// 会话列表自定义排序规则。
|
||||
List<ConversationInfo> simpleSort(List<ConversationInfo> list) => list
|
||||
..sort((a, b) {
|
||||
if ((a.isPinned == true && b.isPinned == true) ||
|
||||
@@ -242,23 +234,4 @@ class ConversationManager {
|
||||
param["ManagerName"] = "conversationManager";
|
||||
return param;
|
||||
}
|
||||
|
||||
static List<ConversationInfo> _toList(String? value) {
|
||||
var list = _formatJson(value);
|
||||
if (null == list) return <ConversationInfo>[];
|
||||
return (list as List).map((e) => ConversationInfo.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
static ConversationInfo _toObj(String value) =>
|
||||
ConversationInfo.fromJson(_formatJson(value));
|
||||
|
||||
static dynamic _formatJson(value) => jsonDecode(_printValue(value));
|
||||
|
||||
static String _printValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
static String _checkOperationID(String? obj) {
|
||||
return obj ?? DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
|
||||
@@ -27,9 +25,9 @@ class FriendshipManager {
|
||||
'getFriendsInfo',
|
||||
_buildParam({
|
||||
"uidList": uidList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value, (v) => UserInfo.fromJson(v.cast())));
|
||||
.then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v)));
|
||||
|
||||
/// Send an friend application
|
||||
/// 发送一个好友请求
|
||||
@@ -43,7 +41,7 @@ class FriendshipManager {
|
||||
_buildParam({
|
||||
"toUserID": uid,
|
||||
"reqMsg": reason,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Get someone's request to add me as a friend
|
||||
@@ -54,10 +52,10 @@ class FriendshipManager {
|
||||
.invokeMethod(
|
||||
'getRecvFriendApplicationList',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) =>
|
||||
_toList(value, (v) => FriendApplicationInfo.fromJson(v.cast())));
|
||||
Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
|
||||
|
||||
/// Get friend requests from me
|
||||
/// 获取我发出的好友申请
|
||||
@@ -67,10 +65,10 @@ class FriendshipManager {
|
||||
.invokeMethod(
|
||||
'getSendFriendApplicationList',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) =>
|
||||
_toList(value, (v) => FriendApplicationInfo.fromJson(v.cast())));
|
||||
Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
|
||||
|
||||
/// Find all friends including those who have been added to the blacklist
|
||||
/// 获取好友列表包含已拉入黑名单的好友
|
||||
@@ -78,9 +76,9 @@ class FriendshipManager {
|
||||
.invokeMethod(
|
||||
'getFriendList',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value, (v) => UserInfo.fromJson(v.cast())));
|
||||
.then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v)));
|
||||
|
||||
/// Find all friends including those who have been added to the blacklist
|
||||
/// 获取好友列表
|
||||
@@ -88,11 +86,11 @@ class FriendshipManager {
|
||||
.invokeMethod(
|
||||
'getFriendList',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toListMap(value));
|
||||
.then((value) => Utils.toListMap(value));
|
||||
|
||||
/// Modify friend information, only [comment] can be modified
|
||||
/// Modify friend remark name
|
||||
/// 设置好友备注
|
||||
Future<dynamic> setFriendRemark({
|
||||
required String uid,
|
||||
@@ -104,7 +102,7 @@ class FriendshipManager {
|
||||
_buildParam({
|
||||
'toUserID': uid,
|
||||
'remark': remark,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Add friends to blacklist
|
||||
@@ -117,7 +115,7 @@ class FriendshipManager {
|
||||
'addBlacklist',
|
||||
_buildParam({
|
||||
"uid": uid,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Find all blacklist
|
||||
@@ -126,9 +124,9 @@ class FriendshipManager {
|
||||
.invokeMethod(
|
||||
'getBlacklist',
|
||||
_buildParam({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value, (v) => UserInfo.fromJson(v.cast())));
|
||||
.then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v)));
|
||||
|
||||
/// Remove from blacklist
|
||||
/// 从黑名单移除
|
||||
@@ -140,7 +138,7 @@ class FriendshipManager {
|
||||
'removeBlacklist',
|
||||
_buildParam({
|
||||
"uid": uid,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Determine if there is a friendship by userId
|
||||
@@ -154,10 +152,10 @@ class FriendshipManager {
|
||||
'checkFriend',
|
||||
_buildParam({
|
||||
'uidList': uidList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) =>
|
||||
_toList(value, (v) => FriendshipInfo.fromJson(v.cast())));
|
||||
Utils.toList(value, (v) => FriendshipInfo.fromJson(v)));
|
||||
|
||||
/// Dissolve friendship from friend list
|
||||
/// 删除好友
|
||||
@@ -169,7 +167,7 @@ class FriendshipManager {
|
||||
'deleteFriend',
|
||||
_buildParam({
|
||||
"uid": uid,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Accept application of be friend
|
||||
@@ -184,7 +182,7 @@ class FriendshipManager {
|
||||
_buildParam({
|
||||
"toUserID": uid,
|
||||
"handleMsg": handleMsg,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Refuse application of be friend
|
||||
@@ -199,49 +197,11 @@ class FriendshipManager {
|
||||
_buildParam({
|
||||
"toUserID": uid,
|
||||
"handleMsg": handleMsg,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
///
|
||||
// Future<dynamic> forceSyncFriendApplication() {
|
||||
// return _channel.invokeMethod('forceSyncFriendApplication', _buildParam({}));
|
||||
// }
|
||||
|
||||
///
|
||||
// Future<dynamic> forceSyncFriend() {
|
||||
// return _channel.invokeMethod('forceSyncFriend', _buildParam({}));
|
||||
// }
|
||||
|
||||
///
|
||||
// Future<dynamic> forceSyncBlackList() {
|
||||
// return _channel.invokeMethod('forceSyncBlackList', _buildParam({}));
|
||||
// }
|
||||
|
||||
static Map _buildParam(Map param) {
|
||||
param["ManagerName"] = "friendshipManager";
|
||||
return param;
|
||||
}
|
||||
|
||||
static List<T> _toList<T>(String? value, T f(Map map)) {
|
||||
var list = _formatJson(value);
|
||||
if (null == list) return <T>[];
|
||||
return (list as List).map((e) => f(e)).toList();
|
||||
}
|
||||
|
||||
static List<dynamic> _toListMap(String? value) {
|
||||
var list = _formatJson(value);
|
||||
return list;
|
||||
}
|
||||
|
||||
// static UserInfo _toObj(String value) => UserInfo.fromJson(_formatJson(value));
|
||||
|
||||
static dynamic _formatJson(value) => jsonDecode(_printValue(value));
|
||||
|
||||
static String _printValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
static String _checkOperationID(String? obj) {
|
||||
return obj ?? DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_openim_sdk/src/listener/group_listener.dart';
|
||||
import 'package:flutter_openim_sdk/src/models/group_info.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
|
||||
class GroupManager {
|
||||
MethodChannel _channel;
|
||||
@@ -32,11 +29,10 @@ class GroupManager {
|
||||
'gid': groupId,
|
||||
'reason': reason,
|
||||
'uidList': uidList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupInviteResult.fromJson(e))
|
||||
.toList());
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => GroupInviteResult.fromJson(map)));
|
||||
|
||||
/// Remove member from group
|
||||
/// 移除组成员
|
||||
@@ -53,11 +49,10 @@ class GroupManager {
|
||||
'gid': groupId,
|
||||
'reason': reason,
|
||||
'uidList': uidList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupInviteResult.fromJson(e))
|
||||
.toList());
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => GroupInviteResult.fromJson(map)));
|
||||
|
||||
/// Get group member's info
|
||||
/// 查询组成员资料
|
||||
@@ -72,11 +67,10 @@ class GroupManager {
|
||||
_buildParam({
|
||||
'gid': groupId,
|
||||
'uidList': uidList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupMembersInfo.fromJson(e))
|
||||
.toList());
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => GroupMembersInfo.fromJson(map)));
|
||||
|
||||
/// Get the list of group members
|
||||
/// 分页获取组成员列表
|
||||
@@ -95,15 +89,14 @@ class GroupManager {
|
||||
'filter': filter,
|
||||
'offset': offset,
|
||||
'count': count,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupMembersInfo.fromJson(e))
|
||||
.toList());
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => GroupMembersInfo.fromJson(map)));
|
||||
|
||||
/// Get the list of group members
|
||||
/// 分页获取组成员列表
|
||||
Future<dynamic> getGroupMemberListMap({
|
||||
Future<List<dynamic>> getGroupMemberListMap({
|
||||
required String groupId,
|
||||
int filter = 0,
|
||||
int offset = 0,
|
||||
@@ -118,9 +111,9 @@ class GroupManager {
|
||||
'filter': filter,
|
||||
'offset': offset,
|
||||
'count': count,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _formatJson(value));
|
||||
.then((value) => Utils.toListMap(value));
|
||||
|
||||
/// Find all groups you have joined
|
||||
/// 查询已加入的组列表
|
||||
@@ -128,11 +121,9 @@ class GroupManager {
|
||||
.invokeMethod(
|
||||
'getJoinedGroupList',
|
||||
_buildParam({
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupInfo.fromJson(e))
|
||||
.toList());
|
||||
.then((value) => Utils.toList(value, (map) => GroupInfo.fromJson(map)));
|
||||
|
||||
/// Find all groups you have joined
|
||||
/// 查询已加入的组列表
|
||||
@@ -140,9 +131,9 @@ class GroupManager {
|
||||
.invokeMethod(
|
||||
'getJoinedGroupList',
|
||||
_buildParam({
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _formatJson(value));
|
||||
.then((value) => Utils.toListMap(value));
|
||||
|
||||
/// Check if you are a member of the group
|
||||
/// 检查是否已加入组
|
||||
@@ -151,7 +142,7 @@ class GroupManager {
|
||||
String? operationID,
|
||||
}) =>
|
||||
getJoinedGroupList(
|
||||
operationID: _checkOperationID(operationID),
|
||||
operationID: Utils.checkOperationID(operationID),
|
||||
).then((list) => list.where((e) => e.groupID == gid).length > 0);
|
||||
|
||||
/// Create a group
|
||||
@@ -179,9 +170,10 @@ class GroupManager {
|
||||
"ex": ex,
|
||||
},
|
||||
'memberList': list.map((e) => e.toJson()).toList(),
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => GroupInfo.fromJson(_formatJson(value)));
|
||||
.then(
|
||||
(value) => Utils.toObj(value, (map) => GroupInfo.fromJson(map)));
|
||||
|
||||
/// Edit group information
|
||||
/// 编辑组资料
|
||||
@@ -206,7 +198,7 @@ class GroupManager {
|
||||
"faceURL": faceUrl,
|
||||
"ex": ex,
|
||||
},
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Find group information by group id
|
||||
@@ -220,12 +212,10 @@ class GroupManager {
|
||||
'getGroupsInfo',
|
||||
_buildParam({
|
||||
'gidList': gidList,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) {
|
||||
List list = _formatJson(value);
|
||||
return list.map((e) => GroupInfo.fromJson(e)).toList();
|
||||
});
|
||||
.then(
|
||||
(value) => Utils.toList(value, (map) => GroupInfo.fromJson(map)));
|
||||
|
||||
/// Apply to join the group
|
||||
/// 申请加入组,需要通过管理员同意。
|
||||
@@ -239,7 +229,7 @@ class GroupManager {
|
||||
_buildParam({
|
||||
'gid': gid,
|
||||
'reason': reason,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Leave group
|
||||
@@ -252,7 +242,7 @@ class GroupManager {
|
||||
'quitGroup',
|
||||
_buildParam({
|
||||
'gid': gid,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Give group permissions to others
|
||||
@@ -267,7 +257,7 @@ class GroupManager {
|
||||
_buildParam({
|
||||
'gid': gid,
|
||||
'uid': uid,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// As the group owner or administrator, get the list of received group members' applications to join the group.
|
||||
@@ -278,11 +268,10 @@ class GroupManager {
|
||||
.invokeMethod(
|
||||
'getRecvGroupApplicationList',
|
||||
_buildParam({
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupApplicationInfo.fromJson(e))
|
||||
.toList());
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => GroupApplicationInfo.fromJson(map)));
|
||||
|
||||
/// Get the record of the group membership application issued by yourself
|
||||
/// 获取自己发出的入群申请记录
|
||||
@@ -292,11 +281,10 @@ class GroupManager {
|
||||
.invokeMethod(
|
||||
'getSendGroupApplicationList',
|
||||
_buildParam({
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => (_formatJson(value) as List)
|
||||
.map((e) => GroupApplicationInfo.fromJson(e))
|
||||
.toList());
|
||||
.then((value) =>
|
||||
Utils.toList(value, (map) => GroupApplicationInfo.fromJson(map)));
|
||||
|
||||
/// Accept group application
|
||||
/// 管理员或者群主同意某人进入某群
|
||||
@@ -312,7 +300,7 @@ class GroupManager {
|
||||
'gid': gid,
|
||||
'uid': uid,
|
||||
'handleMsg': handleMsg,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Refuse group application
|
||||
@@ -329,41 +317,11 @@ class GroupManager {
|
||||
'gid': gid,
|
||||
'uid': uid,
|
||||
'handleMsg': handleMsg,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
///
|
||||
// Future forceSyncApplyGroupRequest() {
|
||||
// return _channel.invokeMethod('forceSyncApplyGroupRequest', _buildParam({}));
|
||||
// }
|
||||
|
||||
///
|
||||
// Future forceSyncGroupRequest() {
|
||||
// return _channel.invokeMethod('forceSyncGroupRequest', _buildParam({}));
|
||||
// }
|
||||
|
||||
///
|
||||
// Future forceSyncJoinedGroup() {
|
||||
// return _channel.invokeMethod('forceSyncJoinedGroup', _buildParam({}));
|
||||
// }
|
||||
|
||||
///
|
||||
// Future forceSyncJoinedGroupMember() {
|
||||
// return _channel.invokeMethod('forceSyncJoinedGroupMember', _buildParam({}));
|
||||
// }
|
||||
|
||||
static Map _buildParam(Map param) {
|
||||
param["ManagerName"] = "groupManager";
|
||||
return param;
|
||||
}
|
||||
|
||||
static dynamic _formatJson(value) => jsonDecode(_printValue(value));
|
||||
|
||||
static String _printValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
static String _checkOperationID(String? obj) {
|
||||
return obj ?? DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
import 'package:flutter_openim_sdk/src/manager/im_user_manager.dart';
|
||||
|
||||
class IMManager {
|
||||
MethodChannel _channel;
|
||||
@@ -61,7 +59,7 @@ class IMManager {
|
||||
dynamic data = call.arguments['data'];
|
||||
switch (type) {
|
||||
case 'onSelfInfoUpdated':
|
||||
uInfo = UserInfo.fromJson(_formatJson(data));
|
||||
uInfo = Utils.toObj(data, (map) => UserInfo.fromJson(map));
|
||||
userManager.userListener.selfInfoUpdated(uInfo);
|
||||
break;
|
||||
}
|
||||
@@ -70,53 +68,52 @@ class IMManager {
|
||||
dynamic data = call.arguments['data'];
|
||||
switch (type) {
|
||||
case 'onGroupApplicationAccepted':
|
||||
final i = GroupApplicationInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(
|
||||
data, (map) => GroupApplicationInfo.fromJson(map));
|
||||
groupManager.groupListener.groupApplicationAccepted(i);
|
||||
break;
|
||||
case 'onGroupApplicationAdded':
|
||||
final i = GroupApplicationInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(
|
||||
data, (map) => GroupApplicationInfo.fromJson(map));
|
||||
groupManager.groupListener.groupApplicationAdded(i);
|
||||
break;
|
||||
case 'onGroupApplicationDeleted':
|
||||
final i = GroupApplicationInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(
|
||||
data, (map) => GroupApplicationInfo.fromJson(map));
|
||||
groupManager.groupListener.groupApplicationDeleted(i);
|
||||
break;
|
||||
case 'onGroupApplicationRejected':
|
||||
final i = GroupApplicationInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(
|
||||
data, (map) => GroupApplicationInfo.fromJson(map));
|
||||
groupManager.groupListener.groupApplicationRejected(i);
|
||||
break;
|
||||
case 'onGroupInfoChanged':
|
||||
final i = GroupInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(data, (map) => GroupInfo.fromJson(map));
|
||||
groupManager.groupListener.groupInfoChanged(i);
|
||||
break;
|
||||
case 'onGroupMemberAdded':
|
||||
final i = GroupMembersInfo.fromJson(_formatJson(data));
|
||||
final i =
|
||||
Utils.toObj(data, (map) => GroupMembersInfo.fromJson(map));
|
||||
groupManager.groupListener.groupMemberAdded(i);
|
||||
break;
|
||||
case 'onGroupMemberDeleted':
|
||||
final i = GroupMembersInfo.fromJson(_formatJson(data));
|
||||
final i =
|
||||
Utils.toObj(data, (map) => GroupMembersInfo.fromJson(map));
|
||||
groupManager.groupListener.groupMemberDeleted(i);
|
||||
break;
|
||||
case 'onGroupMemberInfoChanged':
|
||||
final i = GroupMembersInfo.fromJson(_formatJson(data));
|
||||
final i =
|
||||
Utils.toObj(data, (map) => GroupMembersInfo.fromJson(map));
|
||||
groupManager.groupListener.groupMemberInfoChanged(i);
|
||||
break;
|
||||
case 'onJoinedGroupAdded':
|
||||
final i = GroupInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(data, (map) => GroupInfo.fromJson(map));
|
||||
groupManager.groupListener.joinedGroupAdded(i);
|
||||
break;
|
||||
case 'onJoinedGroupDeleted':
|
||||
final i = GroupInfo.fromJson(_formatJson(data));
|
||||
final i = Utils.toObj(data, (map) => GroupInfo.fromJson(map));
|
||||
groupManager.groupListener.joinedGroupDeleted(i);
|
||||
break;
|
||||
case 'onReceiveJoinGroupApplicationAdded':
|
||||
final i = GroupApplicationInfo.fromJson(_formatJson(data));
|
||||
groupManager.groupListener.receiveJoinGroupApplicationAdded(i);
|
||||
break;
|
||||
case 'onReceiveJoinGroupApplicationDeleted':
|
||||
final i = GroupApplicationInfo.fromJson(_formatJson(data));
|
||||
groupManager.groupListener.receiveJoinGroupApplicationDeleted(i);
|
||||
break;
|
||||
}
|
||||
} else if (call.method == ListenerType.advancedMsgListener) {
|
||||
var type = call.arguments['type'];
|
||||
@@ -124,7 +121,7 @@ class IMManager {
|
||||
switch (type) {
|
||||
case 'onRecvNewMessage':
|
||||
var value = call.arguments['data']['newMessage'];
|
||||
var msg = Message.fromJson(_formatJson(value));
|
||||
final msg = Utils.toObj(value, (map) => Message.fromJson(map));
|
||||
messageManager.advancedMsgListener.recvNewMessage(msg);
|
||||
break;
|
||||
case 'onRecvMessageRevoked':
|
||||
@@ -133,8 +130,8 @@ class IMManager {
|
||||
break;
|
||||
case 'onRecvC2CReadReceipt':
|
||||
var value = call.arguments['data']['haveReadMessage'];
|
||||
var l = _formatJson(value) as List;
|
||||
var list = l.map((e) => HaveReadInfo.fromJson(e)).toList();
|
||||
var list =
|
||||
Utils.toList(value, (map) => ReadReceiptInfo.fromJson(map));
|
||||
messageManager.advancedMsgListener.recvC2CReadReceipt(list);
|
||||
break;
|
||||
}
|
||||
@@ -166,21 +163,13 @@ class IMManager {
|
||||
conversationManager.conversationListener.syncServerFailed();
|
||||
break;
|
||||
case 'onNewConversation':
|
||||
List<ConversationInfo> list = List.empty(growable: true);
|
||||
if (null != data) {
|
||||
list = (_formatJson(data) as List)
|
||||
.map((e) => ConversationInfo.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
var list =
|
||||
Utils.toList(data, (map) => ConversationInfo.fromJson(map));
|
||||
conversationManager.conversationListener.newConversation(list);
|
||||
break;
|
||||
case 'onConversationChanged':
|
||||
List<ConversationInfo> list = List.empty(growable: true);
|
||||
if (null != data) {
|
||||
list = (_formatJson(data) as List)
|
||||
.map((e) => ConversationInfo.fromJson(e))
|
||||
.toList();
|
||||
}
|
||||
var list =
|
||||
Utils.toList(data, (map) => ConversationInfo.fromJson(map));
|
||||
conversationManager.conversationListener
|
||||
.conversationChanged(list);
|
||||
break;
|
||||
@@ -195,46 +184,50 @@ class IMManager {
|
||||
|
||||
switch (type) {
|
||||
case 'onBlacklistAdded':
|
||||
final u = BlacklistInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(data, (map) => BlacklistInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.blacklistAdded(u);
|
||||
break;
|
||||
case 'onBlacklistDeleted':
|
||||
final u = BlacklistInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(data, (map) => BlacklistInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.blacklistDeleted(u);
|
||||
break;
|
||||
case 'onFriendApplicationAccepted':
|
||||
final u = FriendApplicationInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(
|
||||
data, (map) => FriendApplicationInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendApplicationAccepted(u);
|
||||
break;
|
||||
case 'onFriendApplicationAdded':
|
||||
final u = FriendApplicationInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(
|
||||
data, (map) => FriendApplicationInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendApplicationAdded(u);
|
||||
break;
|
||||
case 'onFriendApplicationDeleted':
|
||||
final u = FriendApplicationInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(
|
||||
data, (map) => FriendApplicationInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendApplicationDeleted(u);
|
||||
break;
|
||||
case 'onFriendApplicationListRejected':
|
||||
final u = FriendApplicationInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(
|
||||
data, (map) => FriendApplicationInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendApplicationRejected(u);
|
||||
break;
|
||||
case 'onFriendInfoChanged':
|
||||
final u = FriendInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(data, (map) => FriendInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendInfoChanged(u);
|
||||
break;
|
||||
case 'onFriendAdded':
|
||||
final u = FriendInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(data, (map) => FriendInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendAdded(u);
|
||||
break;
|
||||
case 'onFriendDeleted':
|
||||
final u = FriendInfo.fromJson(_formatJson(data));
|
||||
final u = Utils.toObj(data, (map) => FriendInfo.fromJson(map));
|
||||
friendshipManager.friendshipListener.friendDeleted(u);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
print(
|
||||
"回调失败了,数据类型异常。$err ${call.method} ${call.arguments['type']} ${call.arguments['data']}");
|
||||
"回调失败了。$err ${call.method} ${call.arguments['type']} ${call.arguments['data']}");
|
||||
}
|
||||
return Future.value(null);
|
||||
});
|
||||
@@ -242,14 +235,16 @@ class IMManager {
|
||||
|
||||
/// Initialize SDK
|
||||
///
|
||||
/// [platform] Refer to [IMPlatform]
|
||||
/// [apiAddr] Api server ip address
|
||||
/// [wsAddr] WebSocket ip address
|
||||
/// [dataDir] Data storage directory
|
||||
/// [platform] platform number [IMPlatform]
|
||||
/// [apiAddr] api server ip address
|
||||
/// [wsAddr] webSocket ip address
|
||||
/// [dataDir] data storage directory
|
||||
///
|
||||
/// 初始化SDK
|
||||
/// [platform] 平台编号[IMPlatform]
|
||||
/// [apiAddr] SDK api地址
|
||||
/// [wsAddr] SDK websocket地址
|
||||
///
|
||||
/// [platform] 平台编号[IMPlatform]
|
||||
/// [apiAddr] SDK api地址
|
||||
/// [wsAddr] SDK websocket地址
|
||||
/// [dataDir] SDK数据库存储目录
|
||||
Future<dynamic> initSDK({
|
||||
required int platform,
|
||||
@@ -272,7 +267,7 @@ class IMManager {
|
||||
"data_dir": dataDir,
|
||||
"log_level": logLevel,
|
||||
"object_storage": objectStorage,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -294,7 +289,7 @@ class IMManager {
|
||||
_buildParam({
|
||||
'uid': uid,
|
||||
'token': token,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}),
|
||||
);
|
||||
this.isLogined = true;
|
||||
@@ -309,7 +304,7 @@ class IMManager {
|
||||
var value = await _channel.invokeMethod(
|
||||
'logout',
|
||||
_buildParam({
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
this.isLogined = false;
|
||||
return value;
|
||||
@@ -331,14 +326,4 @@ class IMManager {
|
||||
param["ManagerName"] = "imManager";
|
||||
return param;
|
||||
}
|
||||
|
||||
static dynamic _formatJson(value) => jsonDecode(_printValue(value));
|
||||
|
||||
static String _printValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
static String _checkOperationID(String? obj) {
|
||||
return obj ?? DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
|
||||
@@ -35,22 +33,24 @@ class MessageManager {
|
||||
/// 发送消息
|
||||
/// [userID]接收消息的用户id
|
||||
/// [groupID]接收消息的组id
|
||||
Future<dynamic> sendMessage({
|
||||
Future<Message> sendMessage({
|
||||
required Message message,
|
||||
String? userID,
|
||||
String? groupID,
|
||||
OfflinePushInfo? offlinePushInfo,
|
||||
String? operationID,
|
||||
}) =>
|
||||
_channel.invokeMethod(
|
||||
'sendMessage',
|
||||
_buildParam({
|
||||
'message': message.toJson(),
|
||||
'userID': userID ?? '',
|
||||
'groupID': groupID ?? '',
|
||||
'offlinePushInfo': offlinePushInfo?.toJson(),
|
||||
'operationID': _checkOperationID(operationID),
|
||||
})) /*.then((value) => _toObj(value))*/;
|
||||
_channel
|
||||
.invokeMethod(
|
||||
'sendMessage',
|
||||
_buildParam({
|
||||
'message': message.toJson(),
|
||||
'userID': userID ?? '',
|
||||
'groupID': groupID ?? '',
|
||||
'offlinePushInfo': offlinePushInfo?.toJson() ?? {},
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Find all history message
|
||||
/// 获取聊天记录
|
||||
@@ -71,9 +71,9 @@ class MessageManager {
|
||||
'groupID': groupID ?? '',
|
||||
'startClientMsgID': startMsg?.clientMsgID ?? '',
|
||||
'count': count ?? 10,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value));
|
||||
.then((value) => Utils.toList(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Revoke the sent information
|
||||
/// 撤回消息
|
||||
@@ -85,7 +85,7 @@ class MessageManager {
|
||||
'revokeMessage',
|
||||
_buildParam(message.toJson()
|
||||
..addAll({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
})));
|
||||
|
||||
/// Delete message
|
||||
@@ -98,7 +98,7 @@ class MessageManager {
|
||||
'deleteMessageFromLocalStorage',
|
||||
_buildParam(message.toJson()
|
||||
..addAll({
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
})));
|
||||
|
||||
///
|
||||
@@ -119,7 +119,7 @@ class MessageManager {
|
||||
"message": message?.toJson(),
|
||||
"receiverID": receiverID,
|
||||
"senderID": senderID,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Query the message according to the message id
|
||||
@@ -142,7 +142,7 @@ class MessageManager {
|
||||
_buildParam({
|
||||
"messageIDList": messageIDList,
|
||||
"userID": userID,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Typing
|
||||
@@ -157,7 +157,7 @@ class MessageManager {
|
||||
_buildParam({
|
||||
"msgTip": msgTip,
|
||||
"userID": userID,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Create text message
|
||||
@@ -171,9 +171,9 @@ class MessageManager {
|
||||
'createTextMessage',
|
||||
_buildParam({
|
||||
'text': text,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create @ message
|
||||
/// 创建@消息
|
||||
@@ -188,10 +188,10 @@ class MessageManager {
|
||||
_buildParam({
|
||||
'text': text,
|
||||
'atUserList': atUidList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}),
|
||||
)
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create picture message
|
||||
/// 创建图片消息
|
||||
@@ -204,10 +204,10 @@ class MessageManager {
|
||||
'createImageMessage',
|
||||
_buildParam({
|
||||
'imagePath': imagePath,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}),
|
||||
)
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create picture message
|
||||
/// 创建图片消息
|
||||
@@ -220,10 +220,10 @@ class MessageManager {
|
||||
'createImageMessageFromFullPath',
|
||||
_buildParam({
|
||||
'imagePath': imagePath,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}),
|
||||
)
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create sound message
|
||||
/// 创建语音消息
|
||||
@@ -238,10 +238,10 @@ class MessageManager {
|
||||
_buildParam({
|
||||
'soundPath': soundPath,
|
||||
"duration": duration,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}),
|
||||
)
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create sound message
|
||||
/// 创建语音消息
|
||||
@@ -256,10 +256,10 @@ class MessageManager {
|
||||
_buildParam({
|
||||
'soundPath': soundPath,
|
||||
"duration": duration,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}),
|
||||
)
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create video message
|
||||
/// 创建视频消息
|
||||
@@ -278,9 +278,9 @@ class MessageManager {
|
||||
'videoType': videoType,
|
||||
'duration': duration,
|
||||
'snapshotPath': snapshotPath,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create video message
|
||||
/// 创建视频消息
|
||||
@@ -299,9 +299,9 @@ class MessageManager {
|
||||
'videoType': videoType,
|
||||
'duration': duration,
|
||||
'snapshotPath': snapshotPath,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create file message
|
||||
/// 创建文件消息
|
||||
@@ -316,9 +316,9 @@ class MessageManager {
|
||||
_buildParam({
|
||||
'filePath': filePath,
|
||||
'fileName': fileName,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
}
|
||||
|
||||
/// Create file message
|
||||
@@ -334,9 +334,9 @@ class MessageManager {
|
||||
_buildParam({
|
||||
'filePath': filePath,
|
||||
'fileName': fileName,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create merger message
|
||||
/// 创建合并消息
|
||||
@@ -353,9 +353,9 @@ class MessageManager {
|
||||
'messageList': messageList.map((e) => e.toJson()).toList(),
|
||||
'title': title,
|
||||
'summaryList': summaryList,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create forward message
|
||||
/// 创建转发消息
|
||||
@@ -368,9 +368,9 @@ class MessageManager {
|
||||
'createForwardMessage',
|
||||
_buildParam({
|
||||
'message': message.toJson(),
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
}
|
||||
|
||||
/// Create location message
|
||||
@@ -388,9 +388,9 @@ class MessageManager {
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'description': description,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create custom message
|
||||
/// 创建自定义消息
|
||||
@@ -407,9 +407,9 @@ class MessageManager {
|
||||
'data': data,
|
||||
'extension': extension,
|
||||
'description': description,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create quote message
|
||||
/// 创建引用消息
|
||||
@@ -424,9 +424,9 @@ class MessageManager {
|
||||
_buildParam({
|
||||
'quoteText': text,
|
||||
'quoteMessage': quoteMsg.toJson(),
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Create card message
|
||||
/// 创建卡片消息
|
||||
@@ -439,9 +439,9 @@ class MessageManager {
|
||||
'createCardMessage',
|
||||
_buildParam({
|
||||
'cardMessage': data,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toObj(value));
|
||||
.then((value) => Utils.toObj(value, (map) => Message.fromJson(map)));
|
||||
|
||||
/// Clear all c2c history message
|
||||
/// 清空单聊消息记录
|
||||
@@ -453,7 +453,7 @@ class MessageManager {
|
||||
'clearC2CHistoryMessage',
|
||||
_buildParam({
|
||||
"userID": uid,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
/// Clear all group history
|
||||
@@ -466,31 +466,11 @@ class MessageManager {
|
||||
'clearGroupHistoryMessage',
|
||||
_buildParam({
|
||||
"groupID": gid,
|
||||
"operationID": _checkOperationID(operationID),
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
///
|
||||
// void forceSyncMsg() {
|
||||
// _channel.invokeMethod('forceSyncMsg', _buildParam({}));
|
||||
// }
|
||||
|
||||
static Map _buildParam(Map param) {
|
||||
param["ManagerName"] = "messageManager";
|
||||
return param;
|
||||
}
|
||||
|
||||
static List<Message> _toList(String value) =>
|
||||
(_formatJson(value) as List).map((e) => Message.fromJson(e)).toList();
|
||||
|
||||
static Message _toObj(String value) => Message.fromJson(_formatJson(value));
|
||||
|
||||
static dynamic _formatJson(value) => jsonDecode(_printValue(value));
|
||||
|
||||
static String _printValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
static String _checkOperationID(String? obj) {
|
||||
return obj ?? DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
|
||||
@@ -27,9 +25,9 @@ class UserManager {
|
||||
'getUsersInfo',
|
||||
_buildParam({
|
||||
'uidList': uidList,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => _toList(value, (v) => UserInfo.fromJson(v.cast())));
|
||||
.then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v)));
|
||||
|
||||
/// Get the information of the currently logged in user
|
||||
/// 获取当前登录用户的信息
|
||||
@@ -40,9 +38,9 @@ class UserManager {
|
||||
.invokeMethod(
|
||||
'getSelfUserInfo',
|
||||
_buildParam({
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}))
|
||||
.then((value) => UserInfo.fromJson(_formatJson(value)));
|
||||
.then((value) => Utils.toObj(value, (map) => UserInfo.fromJson(map)));
|
||||
|
||||
/// Modify current user info
|
||||
/// 修改当前登录用户资料
|
||||
@@ -52,7 +50,7 @@ class UserManager {
|
||||
int? gender,
|
||||
int? appMangerLevel,
|
||||
String? phoneNumber,
|
||||
String? birth,
|
||||
int? birth,
|
||||
String? email,
|
||||
String? ex,
|
||||
String? operationID,
|
||||
@@ -69,27 +67,11 @@ class UserManager {
|
||||
'birth': birth,
|
||||
'email': email,
|
||||
'ex': ex,
|
||||
'operationID': _checkOperationID(operationID),
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
}));
|
||||
|
||||
static Map _buildParam(Map param) {
|
||||
param["ManagerName"] = "userManager";
|
||||
return param;
|
||||
}
|
||||
|
||||
static List<T> _toList<T>(String? value, T f(Map map)) {
|
||||
var list = _formatJson(value);
|
||||
if (null == list) return <T>[];
|
||||
return (list as List).map((e) => f(e)).toList();
|
||||
}
|
||||
|
||||
static dynamic _formatJson(value) => jsonDecode(_printValue(value));
|
||||
|
||||
static String _printValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
static String _checkOperationID(String? obj) {
|
||||
return obj ?? DateTime.now().millisecondsSinceEpoch.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user