This commit is contained in:
hrxiang
2022-04-24 12:12:26 +08:00
parent fcc8373560
commit 6edf9b74fa
29 changed files with 545 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
library flutter_openim_sdk;
export 'src/enum/conversation_type.dart';
export 'src/enum/group_at_type.dart';
export 'src/enum/group_role_level.dart';
export 'src/enum/im_platform.dart';
export 'src/enum/listener_type.dart';
@@ -14,6 +15,7 @@ export 'src/listener/group_listener.dart';
export 'src/listener/msg_send_progress_listener.dart';
export 'src/listener/signaling_listener.dart';
export 'src/listener/user_listener.dart';
export 'src/listener/workmoments_listener.dart';
export 'src/manager/im_conversation_manager.dart';
export 'src/manager/im_friendship_manager.dart';
export 'src/manager/im_group_manager.dart';
@@ -22,6 +24,7 @@ export 'src/manager/im_message_manager.dart';
export 'src/manager/im_offline_push_manager.dart';
export 'src/manager/im_signaling_manager.dart';
export 'src/manager/im_user_manager.dart';
export 'src/manager/im_workmoments_manager.dart';
export 'src/models/conversation_info.dart';
export 'src/models/group_info.dart';
export 'src/models/message.dart';
@@ -29,5 +32,6 @@ export 'src/models/notification_info.dart';
export 'src/models/search_info.dart';
export 'src/models/signaling_info.dart';
export 'src/models/user_info.dart';
export 'src/models/workmoments_info.dart';
export 'src/openim.dart';
export 'src/utils.dart';

View File

@@ -0,0 +1,6 @@
class GroupAtType {
static const atNormal = 0;
static const atMe = 1;
static const atAll = 2;
static const atAllAtMe = 3;
}

View File

@@ -8,4 +8,5 @@ class ListenerType {
static final friendListener = 'friendListener';
static final signalingListener = 'signalingListener';
static final msgSendProgressListener = "msgSendProgressListener";
static final workMomentsListener = "workMomentsListener";
}

View File

@@ -56,6 +56,7 @@ class MessageType {
static const groupMemberCancelMutedNotification = 1513;
static const groupMutedNotification = 1514;
static const groupCancelMutedNotification = 1515;
static const groupMemberInfoChangedNotification = 1516;
static const signalingNotificationBegin = 1600;
static const signalingNotification = 1601;

View File

@@ -0,0 +1,9 @@
class OnWorkMomentsListener {
Function()? onRecvNewNotification;
OnWorkMomentsListener({this.onRecvNewNotification});
void recvNewNotification() {
onRecvNewNotification?.call();
}
}

View File

@@ -365,6 +365,23 @@ class GroupManager {
'operationID': Utils.checkOperationID(operationID),
}));
/// Set group user nickname
/// 设置群成员昵称
Future<dynamic> setGroupMemberNickname({
required String groupID,
required String userID,
String? groupNickname,
String? operationID,
}) =>
_channel.invokeMethod(
'setGroupMemberNickname',
_buildParam({
'gid': groupID,
'uid': userID,
'groupNickname': groupNickname ?? '',
'operationID': Utils.checkOperationID(operationID),
}));
static Map _buildParam(Map param) {
param["ManagerName"] = "groupManager";
return param;

View File

@@ -13,6 +13,7 @@ class IMManager {
// late OfflinePushManager offlinePushManager;
late SignalingManager signalingManager;
late WorkMomentsManager workMomentsManager;
late OnConnectListener _connectListener;
late String uid;
@@ -27,6 +28,7 @@ class IMManager {
userManager = UserManager(_channel);
// offlinePushManager = OfflinePushManager(_channel);
signalingManager = SignalingManager(_channel);
workMomentsManager = WorkMomentsManager(_channel);
_addNativeCallback(_channel);
}
@@ -212,7 +214,7 @@ class IMManager {
data, (map) => FriendApplicationInfo.fromJson(map));
friendshipManager.listener.friendApplicationDeleted(u);
break;
case 'onFriendApplicationListRejected':
case 'onFriendApplicationRejected':
final u = Utils.toObj(
data, (map) => FriendApplicationInfo.fromJson(map));
friendshipManager.listener.friendApplicationRejected(u);
@@ -257,6 +259,13 @@ class IMManager {
signalingManager.listener.inviteeRejectedByOtherDevice(u);
break;
}
} else if (call.method == ListenerType.workMomentsListener) {
String type = call.arguments['type'];
switch (type) {
case 'OnRecvNewNotification':
workMomentsManager.listener.recvNewNotification();
break;
}
}
} catch (err) {
print(

View File

@@ -214,7 +214,9 @@ class MessageManager {
/// 创建@消息
Future<Message> createTextAtMessage({
required String text,
required List<String> atUidList,
required List<String> atUserIDList,
List<AtUserInfo> atUserInfoList = const [],
Message? quoteMessage,
String? operationID,
}) =>
_channel
@@ -222,7 +224,9 @@ class MessageManager {
'createTextAtMessage',
_buildParam({
'text': text,
'atUserList': atUidList,
'atUserIDList': atUserIDList,
'atUserInfoList': atUserInfoList.map((e) => e.toJson()).toList(),
'quoteMessage': quoteMessage?.toJson(),
"operationID": Utils.checkOperationID(operationID),
}),
)

View File

@@ -0,0 +1,59 @@
import 'package:flutter/services.dart';
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
class WorkMomentsManager {
MethodChannel _channel;
late OnWorkMomentsListener listener;
WorkMomentsManager(this._channel);
/// Observe work moments changes
Future setWorkMomentsListener(OnWorkMomentsListener listener) {
this.listener = listener;
return _channel.invokeMethod('setWorkMomentsListener', _buildParam({}));
}
/// Get work moments unread count
Future<int> getWorkMomentsUnReadCount({
String? operationID,
}) =>
_channel
.invokeMethod(
'getWorkMomentsUnReadCount',
_buildParam({
'operationID': Utils.checkOperationID(operationID),
}))
.then((value) => Utils.toObj(value, (map) => map['unread_count']));
/// Get work moments notification list
Future<List<WorkMomentsInfo>> getWorkMomentsNotification({
required int offset,
required int count,
String? operationID,
}) =>
_channel
.invokeMethod(
'getWorkMomentsNotification',
_buildParam({
'offset': offset,
'count': count,
'operationID': Utils.checkOperationID(operationID),
}))
.then((value) =>
Utils.toList(value, (map) => WorkMomentsInfo.fromJson(map)));
/// Clear work moments notification
Future clearWorkMomentsNotification({
String? operationID,
}) =>
_channel.invokeMethod(
'clearWorkMomentsNotification',
_buildParam({
'operationID': Utils.checkOperationID(operationID),
}));
static Map _buildParam(Map param) {
param["ManagerName"] = "workMomentsManager";
return param;
}
}

View File

@@ -21,22 +21,25 @@ class ConversationInfo {
bool? isPinned;
bool? isPrivateChat;
String? ext;
bool? isNotInGroup;
ConversationInfo(
{required this.conversationID,
this.conversationType,
this.userID,
this.groupID,
this.showName,
this.faceURL,
this.recvMsgOpt,
this.unreadCount,
this.latestMsg,
this.latestMsgSendTime,
this.draftText,
this.draftTextTime,
this.isPrivateChat,
this.isPinned});
ConversationInfo({
required this.conversationID,
this.conversationType,
this.userID,
this.groupID,
this.showName,
this.faceURL,
this.recvMsgOpt,
this.unreadCount,
this.latestMsg,
this.latestMsgSendTime,
this.draftText,
this.draftTextTime,
this.isPrivateChat,
this.isPinned,
this.isNotInGroup,
});
ConversationInfo.fromJson(Map<String, dynamic> json)
: conversationID = json['conversationID'] {
@@ -59,6 +62,8 @@ class ConversationInfo {
draftTextTime = json['draftTextTime'];
isPinned = json['isPinned'];
isPrivateChat = json['isPrivateChat'];
isNotInGroup = json['isNotInGroup'];
groupAtType = json['groupAtType'];
}
Map<String, dynamic> toJson() {
@@ -77,6 +82,8 @@ class ConversationInfo {
data['draftTextTime'] = this.draftTextTime;
data['isPinned'] = this.isPinned;
data['isPrivateChat'] = this.isPrivateChat;
data['isNotInGroup'] = this.isNotInGroup;
data['groupAtType'] = this.groupAtType;
return data;
}

View File

@@ -424,8 +424,16 @@ class AtElem {
String? text;
List<String>? atUserList;
bool? isAtSelf;
List<AtUserInfo>? atUsersInfo;
Message? quoteMessage;
AtElem({this.text, this.atUserList, this.isAtSelf});
AtElem({
this.text,
this.atUserList,
this.isAtSelf,
this.atUsersInfo,
this.quoteMessage,
});
AtElem.fromJson(Map<String, dynamic> json) {
text = json['text'];
@@ -433,6 +441,14 @@ class AtElem {
atUserList = (json['atUserList'] as List).map((e) => '$e').toList();
}
isAtSelf = json['isAtSelf'];
if (json['atUsersInfo'] is List) {
atUsersInfo = (json['atUsersInfo'] as List)
.map((e) => AtUserInfo.fromJson(e))
.toList();
}
quoteMessage = null != json['quoteMessage']
? Message.fromJson(json['quoteMessage'])
: null;
}
Map<String, dynamic> toJson() {
@@ -440,6 +456,8 @@ class AtElem {
data['text'] = this.text;
data['atUserList'] = this.atUserList;
data['isAtSelf'] = this.isAtSelf;
data['atUsersInfo'] = this.atUsersInfo?.map((e) => e.toJson()).toList();
data['quoteMessage'] = this.quoteMessage?.toJson();
return data;
}
}
@@ -705,3 +723,22 @@ class OfflinePushInfo {
return data;
}
}
class AtUserInfo {
String? atUserID;
String? groupNickname;
AtUserInfo({this.atUserID, this.groupNickname});
AtUserInfo.fromJson(Map<String, dynamic> json) {
atUserID = json['atUserID'];
groupNickname = json['groupNickname'];
}
Map<String, dynamic> toJson() {
final data = Map<String, dynamic>();
data['atUserID'] = this.atUserID;
data['groupNickname'] = this.groupNickname;
return data;
}
}

View File

@@ -233,6 +233,33 @@ class QuitGroupNotification {
}
}
/// Enter group notification
/// 进群通知
class EnterGroupNotification {
GroupInfo? group;
GroupMembersInfo? entrantUser;
EnterGroupNotification({this.group, this.entrantUser});
EnterGroupNotification.fromJson(Map<String, dynamic> json) {
group = json['group'] != null ? GroupInfo.fromJson(json['group']) : null;
entrantUser = json['entrantUser'] != null
? GroupMembersInfo.fromJson(json['entrantUser'])
: null;
}
Map<String, dynamic> toJson() {
final data = Map<String, dynamic>();
if (this.group != null) {
data['group'] = this.group!.toJson();
}
if (this.entrantUser != null) {
data['quitUser'] = this.entrantUser!.toJson();
}
return data;
}
}
/// Group rights transfer noticication
/// 群权转让通知
class GroupRightsTransferNoticication {
@@ -277,11 +304,13 @@ class MuteMemberNotification {
GroupInfo? group;
GroupMembersInfo? opUser;
GroupMembersInfo? mutedUser;
int? mutedSeconds;
MuteMemberNotification({
this.group,
this.opUser,
this.mutedUser,
this.mutedSeconds,
});
MuteMemberNotification.fromJson(Map<String, dynamic> json) {
@@ -292,6 +321,7 @@ class MuteMemberNotification {
mutedUser = json['mutedUser'] != null
? GroupMembersInfo.fromJson(json['mutedUser'])
: null;
mutedSeconds = json['mutedSeconds'];
}
Map<String, dynamic> toJson() {
@@ -305,6 +335,7 @@ class MuteMemberNotification {
if (this.mutedUser != null) {
data['mutedUser'] = this.mutedUser!.toJson();
}
data['mutedSeconds'] = this.mutedSeconds;
return data;
}
}
@@ -332,3 +363,41 @@ class BurnAfterReadingNotification {
return data;
}
}
/// Group member info changed notification
/// 禁言成员通知
class GroupMemberInfoChangedNotification {
GroupInfo? group;
GroupMembersInfo? opUser;
GroupMembersInfo? changedUser;
GroupMemberInfoChangedNotification({
this.group,
this.opUser,
this.changedUser,
});
GroupMemberInfoChangedNotification.fromJson(Map<String, dynamic> json) {
group = json['group'] != null ? GroupInfo.fromJson(json['group']) : null;
opUser = json['opUser'] != null
? GroupMembersInfo.fromJson(json['opUser'])
: null;
changedUser = json['changedUser'] != null
? GroupMembersInfo.fromJson(json['changedUser'])
: null;
}
Map<String, dynamic> toJson() {
final data = Map<String, dynamic>();
if (this.group != null) {
data['group'] = this.group!.toJson();
}
if (this.opUser != null) {
data['opUser'] = this.opUser!.toJson();
}
if (this.changedUser != null) {
data['changedUser'] = this.changedUser!.toJson();
}
return data;
}
}

View File

@@ -0,0 +1,114 @@
class WorkMomentsInfo {
/// 工作圈消息类型 0为普通评论 1为被喜欢 2为AT提醒看的朋友圈
int? notificationMsgType;
Comment? comment;
/// 工作圈id
String? workMomentID;
/// 工作圈所属用户
String? userID;
/// 工作圈所属用户名字
String? userName;
/// 工作圈用户faceurl
String? faceURL;
/// 工作圈内容
String? workMomentContent;
WorkMomentsInfo(
{this.notificationMsgType,
this.comment,
this.workMomentID,
this.userID,
this.userName,
this.faceURL,
this.workMomentContent});
WorkMomentsInfo.fromJson(Map<String, dynamic> json) {
notificationMsgType = json['notificationMsgType'];
comment =
json['comment'] != null ? Comment.fromJson(json['comment']) : null;
workMomentID = json['workMomentID'];
userID = json['userID'];
userName = json['userName'];
faceURL = json['faceURL'];
workMomentContent = json['workMomentContent'];
}
Map<String, dynamic> toJson() {
final data = Map<String, dynamic>();
data['notificationMsgType'] = this.notificationMsgType;
if (this.comment != null) {
data['comment'] = this.comment!.toJson();
}
data['workMomentID'] = this.workMomentID;
data['userID'] = this.userID;
data['userName'] = this.userName;
data['faceURL'] = this.faceURL;
data['workMomentContent'] = this.workMomentContent;
return data;
}
}
class Comment {
/// 回复的用户
String? userID;
/// 回复的用户名
String? userName;
/// 回复的用户头像
String? faceURL;
/// 被回复的用户ID
String? replyUserID;
/// 被回复的用户名字
String? replyUserName;
/// 回复ID
String? contentID;
/// 回复内容
String? content;
/// 回复时间
int? createTime;
Comment(
{this.userID,
this.userName,
this.faceURL,
this.replyUserID,
this.replyUserName,
this.contentID,
this.content,
this.createTime});
Comment.fromJson(Map<String, dynamic> json) {
userID = json['userID'];
userName = json['userName'];
faceURL = json['faceURL'];
replyUserID = json['replyUserID'];
replyUserName = json['replyUserName'];
contentID = json['contentID'];
content = json['content'];
createTime = json['createTime'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['userID'] = this.userID;
data['userName'] = this.userName;
data['faceURL'] = this.faceURL;
data['replyUserID'] = this.replyUserID;
data['replyUserName'] = this.replyUserName;
data['contentID'] = this.contentID;
data['content'] = this.content;
data['createTime'] = this.createTime;
return data;
}
}