feat: Add input status related API; update synchronization monitoring related API.
This commit is contained in:
@@ -34,5 +34,6 @@ export 'src/models/message.dart';
|
||||
export 'src/models/notification_info.dart';
|
||||
export 'src/models/search_info.dart';
|
||||
export 'src/models/user_info.dart';
|
||||
export 'src/models/input_status_changed_data.dart';
|
||||
export 'src/openim.dart';
|
||||
export 'src/utils.dart';
|
||||
|
||||
@@ -5,6 +5,7 @@ class OnConnectListener {
|
||||
Function()? onConnecting;
|
||||
Function()? onKickedOffline;
|
||||
Function()? onUserTokenExpired;
|
||||
Function()? onUserTokenInvalid;
|
||||
|
||||
OnConnectListener({
|
||||
this.onConnectFailed,
|
||||
@@ -12,6 +13,7 @@ class OnConnectListener {
|
||||
this.onConnecting,
|
||||
this.onKickedOffline,
|
||||
this.onUserTokenExpired,
|
||||
this.onUserTokenInvalid,
|
||||
});
|
||||
|
||||
/// SDK failed to connect to the server
|
||||
@@ -38,4 +40,8 @@ class OnConnectListener {
|
||||
void userTokenExpired() {
|
||||
onUserTokenExpired?.call();
|
||||
}
|
||||
|
||||
void userTokenInvalid() {
|
||||
onUserTokenInvalid?.call();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
|
||||
/// Conversation Listener
|
||||
@@ -5,17 +6,21 @@ class OnConversationListener {
|
||||
Function(List<ConversationInfo> list)? onConversationChanged;
|
||||
Function(List<ConversationInfo> list)? onNewConversation;
|
||||
Function(int count)? onTotalUnreadMessageCountChanged;
|
||||
Function()? onSyncServerFailed;
|
||||
Function()? onSyncServerFinish;
|
||||
Function()? onSyncServerStart;
|
||||
Function(bool? reinstalled)? onSyncServerStart;
|
||||
Function(int? progress)? onSyncServerProgress;
|
||||
Function(bool? reinstalled)? onSyncServerFinish;
|
||||
Function(bool? reinstalled)? onSyncServerFailed;
|
||||
ValueChanged<InputStatusChangedData>? onInputStatusChanged;
|
||||
|
||||
OnConversationListener({
|
||||
this.onConversationChanged,
|
||||
this.onNewConversation,
|
||||
this.onTotalUnreadMessageCountChanged,
|
||||
this.onSyncServerFailed,
|
||||
this.onSyncServerFinish,
|
||||
this.onSyncServerStart,
|
||||
this.onSyncServerProgress,
|
||||
this.onSyncServerFinish,
|
||||
this.onSyncServerFailed,
|
||||
this.onInputStatusChanged,
|
||||
});
|
||||
|
||||
/// Conversations have changed
|
||||
@@ -33,15 +38,23 @@ class OnConversationListener {
|
||||
onTotalUnreadMessageCountChanged?.call(count);
|
||||
}
|
||||
|
||||
void syncServerFailed() {
|
||||
onSyncServerFailed?.call();
|
||||
void syncServerStart(bool? reinstalled) {
|
||||
onSyncServerStart?.call(reinstalled);
|
||||
}
|
||||
|
||||
void syncServerFinish() {
|
||||
onSyncServerFinish?.call();
|
||||
void syncServerProgress(int? progress) {
|
||||
onSyncServerProgress?.call(progress);
|
||||
}
|
||||
|
||||
void syncServerStart() {
|
||||
onSyncServerStart?.call();
|
||||
void syncServerFailed(bool? reinstalled) {
|
||||
onSyncServerFailed?.call(reinstalled);
|
||||
}
|
||||
|
||||
void syncServerFinish(bool? reinstalled) {
|
||||
onSyncServerFinish?.call(reinstalled);
|
||||
}
|
||||
|
||||
void conversationUserInputStatusChanged(InputStatusChangedData data) {
|
||||
onInputStatusChanged?.call(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,14 +361,13 @@ class ConversationManager {
|
||||
String? ex,
|
||||
String? operationID,
|
||||
}) {
|
||||
return _channel
|
||||
.invokeMethod(
|
||||
'setConversationEx',
|
||||
_buildParam({
|
||||
'conversationID': conversationID,
|
||||
'ex': ex,
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
return _channel.invokeMethod(
|
||||
'setConversationEx',
|
||||
_buildParam({
|
||||
'conversationID': conversationID,
|
||||
'ex': ex,
|
||||
"operationID": Utils.checkOperationID(operationID),
|
||||
}));
|
||||
}
|
||||
|
||||
/// Custom Sort for Conversation List
|
||||
@@ -391,6 +390,45 @@ class ConversationManager {
|
||||
}
|
||||
});
|
||||
|
||||
Future changeInputStates({
|
||||
required String conversationID,
|
||||
required bool focus,
|
||||
String? operationID,
|
||||
}) {
|
||||
return _channel.invokeMethod(
|
||||
'changeInputStates',
|
||||
_buildParam(
|
||||
{
|
||||
'focus': focus,
|
||||
'conversationID': conversationID,
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<int>?> getInputStates(
|
||||
String conversationID,
|
||||
String userID, {
|
||||
String? operationID,
|
||||
}) {
|
||||
return _channel
|
||||
.invokeMethod(
|
||||
'getInputStates',
|
||||
_buildParam(
|
||||
{
|
||||
'conversationID': conversationID,
|
||||
'userID': userID,
|
||||
'operationID': Utils.checkOperationID(operationID),
|
||||
},
|
||||
),
|
||||
)
|
||||
.then((value) {
|
||||
final result = Utils.toListMap(value);
|
||||
return List<int>.from(result);
|
||||
});
|
||||
}
|
||||
|
||||
static Map _buildParam(Map param) {
|
||||
param["ManagerName"] = "conversationManager";
|
||||
log('param: $param');
|
||||
|
||||
@@ -56,6 +56,9 @@ class IMManager {
|
||||
case 'onUserTokenExpired':
|
||||
_connectListener.userTokenExpired();
|
||||
break;
|
||||
case 'onUserTokenInvalid':
|
||||
_connectListener.userTokenInvalid();
|
||||
break;
|
||||
}
|
||||
} else if (call.method == ListenerType.userListener) {
|
||||
String type = call.arguments['type'];
|
||||
@@ -184,14 +187,17 @@ class IMManager {
|
||||
dynamic data = call.arguments['data'];
|
||||
switch (type) {
|
||||
case 'onSyncServerStart':
|
||||
conversationManager.listener.syncServerStart();
|
||||
print('dart onSyncServerStart: $data');
|
||||
conversationManager.listener.syncServerStart(data);
|
||||
break;
|
||||
case 'onSyncServerProgress':
|
||||
conversationManager.listener.syncServerProgress(data);
|
||||
break;
|
||||
case 'onSyncServerFinish':
|
||||
conversationManager.listener.syncServerFinish();
|
||||
conversationManager.listener.syncServerFinish(data);
|
||||
break;
|
||||
|
||||
case 'onSyncServerFailed':
|
||||
conversationManager.listener.syncServerFailed();
|
||||
conversationManager.listener.syncServerFailed(data);
|
||||
break;
|
||||
case 'onNewConversation':
|
||||
var list = Utils.toList(data, (map) => ConversationInfo.fromJson(map));
|
||||
@@ -204,6 +210,10 @@ class IMManager {
|
||||
case 'onTotalUnreadMessageCountChanged':
|
||||
conversationManager.listener.totalUnreadMessageCountChanged(data ?? 0);
|
||||
break;
|
||||
case 'onConversationUserInputStatusChanged':
|
||||
final i = Utils.toObj(data, (map) => InputStatusChangedData.fromJson(map));
|
||||
conversationManager.listener.conversationUserInputStatusChanged(i);
|
||||
break;
|
||||
}
|
||||
} else if (call.method == ListenerType.friendListener) {
|
||||
String type = call.arguments['type'];
|
||||
|
||||
24
lib/src/models/input_status_changed_data.dart
Normal file
24
lib/src/models/input_status_changed_data.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
class InputStatusChangedData {
|
||||
final String userID;
|
||||
final String conversationID;
|
||||
final List<int>? platformIDs;
|
||||
|
||||
InputStatusChangedData({
|
||||
required this.userID,
|
||||
required this.conversationID,
|
||||
this.platformIDs,
|
||||
});
|
||||
|
||||
InputStatusChangedData.fromJson(Map<String, dynamic> json)
|
||||
: userID = json['userID'],
|
||||
conversationID = json['conversationID'],
|
||||
platformIDs = List<int>.from(json['platformIDs'] ?? []);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
data['userID'] = userID;
|
||||
data['conversationID'] = conversationID;
|
||||
data['platformIDs'] = platformIDs;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user