Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## NEXT

## 4.0.0+6

- 修复 Hot reload 后回调执行多次的问题。

## 4.0.0+5

#### 修复
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private void downloadAttachment(JSONObject param, String channelName, Result res
public void onSuccess() {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(msg));
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.SUCCESSED, msg, false));
map.put("localId", msg.getMsgId());
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
});
Expand All @@ -466,7 +466,7 @@ public void onError(int code, String desc) {
data.put("description", desc);
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(msg));
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.FAILED, msg, false));
map.put("localId", msg.getMsgId());
map.put("error", data);
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
Expand All @@ -475,7 +475,7 @@ public void onError(int code, String desc) {
});
asyncRunnable(() -> {
EMClient.getInstance().chatManager().downloadAttachment(msg);
onSuccess(result, channelName, EMMessageHelper.toJson(msg));
onSuccess(result, channelName, updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.DOWNLOADING, msg, false));
});
}

Expand All @@ -487,7 +487,7 @@ private void downloadThumbnail(JSONObject param, String channelName, Result resu
public void onSuccess() {
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(msg));
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.SUCCESSED, msg, true));
map.put("localId", msg.getMsgId());
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
});
Expand All @@ -510,7 +510,7 @@ public void onError(int code, String desc) {
data.put("description", desc);
post(() -> {
Map<String, Object> map = new HashMap<>();
map.put("message", EMMessageHelper.toJson(msg));
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.FAILED, msg, true));
map.put("localId", msg.getMsgId());
map.put("error", data);
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
Expand All @@ -519,10 +519,65 @@ public void onError(int code, String desc) {
});
asyncRunnable(() -> {
EMClient.getInstance().chatManager().downloadThumbnail(msg);
onSuccess(result, channelName, EMMessageHelper.toJson(msg));
onSuccess(result, channelName, updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.DOWNLOADING, msg, true));
});
}

private Map<String, Object> updateDownloadStatus(EMFileMessageBody.EMDownloadStatus downloadStatus, EMMessage msg, boolean isThumbnail) {
boolean canUpdate = false;
switch (msg.getType()) {
case FILE:
case VOICE: {
if (isThumbnail) {
break;
}
}
case IMAGE:
case VIDEO:
{
canUpdate = true;
}
break;
default:
break;
}
if (canUpdate) {
EMMessageBody body = msg.getBody();
if (msg.getType() == EMMessage.Type.FILE) {
EMFileMessageBody tmpBody = (EMFileMessageBody) body;
tmpBody.setDownloadStatus(downloadStatus);
body = tmpBody;
}else if (msg.getType() == EMMessage.Type.VOICE) {
EMVoiceMessageBody tmpBody = (EMVoiceMessageBody) body;
tmpBody.setDownloadStatus(downloadStatus);
body = tmpBody;
}else if (msg.getType() == EMMessage.Type.IMAGE) {
EMImageMessageBody tmpBody = (EMImageMessageBody) body;
if (isThumbnail) {
// android not support now.
// tmpBody.setThumbnailDownloadStatus(downloadStatus);
}else {
tmpBody.setDownloadStatus(downloadStatus);
}

body = tmpBody;
}else if (msg.getType() == EMMessage.Type.VIDEO) {
EMVideoMessageBody tmpBody = (EMVideoMessageBody) body;
if (isThumbnail) {
// android not support now.
// tmpBody.setThumbnailDownloadStatus(downloadStatus);
}else {
tmpBody.setDownloadStatus(downloadStatus);
}

body = tmpBody;
}

msg.setBody(body);
}
return EMMessageHelper.toJson(msg);
}

private void loadAllConversations(JSONObject param, String channelName, Result result) throws JSONException {
if (EMClient.getInstance().getCurrentUser() == null || EMClient.getInstance().getCurrentUser().length() == 0) {
onSuccess(result, channelName, new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

public class EMClientWrapper extends EMWrapper implements MethodCallHandler {

private EMOptions options;
static EMClientWrapper wrapper;
private EMChatManagerWrapper chatManagerWrapper;
private EMGroupManagerWrapper groupManagerWrapper;
Expand Down Expand Up @@ -279,13 +280,15 @@ private void kickAllDevices(JSONObject param, String channelName, Result result)
}

private void init(JSONObject param, String channelName, Result result) throws JSONException {
EMOptions options = EMOptionsHelper.fromJson(param, this.context);
if(options != null) return;
options = EMOptionsHelper.fromJson(param, this.context);
EMClient.getInstance().init(this.context, options);
EMClient.getInstance().setDebugMode(param.getBoolean("debugModel"));

bindingManagers();
registerEaseListener();
onSuccess(result, channelName, null);

}

private void renewToken(JSONObject param, String channelName, Result result) throws JSONException {
Expand Down
89 changes: 75 additions & 14 deletions ios/Classes/EMChatManagerWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "EMMessageReaction+Helper.h"
#import "EMMessageReactionChange+Helper.h"


@interface EMChatManagerWrapper () <EMChatManagerDelegate>
@property (nonatomic, strong) FlutterMethodChannel *messageChannel;

Expand Down Expand Up @@ -465,46 +466,49 @@ - (void)downloadAttachment:(NSDictionary *)param
result:(FlutterResult)result {
__weak typeof(self) weakSelf = self;
__block EMChatMessage *msg = [EMChatMessage fromJson:param[@"message"]];
EMChatMessage *needDownMSg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
[EMClient.sharedClient.chatManager downloadMessageAttachment:needDownMSg
EMChatMessage *needDownMsg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
[EMClient.sharedClient.chatManager downloadMessageAttachment:needDownMsg
progress:^(int progress)
{
[weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate
arguments:@{
@"progress":@(progress),
@"localId":msg.messageId
@"localId": msg.messageId
}];
} completion:^(EMChatMessage *message, EMError *error)
{
if (error) {
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusFailed message:message thumbnail:NO];
[weakSelf.messageChannel invokeMethod:ChatOnMessageError
arguments:@{
@"error":[error toJson],
@"localId":msg.messageId,
@"message":[message toJson]
@"localId": msg.messageId,
@"message":msgDict
}];
}else {
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusSucceed message:message thumbnail:NO];
[weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess
arguments:@{
@"message":[message toJson],
@"localId":msg.messageId
@"message":msgDict,
@"localId": msg.messageId
}];
}
}];

NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusDownloading message:msg thumbnail:NO];
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:nil
object:[msg toJson]];
object:msgDict];
}

- (void)downloadThumbnail:(NSDictionary *)param
channelName:(NSString *)aChannelName
result:(FlutterResult)result {
__weak typeof(self) weakSelf = self;
__block EMChatMessage *msg = [EMChatMessage fromJson:param[@"message"]];
EMChatMessage *needDownMSg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
[EMClient.sharedClient.chatManager downloadMessageThumbnail:needDownMSg
EMChatMessage *needDownMsg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
[EMClient.sharedClient.chatManager downloadMessageThumbnail:needDownMsg
progress:^(int progress)
{
[weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate
Expand All @@ -515,25 +519,81 @@ - (void)downloadThumbnail:(NSDictionary *)param
} completion:^(EMChatMessage *message, EMError *error)
{
if (error) {
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusFailed message:message thumbnail:YES];
[weakSelf.messageChannel invokeMethod:ChatOnMessageError
arguments:@{
@"error":[error toJson],
@"localId":msg.messageId,
@"message":[message toJson]
@"message":msgDict
}];
}else {
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusSucceed message:message thumbnail:YES];
[weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess
arguments:@{
@"message":[message toJson],
@"message":msgDict,
@"localId":msg.messageId
}];
}
}];

NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusDownloading message:msg thumbnail:YES];
[weakSelf wrapperCallBack:result
channelName:aChannelName
error:nil
object:[msg toJson]];
object:msgDict];
}

// 用于修改下载状态。
- (NSDictionary *)updateDownloadStatus:(EMDownloadStatus)status
message:(EMChatMessage *)msg
thumbnail:(BOOL)isThumbnail
{
BOOL canUpdate = NO;
switch(msg.body.type){
case EMMessageBodyTypeFile:
case EMMessageBodyTypeVoice:{
if(isThumbnail) {
break;
}
}
case EMMessageBodyTypeVideo:
case EMMessageBodyTypeImage:{
canUpdate = YES;
}
break;
default:
break;
}

if(canUpdate) {
EMMessageBody *body = msg.body;
if(msg.body.type == EMMessageBodyTypeFile) {
EMFileMessageBody *tmpBody = (EMFileMessageBody *)body;
tmpBody.downloadStatus = status;
body = tmpBody;
}else if(msg.body.type == EMMessageBodyTypeVoice) {
EMVoiceMessageBody *tmpBody = (EMVoiceMessageBody *)body;
tmpBody.downloadStatus = status;
body = tmpBody;
}else if(msg.body.type == EMMessageBodyTypeImage) {
EMImageMessageBody *tmpBody = (EMImageMessageBody *)body;
if(isThumbnail) {
tmpBody.thumbnailDownloadStatus = status;
}else {
tmpBody.downloadStatus = status;
}
body = tmpBody;
}else if(msg.body.type == EMMessageBodyTypeVideo) {
EMVideoMessageBody *tmpBody = (EMVideoMessageBody *)body;
if(isThumbnail) {
tmpBody.thumbnailDownloadStatus = status;
}else {
tmpBody.downloadStatus = status;
}
body = tmpBody;
}
msg.body = body;
}
return [msg toJson] ;
}

- (void)loadAllConversations:(NSDictionary *)param
Expand Down Expand Up @@ -619,6 +679,7 @@ - (void)fetchHistoryMessages:(NSDictionary *)param
}];
}


- (void)fetchGroupReadAck:(NSDictionary *)param
channelName:(NSString *)aChannelName
result:(FlutterResult) result {
Expand Down
9 changes: 6 additions & 3 deletions ios/Classes/EMClientWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ @interface EMClientWrapper () <EMClientDelegate, EMMultiDevicesDelegate, Flutter
@end

@implementation EMClientWrapper
{
EMOptions *_options;
}

static EMClientWrapper *wrapper = nil;

Expand Down Expand Up @@ -183,12 +186,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
#pragma mark - Actions
- (void)initSDKWithDict:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result {


if(_options != nil) return;
__weak typeof(self) weakSelf = self;

EMOptions *options = [EMOptions fromJson:param];
_options = [EMOptions fromJson:param];

[EMClient.sharedClient initializeSDKWithOptions:options];
[EMClient.sharedClient initializeSDKWithOptions:_options];

[EMClient.sharedClient addDelegate:self delegateQueue:nil];
[EMClient.sharedClient addMultiDevicesDelegate:self delegateQueue:nil];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: im_flutter_sdk
description: Integrate the Chat SDK to enjoy the global IM services with high reliability, ultra-low latency, and high concurrency.
version: 4.0.0+5
version: 4.0.0+6
homepage: https://www.easemob.com/product/im

environment:
Expand Down