Skip to content

Commit 6099482

Browse files
authored
Merge pull request #547 from easemob/dev_4.0.0+6
Dev 4.0.0+6
2 parents 7ac53f0 + 7c98620 commit 6099482

File tree

6 files changed

+151
-25
lines changed

6 files changed

+151
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## NEXT
22

3+
## 4.0.0+6
4+
5+
- 修复 Hot reload 后回调执行多次的问题。
6+
37
## 4.0.0+5
48

59
#### 修复

android/src/main/java/com/easemob/im_flutter_sdk/EMChatManagerWrapper.java

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ private void downloadAttachment(JSONObject param, String channelName, Result res
443443
public void onSuccess() {
444444
post(() -> {
445445
Map<String, Object> map = new HashMap<>();
446-
map.put("message", EMMessageHelper.toJson(msg));
446+
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.SUCCESSED, msg, false));
447447
map.put("localId", msg.getMsgId());
448448
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
449449
});
@@ -466,7 +466,7 @@ public void onError(int code, String desc) {
466466
data.put("description", desc);
467467
post(() -> {
468468
Map<String, Object> map = new HashMap<>();
469-
map.put("message", EMMessageHelper.toJson(msg));
469+
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.FAILED, msg, false));
470470
map.put("localId", msg.getMsgId());
471471
map.put("error", data);
472472
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
@@ -475,7 +475,7 @@ public void onError(int code, String desc) {
475475
});
476476
asyncRunnable(() -> {
477477
EMClient.getInstance().chatManager().downloadAttachment(msg);
478-
onSuccess(result, channelName, EMMessageHelper.toJson(msg));
478+
onSuccess(result, channelName, updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.DOWNLOADING, msg, false));
479479
});
480480
}
481481

@@ -487,7 +487,7 @@ private void downloadThumbnail(JSONObject param, String channelName, Result resu
487487
public void onSuccess() {
488488
post(() -> {
489489
Map<String, Object> map = new HashMap<>();
490-
map.put("message", EMMessageHelper.toJson(msg));
490+
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.SUCCESSED, msg, true));
491491
map.put("localId", msg.getMsgId());
492492
messageChannel.invokeMethod(EMSDKMethod.onMessageSuccess, map);
493493
});
@@ -510,7 +510,7 @@ public void onError(int code, String desc) {
510510
data.put("description", desc);
511511
post(() -> {
512512
Map<String, Object> map = new HashMap<>();
513-
map.put("message", EMMessageHelper.toJson(msg));
513+
map.put("message", updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.FAILED, msg, true));
514514
map.put("localId", msg.getMsgId());
515515
map.put("error", data);
516516
messageChannel.invokeMethod(EMSDKMethod.onMessageError, map);
@@ -519,10 +519,65 @@ public void onError(int code, String desc) {
519519
});
520520
asyncRunnable(() -> {
521521
EMClient.getInstance().chatManager().downloadThumbnail(msg);
522-
onSuccess(result, channelName, EMMessageHelper.toJson(msg));
522+
onSuccess(result, channelName, updateDownloadStatus(EMFileMessageBody.EMDownloadStatus.DOWNLOADING, msg, true));
523523
});
524524
}
525525

526+
private Map<String, Object> updateDownloadStatus(EMFileMessageBody.EMDownloadStatus downloadStatus, EMMessage msg, boolean isThumbnail) {
527+
boolean canUpdate = false;
528+
switch (msg.getType()) {
529+
case FILE:
530+
case VOICE: {
531+
if (isThumbnail) {
532+
break;
533+
}
534+
}
535+
case IMAGE:
536+
case VIDEO:
537+
{
538+
canUpdate = true;
539+
}
540+
break;
541+
default:
542+
break;
543+
}
544+
if (canUpdate) {
545+
EMMessageBody body = msg.getBody();
546+
if (msg.getType() == EMMessage.Type.FILE) {
547+
EMFileMessageBody tmpBody = (EMFileMessageBody) body;
548+
tmpBody.setDownloadStatus(downloadStatus);
549+
body = tmpBody;
550+
}else if (msg.getType() == EMMessage.Type.VOICE) {
551+
EMVoiceMessageBody tmpBody = (EMVoiceMessageBody) body;
552+
tmpBody.setDownloadStatus(downloadStatus);
553+
body = tmpBody;
554+
}else if (msg.getType() == EMMessage.Type.IMAGE) {
555+
EMImageMessageBody tmpBody = (EMImageMessageBody) body;
556+
if (isThumbnail) {
557+
// android not support now.
558+
// tmpBody.setThumbnailDownloadStatus(downloadStatus);
559+
}else {
560+
tmpBody.setDownloadStatus(downloadStatus);
561+
}
562+
563+
body = tmpBody;
564+
}else if (msg.getType() == EMMessage.Type.VIDEO) {
565+
EMVideoMessageBody tmpBody = (EMVideoMessageBody) body;
566+
if (isThumbnail) {
567+
// android not support now.
568+
// tmpBody.setThumbnailDownloadStatus(downloadStatus);
569+
}else {
570+
tmpBody.setDownloadStatus(downloadStatus);
571+
}
572+
573+
body = tmpBody;
574+
}
575+
576+
msg.setBody(body);
577+
}
578+
return EMMessageHelper.toJson(msg);
579+
}
580+
526581
private void loadAllConversations(JSONObject param, String channelName, Result result) throws JSONException {
527582
if (EMClient.getInstance().getCurrentUser() == null || EMClient.getInstance().getCurrentUser().length() == 0) {
528583
onSuccess(result, channelName, new ArrayList<>());

android/src/main/java/com/easemob/im_flutter_sdk/EMClientWrapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
public class EMClientWrapper extends EMWrapper implements MethodCallHandler {
3232

33+
private EMOptions options;
3334
static EMClientWrapper wrapper;
3435
private EMChatManagerWrapper chatManagerWrapper;
3536
private EMGroupManagerWrapper groupManagerWrapper;
@@ -279,13 +280,15 @@ private void kickAllDevices(JSONObject param, String channelName, Result result)
279280
}
280281

281282
private void init(JSONObject param, String channelName, Result result) throws JSONException {
282-
EMOptions options = EMOptionsHelper.fromJson(param, this.context);
283+
if(options != null) return;
284+
options = EMOptionsHelper.fromJson(param, this.context);
283285
EMClient.getInstance().init(this.context, options);
284286
EMClient.getInstance().setDebugMode(param.getBoolean("debugModel"));
285287

286288
bindingManagers();
287289
registerEaseListener();
288290
onSuccess(result, channelName, null);
291+
289292
}
290293

291294
private void renewToken(JSONObject param, String channelName, Result result) throws JSONException {

ios/Classes/EMChatManagerWrapper.m

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#import "EMMessageReaction+Helper.h"
1717
#import "EMMessageReactionChange+Helper.h"
1818

19+
1920
@interface EMChatManagerWrapper () <EMChatManagerDelegate>
2021
@property (nonatomic, strong) FlutterMethodChannel *messageChannel;
2122

@@ -465,46 +466,49 @@ - (void)downloadAttachment:(NSDictionary *)param
465466
result:(FlutterResult)result {
466467
__weak typeof(self) weakSelf = self;
467468
__block EMChatMessage *msg = [EMChatMessage fromJson:param[@"message"]];
468-
EMChatMessage *needDownMSg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
469-
[EMClient.sharedClient.chatManager downloadMessageAttachment:needDownMSg
469+
EMChatMessage *needDownMsg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
470+
[EMClient.sharedClient.chatManager downloadMessageAttachment:needDownMsg
470471
progress:^(int progress)
471472
{
472473
[weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate
473474
arguments:@{
474475
@"progress":@(progress),
475-
@"localId":msg.messageId
476+
@"localId": msg.messageId
476477
}];
477478
} completion:^(EMChatMessage *message, EMError *error)
478479
{
479480
if (error) {
481+
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusFailed message:message thumbnail:NO];
480482
[weakSelf.messageChannel invokeMethod:ChatOnMessageError
481483
arguments:@{
482484
@"error":[error toJson],
483-
@"localId":msg.messageId,
484-
@"message":[message toJson]
485+
@"localId": msg.messageId,
486+
@"message":msgDict
485487
}];
486488
}else {
489+
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusSucceed message:message thumbnail:NO];
487490
[weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess
488491
arguments:@{
489-
@"message":[message toJson],
490-
@"localId":msg.messageId
492+
@"message":msgDict,
493+
@"localId": msg.messageId
491494
}];
492495
}
493496
}];
494497

498+
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusDownloading message:msg thumbnail:NO];
495499
[weakSelf wrapperCallBack:result
496500
channelName:aChannelName
497501
error:nil
498-
object:[msg toJson]];
502+
object:msgDict];
499503
}
500504

501505
- (void)downloadThumbnail:(NSDictionary *)param
502506
channelName:(NSString *)aChannelName
503507
result:(FlutterResult)result {
504508
__weak typeof(self) weakSelf = self;
505509
__block EMChatMessage *msg = [EMChatMessage fromJson:param[@"message"]];
506-
EMChatMessage *needDownMSg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
507-
[EMClient.sharedClient.chatManager downloadMessageThumbnail:needDownMSg
510+
EMChatMessage *needDownMsg = [EMClient.sharedClient.chatManager getMessageWithMessageId:msg.messageId];
511+
[EMClient.sharedClient.chatManager downloadMessageThumbnail:needDownMsg
508512
progress:^(int progress)
509513
{
510514
[weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate
@@ -515,25 +519,81 @@ - (void)downloadThumbnail:(NSDictionary *)param
515519
} completion:^(EMChatMessage *message, EMError *error)
516520
{
517521
if (error) {
522+
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusFailed message:message thumbnail:YES];
518523
[weakSelf.messageChannel invokeMethod:ChatOnMessageError
519524
arguments:@{
520525
@"error":[error toJson],
521526
@"localId":msg.messageId,
522-
@"message":[message toJson]
527+
@"message":msgDict
523528
}];
524529
}else {
530+
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusSucceed message:message thumbnail:YES];
525531
[weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess
526532
arguments:@{
527-
@"message":[message toJson],
533+
@"message":msgDict,
528534
@"localId":msg.messageId
529535
}];
530536
}
531537
}];
532-
538+
NSDictionary *msgDict = [self updateDownloadStatus:EMDownloadStatusDownloading message:msg thumbnail:YES];
533539
[weakSelf wrapperCallBack:result
534540
channelName:aChannelName
535541
error:nil
536-
object:[msg toJson]];
542+
object:msgDict];
543+
}
544+
545+
// 用于修改下载状态。
546+
- (NSDictionary *)updateDownloadStatus:(EMDownloadStatus)status
547+
message:(EMChatMessage *)msg
548+
thumbnail:(BOOL)isThumbnail
549+
{
550+
BOOL canUpdate = NO;
551+
switch(msg.body.type){
552+
case EMMessageBodyTypeFile:
553+
case EMMessageBodyTypeVoice:{
554+
if(isThumbnail) {
555+
break;
556+
}
557+
}
558+
case EMMessageBodyTypeVideo:
559+
case EMMessageBodyTypeImage:{
560+
canUpdate = YES;
561+
}
562+
break;
563+
default:
564+
break;
565+
}
566+
567+
if(canUpdate) {
568+
EMMessageBody *body = msg.body;
569+
if(msg.body.type == EMMessageBodyTypeFile) {
570+
EMFileMessageBody *tmpBody = (EMFileMessageBody *)body;
571+
tmpBody.downloadStatus = status;
572+
body = tmpBody;
573+
}else if(msg.body.type == EMMessageBodyTypeVoice) {
574+
EMVoiceMessageBody *tmpBody = (EMVoiceMessageBody *)body;
575+
tmpBody.downloadStatus = status;
576+
body = tmpBody;
577+
}else if(msg.body.type == EMMessageBodyTypeImage) {
578+
EMImageMessageBody *tmpBody = (EMImageMessageBody *)body;
579+
if(isThumbnail) {
580+
tmpBody.thumbnailDownloadStatus = status;
581+
}else {
582+
tmpBody.downloadStatus = status;
583+
}
584+
body = tmpBody;
585+
}else if(msg.body.type == EMMessageBodyTypeVideo) {
586+
EMVideoMessageBody *tmpBody = (EMVideoMessageBody *)body;
587+
if(isThumbnail) {
588+
tmpBody.thumbnailDownloadStatus = status;
589+
}else {
590+
tmpBody.downloadStatus = status;
591+
}
592+
body = tmpBody;
593+
}
594+
msg.body = body;
595+
}
596+
return [msg toJson] ;
537597
}
538598

539599
- (void)loadAllConversations:(NSDictionary *)param
@@ -619,6 +679,7 @@ - (void)fetchHistoryMessages:(NSDictionary *)param
619679
}];
620680
}
621681

682+
622683
- (void)fetchGroupReadAck:(NSDictionary *)param
623684
channelName:(NSString *)aChannelName
624685
result:(FlutterResult) result {

ios/Classes/EMClientWrapper.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ @interface EMClientWrapper () <EMClientDelegate, EMMultiDevicesDelegate, Flutter
3939
@end
4040

4141
@implementation EMClientWrapper
42+
{
43+
EMOptions *_options;
44+
}
4245

4346
static EMClientWrapper *wrapper = nil;
4447

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

186-
189+
if(_options != nil) return;
187190
__weak typeof(self) weakSelf = self;
188191

189-
EMOptions *options = [EMOptions fromJson:param];
192+
_options = [EMOptions fromJson:param];
190193

191-
[EMClient.sharedClient initializeSDKWithOptions:options];
194+
[EMClient.sharedClient initializeSDKWithOptions:_options];
192195

193196
[EMClient.sharedClient addDelegate:self delegateQueue:nil];
194197
[EMClient.sharedClient addMultiDevicesDelegate:self delegateQueue:nil];

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: im_flutter_sdk
22
description: Integrate the Chat SDK to enjoy the global IM services with high reliability, ultra-low latency, and high concurrency.
3-
version: 4.0.0+5
3+
version: 4.0.0+6
44
homepage: https://www.easemob.com/product/im
55

66
environment:

0 commit comments

Comments
 (0)