juggleim-rnsdk 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,16 +28,36 @@ RCT_EXPORT_METHOD(connectWithToken : (NSString *)token) {
28
28
  [JIM.shared.connectionManager connectWithToken:token];
29
29
  }
30
30
 
31
+ RCT_EXPORT_METHOD(disconnect : (BOOL)pushable) {
32
+ [JIM.shared.connectionManager disconnect:pushable];
33
+ }
34
+
31
35
  - (NSArray<NSString *> *)supportedEvents {
32
36
  return @[
33
- @"ConnectionStatusChanged", @"DbDidOpen", @"DbDidClose", @"MessageReceived",
34
- @"MessageRecalled", @"MessageUpdated", @"MessageDeleted", @"MessageCleared",
35
- @"MessageReactionAdded", @"MessageReactionRemoved", @"MessageSetTop",
36
- @"MessagesRead", @"GroupMessagesRead", @"MessageDestroyTimeUpdated",
37
- @"ConversationInfoAdded", @"ConversationInfoUpdated",
38
- @"ConversationInfoDeleted", @"TotalUnreadMessageCountUpdated",
39
- @"onMessageSent", @"onMessageSentError", @"onMediaMessageProgress",
40
- @"onMediaMessageSent", @"onMediaMessageSentError", @"onMediaMessageCancelled"
37
+ @"ConnectionStatusChanged",
38
+ @"DbDidOpen",
39
+ @"DbDidClose",
40
+ @"MessageReceived",
41
+ @"MessageRecalled",
42
+ @"MessageUpdated",
43
+ @"MessageDeleted",
44
+ @"MessageCleared",
45
+ @"MessageReactionAdded",
46
+ @"MessageReactionRemoved",
47
+ @"MessageSetTop",
48
+ @"MessagesRead",
49
+ @"GroupMessagesRead",
50
+ @"MessageDestroyTimeUpdated",
51
+ @"ConversationInfoAdded",
52
+ @"ConversationInfoUpdated",
53
+ @"ConversationInfoDeleted",
54
+ @"TotalUnreadMessageCountUpdated",
55
+ @"onMessageSent",
56
+ @"onMessageSentError",
57
+ @"onMediaMessageProgress",
58
+ @"onMediaMessageSent",
59
+ @"onMediaMessageSentError",
60
+ @"onMediaMessageCancelled"
41
61
  ];
42
62
  }
43
63
 
@@ -340,39 +360,43 @@ RCT_EXPORT_METHOD(addConversationDelegate) {
340
360
  - (NSDictionary *)convertMessageToDictionary:(JMessage *)message {
341
361
  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
342
362
  dict[@"messageId"] = message.messageId ?: @"";
343
- dict[@"clientMsgNo"] = [NSString stringWithFormat:@"%lld", message.clientMsgNo];
363
+ dict[@"clientMsgNo"] =
364
+ [NSString stringWithFormat:@"%lld", message.clientMsgNo];
344
365
  dict[@"timestamp"] = @(message.timestamp);
345
366
  dict[@"senderUserId"] = message.senderUserId ?: @"";
346
367
  dict[@"conversation"] =
347
368
  [self convertConversationToDictionary:message.conversation];
348
369
  dict[@"content"] = [self convertMessageContentToDictionary:message.content];
349
370
  dict[@"direction"] = @(message.direction);
350
- dict[@"messageState"] = @(message.messageState);
371
+ dict[@"messageState"] = @(message.messageState);
351
372
 
352
373
  // 添加是否已读
353
374
  dict[@"hasRead"] = @(message.hasRead);
354
-
375
+
355
376
  // 添加群消息阅读信息
356
377
  if (message.groupReadInfo) {
357
- dict[@"groupMessageReadInfo"] = [self convertGroupMessageReadInfoToDictionary:message.groupReadInfo];
378
+ dict[@"groupMessageReadInfo"] =
379
+ [self convertGroupMessageReadInfoToDictionary:message.groupReadInfo];
358
380
  }
359
-
381
+
360
382
  // 添加引用消息
361
383
  if (message.referredMsg) {
362
- dict[@"referredMessage"] = [self convertMessageToDictionary:message.referredMsg];
384
+ dict[@"referredMessage"] =
385
+ [self convertMessageToDictionary:message.referredMsg];
363
386
  }
364
-
387
+
365
388
  // 添加@消息信息
366
389
  if (message.mentionInfo) {
367
- dict[@"mentionInfo"] = [self convertMentionInfoToDictionary:message.mentionInfo];
390
+ dict[@"mentionInfo"] =
391
+ [self convertMentionInfoToDictionary:message.mentionInfo];
368
392
  }
369
-
393
+
370
394
  // 添加本地属性
371
395
  dict[@"localAttribute"] = message.localAttribute ?: @"";
372
-
396
+
373
397
  // 添加是否删除
374
398
  dict[@"isDelete"] = @(message.isDeleted);
375
-
399
+
376
400
  // 添加是否编辑
377
401
  dict[@"isEdit"] = @(message.isEdit);
378
402
 
@@ -470,17 +494,18 @@ RCT_EXPORT_METHOD(addConversationDelegate) {
470
494
  /**
471
495
  * 将@消息信息转换为字典
472
496
  */
473
- - (NSDictionary *)convertMentionInfoToDictionary:(JMessageMentionInfo *)mentionInfo {
474
- NSMutableDictionary *map = [NSMutableDictionary dictionary];
475
- map[@"type"] = @(mentionInfo.type);
476
-
477
- NSMutableArray *userArray = [NSMutableArray array];
478
- for (JUserInfo *userInfo in mentionInfo.targetUsers) {
479
- [userArray addObject:[self convertUserInfoToDictionary:userInfo]];
480
- }
481
- map[@"targetUsers"] = userArray;
482
-
483
- return map;
497
+ - (NSDictionary *)convertMentionInfoToDictionary:
498
+ (JMessageMentionInfo *)mentionInfo {
499
+ NSMutableDictionary *map = [NSMutableDictionary dictionary];
500
+ map[@"type"] = @(mentionInfo.type);
501
+
502
+ NSMutableArray *userArray = [NSMutableArray array];
503
+ for (JUserInfo *userInfo in mentionInfo.targetUsers) {
504
+ [userArray addObject:[self convertUserInfoToDictionary:userInfo]];
505
+ }
506
+ map[@"targetUsers"] = userArray;
507
+
508
+ return map;
484
509
  }
485
510
 
486
511
  /**
@@ -495,9 +520,11 @@ RCT_EXPORT_METHOD(addConversationDelegate) {
495
520
  /**
496
521
  * 将会话信息转换为字典
497
522
  */
498
- - (NSDictionary *)convertConversationInfoToDictionary:(JConversationInfo *)info {
523
+ - (NSDictionary *)convertConversationInfoToDictionary:
524
+ (JConversationInfo *)info {
499
525
  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
500
- dict[@"conversation"] = [self convertConversationToDictionary:info.conversation];
526
+ dict[@"conversation"] =
527
+ [self convertConversationToDictionary:info.conversation];
501
528
  dict[@"unreadCount"] = @(info.unreadCount);
502
529
  dict[@"topTime"] = @(info.topTime);
503
530
  dict[@"sortTime"] = @(info.sortTime);
@@ -509,21 +536,24 @@ RCT_EXPORT_METHOD(addConversationDelegate) {
509
536
  dict[@"lastMessage"] = [self convertMessageToDictionary:info.lastMessage];
510
537
  }
511
538
  if (info.mentionInfo) {
512
- dict[@"mentionInfo"] = [self convertConversationMentionInfoToDictionary:info.mentionInfo];
539
+ dict[@"mentionInfo"] =
540
+ [self convertConversationMentionInfoToDictionary:info.mentionInfo];
513
541
  }
514
542
  return dict;
515
543
  }
516
544
 
517
- - (NSDictionary *)convertConversationMentionInfoToDictionary:(JConversationMentionInfo *)mentionInfo {
545
+ - (NSDictionary *)convertConversationMentionInfoToDictionary:
546
+ (JConversationMentionInfo *)mentionInfo {
518
547
  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
519
548
  if (mentionInfo.mentionMsgList) {
520
549
  NSMutableArray *mentionMsgArray = [NSMutableArray array];
521
- for (JConversationMentionMessage *mentionMsg in mentionInfo.mentionMsgList) {
550
+ for (JConversationMentionMessage *mentionMsg in mentionInfo
551
+ .mentionMsgList) {
522
552
  NSDictionary *msgDict = @{
523
- @"senderId": mentionMsg.senderId ?: @"",
524
- @"msgId": mentionMsg.msgId ?: @"",
525
- @"msgTime": @(mentionMsg.msgTime),
526
- @"type": @(mentionMsg.type)
553
+ @"senderId" : mentionMsg.senderId ?: @"",
554
+ @"msgId" : mentionMsg.msgId ?: @"",
555
+ @"msgTime" : @(mentionMsg.msgTime),
556
+ @"type" : @(mentionMsg.type)
527
557
  };
528
558
  [mentionMsgArray addObject:msgDict];
529
559
  }
@@ -532,42 +562,43 @@ RCT_EXPORT_METHOD(addConversationDelegate) {
532
562
  return dict;
533
563
  }
534
564
 
535
-
536
565
  #pragma mark - Conversation Methods
537
566
 
538
567
  /**
539
568
  * 获取会话列表
540
569
  */
541
- RCT_EXPORT_METHOD(getConversationInfoList:(int)count
542
- timestamp:(double)timestamp
543
- pullDirection:(int)pullDirection
544
- resolver:(RCTPromiseResolveBlock)resolve
545
- rejecter:(RCTPromiseRejectBlock)reject) {
546
- JPullDirection direction = 0 == pullDirection ? JPullDirectionNewer : JPullDirectionOlder;
547
-
548
- NSArray<JConversationInfo *> *conversationInfos = [JIM.shared.conversationManager
549
- getConversationInfoListByCount:count
550
- timestamp:timestamp
551
- direction:direction];
552
-
570
+ RCT_EXPORT_METHOD(getConversationInfoList : (int)count timestamp : (double)
571
+ timestamp pullDirection : (int)pullDirection resolver : (
572
+ RCTPromiseResolveBlock)
573
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
574
+ JPullDirection direction =
575
+ 0 == pullDirection ? JPullDirectionNewer : JPullDirectionOlder;
576
+
577
+ NSArray<JConversationInfo *> *conversationInfos =
578
+ [JIM.shared.conversationManager getConversationInfoListByCount:count
579
+ timestamp:timestamp
580
+ direction:direction];
581
+
553
582
  NSMutableArray *result = [NSMutableArray array];
554
583
  for (JConversationInfo *info in conversationInfos) {
555
584
  [result addObject:[self convertConversationInfoToDictionary:info]];
556
585
  }
557
-
586
+
558
587
  resolve(result);
559
588
  }
560
589
 
561
590
  /**
562
591
  * 获取单个会话信息
563
592
  */
564
- RCT_EXPORT_METHOD(getConversationInfo:(NSDictionary *)conversationMap
565
- resolver:(RCTPromiseResolveBlock)resolve
566
- rejecter:(RCTPromiseRejectBlock)reject) {
567
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
568
-
569
- JConversationInfo *info = [JIM.shared.conversationManager getConversationInfo:conversation];
570
-
593
+ RCT_EXPORT_METHOD(getConversationInfo : (NSDictionary *)
594
+ conversationMap resolver : (RCTPromiseResolveBlock)
595
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
596
+ JConversation *conversation =
597
+ [self convertDictionaryToConversation:conversationMap];
598
+
599
+ JConversationInfo *info =
600
+ [JIM.shared.conversationManager getConversationInfo:conversation];
601
+
571
602
  if (info) {
572
603
  resolve([self convertConversationInfoToDictionary:info]);
573
604
  } else {
@@ -578,104 +609,120 @@ RCT_EXPORT_METHOD(getConversationInfo:(NSDictionary *)conversationMap
578
609
  /**
579
610
  * 创建会话信息
580
611
  */
581
- RCT_EXPORT_METHOD(createConversationInfo:(NSDictionary *)conversationMap
582
- resolver:(RCTPromiseResolveBlock)resolve
583
- rejecter:(RCTPromiseRejectBlock)reject) {
584
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
585
-
612
+ RCT_EXPORT_METHOD(createConversationInfo : (NSDictionary *)
613
+ conversationMap resolver : (RCTPromiseResolveBlock)
614
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
615
+ JConversation *conversation =
616
+ [self convertDictionaryToConversation:conversationMap];
617
+
586
618
  [JIM.shared.conversationManager createConversationInfo:conversation
587
- success:^(JConversationInfo *info) {
588
- resolve([self convertConversationInfoToDictionary:info]);
589
- } error:^(JErrorCode code) {
590
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
591
- }];
619
+ success:^(JConversationInfo *info) {
620
+ resolve([self convertConversationInfoToDictionary:info]);
621
+ }
622
+ error:^(JErrorCode code) {
623
+ reject(@"error",
624
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
625
+ }];
592
626
  }
593
627
 
594
628
  /**
595
629
  * 删除会话信息
596
630
  */
597
- RCT_EXPORT_METHOD(deleteConversationInfo:(NSDictionary *)conversationMap
598
- resolver:(RCTPromiseResolveBlock)resolve
599
- rejecter:(RCTPromiseRejectBlock)reject) {
600
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
601
-
631
+ RCT_EXPORT_METHOD(deleteConversationInfo : (NSDictionary *)
632
+ conversationMap resolver : (RCTPromiseResolveBlock)
633
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
634
+ JConversation *conversation =
635
+ [self convertDictionaryToConversation:conversationMap];
636
+
602
637
  [JIM.shared.conversationManager deleteConversationInfoBy:conversation
603
- success:^{
604
- resolve(@YES);
605
- } error:^(JErrorCode code) {
606
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
607
- }];
638
+ success:^{
639
+ resolve(@YES);
640
+ }
641
+ error:^(JErrorCode code) {
642
+ reject(@"error",
643
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
644
+ }];
608
645
  }
609
646
 
610
647
  /**
611
648
  * 设置会话免打扰状态
612
649
  */
613
- RCT_EXPORT_METHOD(setMute:(NSDictionary *)conversationMap
614
- isMute:(BOOL)isMute
615
- resolver:(RCTPromiseResolveBlock)resolve
616
- rejecter:(RCTPromiseRejectBlock)reject) {
617
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
618
-
650
+ RCT_EXPORT_METHOD(setMute : (NSDictionary *)conversationMap isMute : (BOOL)
651
+ isMute resolver : (RCTPromiseResolveBlock)
652
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
653
+ JConversation *conversation =
654
+ [self convertDictionaryToConversation:conversationMap];
655
+
619
656
  [JIM.shared.conversationManager setMute:isMute
620
- conversation:conversation
621
- success:^{
622
- resolve(@YES);
623
- } error:^(JErrorCode code) {
624
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
625
- }];
657
+ conversation:conversation
658
+ success:^{
659
+ resolve(@YES);
660
+ }
661
+ error:^(JErrorCode code) {
662
+ reject(@"error",
663
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
664
+ }];
626
665
  }
627
666
 
628
667
  /**
629
668
  * 设置会话置顶状态
630
669
  */
631
- RCT_EXPORT_METHOD(setTop:(NSDictionary *)conversationMap
632
- isTop:(BOOL)isTop
633
- resolver:(RCTPromiseResolveBlock)resolve
634
- rejecter:(RCTPromiseRejectBlock)reject) {
635
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
636
-
670
+ RCT_EXPORT_METHOD(setTop : (NSDictionary *)conversationMap isTop : (BOOL)
671
+ isTop resolver : (RCTPromiseResolveBlock)
672
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
673
+ JConversation *conversation =
674
+ [self convertDictionaryToConversation:conversationMap];
675
+
637
676
  [JIM.shared.conversationManager setTop:isTop
638
- conversation:conversation
639
- success:^{
640
- resolve(@YES);
641
- } error:^(JErrorCode code) {
642
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
643
- }];
677
+ conversation:conversation
678
+ success:^{
679
+ resolve(@YES);
680
+ }
681
+ error:^(JErrorCode code) {
682
+ reject(@"error",
683
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
684
+ }];
644
685
  }
645
686
 
646
687
  /**
647
688
  * 清除会话未读数
648
689
  */
649
- RCT_EXPORT_METHOD(clearUnreadCount:(NSDictionary *)conversationMap
650
- resolver:(RCTPromiseResolveBlock)resolve
651
- rejecter:(RCTPromiseRejectBlock)reject) {
652
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
653
-
690
+ RCT_EXPORT_METHOD(clearUnreadCount : (NSDictionary *)
691
+ conversationMap resolver : (RCTPromiseResolveBlock)
692
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
693
+ JConversation *conversation =
694
+ [self convertDictionaryToConversation:conversationMap];
695
+
654
696
  [JIM.shared.conversationManager clearUnreadCountByConversation:conversation
655
- success:^{
656
- resolve(@YES);
657
- } error:^(JErrorCode code) {
658
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
659
- }];
697
+ success:^{
698
+ resolve(@YES);
699
+ }
700
+ error:^(JErrorCode code) {
701
+ reject(@"error",
702
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
703
+ }];
660
704
  }
661
705
 
662
706
  /**
663
707
  * 清除总未读数
664
708
  */
665
- RCT_EXPORT_METHOD(clearTotalUnreadCount:(RCTPromiseResolveBlock)resolve
666
- rejecter:(RCTPromiseRejectBlock)reject) {
667
- [JIM.shared.conversationManager clearTotalUnreadCount:^{
668
- resolve(@YES);
669
- } error:^(JErrorCode code) {
670
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
671
- }];
709
+ RCT_EXPORT_METHOD(clearTotalUnreadCount : (RCTPromiseResolveBlock)
710
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
711
+ [JIM.shared.conversationManager
712
+ clearTotalUnreadCount:^{
713
+ resolve(@YES);
714
+ }
715
+ error:^(JErrorCode code) {
716
+ reject(@"error",
717
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
718
+ }];
672
719
  }
673
720
 
674
721
  /**
675
722
  * 获取总未读数
676
723
  */
677
- RCT_EXPORT_METHOD(getTotalUnreadCount:(RCTPromiseResolveBlock)resolve
678
- rejecter:(RCTPromiseRejectBlock)reject) {
724
+ RCT_EXPORT_METHOD(getTotalUnreadCount : (RCTPromiseResolveBlock)
725
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
679
726
  int count = [JIM.shared.conversationManager getTotalUnreadCount];
680
727
  resolve(@(count));
681
728
  }
@@ -683,12 +730,12 @@ RCT_EXPORT_METHOD(getTotalUnreadCount:(RCTPromiseResolveBlock)resolve
683
730
  /**
684
731
  * 设置会话草稿
685
732
  */
686
- RCT_EXPORT_METHOD(setDraft:(NSDictionary *)conversationMap
687
- draft:(NSString *)draft
688
- resolver:(RCTPromiseResolveBlock)resolve
689
- rejecter:(RCTPromiseRejectBlock)reject) {
690
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
691
-
733
+ RCT_EXPORT_METHOD(setDraft : (NSDictionary *)conversationMap draft : (
734
+ NSString *)draft resolver : (RCTPromiseResolveBlock)
735
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
736
+ JConversation *conversation =
737
+ [self convertDictionaryToConversation:conversationMap];
738
+
692
739
  [JIM.shared.conversationManager setDraft:draft inConversation:conversation];
693
740
  resolve(@YES);
694
741
  }
@@ -696,11 +743,11 @@ RCT_EXPORT_METHOD(setDraft:(NSDictionary *)conversationMap
696
743
  /**
697
744
  * 清除会话草稿
698
745
  */
699
- RCT_EXPORT_METHOD(clearDraft:(NSDictionary *)conversationMap
700
- resolver:(RCTPromiseResolveBlock)resolve
701
- rejecter:(RCTPromiseRejectBlock)reject) {
702
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
703
-
746
+ RCT_EXPORT_METHOD(clearDraft : (NSDictionary *)conversationMap resolver : (
747
+ RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
748
+ JConversation *conversation =
749
+ [self convertDictionaryToConversation:conversationMap];
750
+
704
751
  [JIM.shared.conversationManager clearDraftInConversation:conversation];
705
752
  resolve(@YES);
706
753
  }
@@ -708,49 +755,54 @@ RCT_EXPORT_METHOD(clearDraft:(NSDictionary *)conversationMap
708
755
  /**
709
756
  * 标记会话未读
710
757
  */
711
- RCT_EXPORT_METHOD(setUnread:(NSDictionary *)conversationMap
712
- resolver:(RCTPromiseResolveBlock)resolve
713
- rejecter:(RCTPromiseRejectBlock)reject) {
714
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
715
-
758
+ RCT_EXPORT_METHOD(setUnread : (NSDictionary *)conversationMap resolver : (
759
+ RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
760
+ JConversation *conversation =
761
+ [self convertDictionaryToConversation:conversationMap];
762
+
716
763
  [JIM.shared.conversationManager setUnread:conversation
717
- success:^{
718
- resolve(@YES);
719
- } error:^(JErrorCode code) {
720
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
721
- }];
764
+ success:^{
765
+ resolve(@YES);
766
+ }
767
+ error:^(JErrorCode code) {
768
+ reject(@"error",
769
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
770
+ }];
722
771
  }
723
772
 
724
773
  /**
725
774
  * 获取置顶会话列表
726
775
  */
727
- RCT_EXPORT_METHOD(getTopConversationInfoList:(int)count
728
- timestamp:(long long)timestamp
729
- pullDirection:(NSString *)pullDirection
730
- resolver:(RCTPromiseResolveBlock)resolve
731
- rejecter:(RCTPromiseRejectBlock)reject) {
732
- JPullDirection direction = [@"up" isEqualToString:pullDirection] ? JPullDirectionNewer : JPullDirectionOlder;
733
-
734
- NSArray<JConversationInfo *> *conversationInfos = [JIM.shared.conversationManager
735
- getTopConversationInfoListByCount:count
736
- timestamp:timestamp
737
- direction:direction];
738
-
776
+ RCT_EXPORT_METHOD(getTopConversationInfoList : (int)count timestamp : (
777
+ long long)timestamp pullDirection : (NSString *)
778
+ pullDirection resolver : (RCTPromiseResolveBlock)
779
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
780
+ JPullDirection direction = [@"up" isEqualToString:pullDirection]
781
+ ? JPullDirectionNewer
782
+ : JPullDirectionOlder;
783
+
784
+ NSArray<JConversationInfo *> *conversationInfos =
785
+ [JIM.shared.conversationManager
786
+ getTopConversationInfoListByCount:count
787
+ timestamp:timestamp
788
+ direction:direction];
789
+
739
790
  NSMutableArray *result = [NSMutableArray array];
740
791
  for (JConversationInfo *info in conversationInfos) {
741
792
  [result addObject:[self convertConversationInfoToDictionary:info]];
742
793
  }
743
-
794
+
744
795
  resolve(result);
745
796
  }
746
797
 
747
798
  /**
748
799
  * 获取指定类型未读数
749
800
  */
750
- RCT_EXPORT_METHOD(getUnreadCountWithTypes:(NSArray<NSNumber *> *)conversationTypes
751
- resolver:(RCTPromiseResolveBlock)resolve
752
- rejecter:(RCTPromiseRejectBlock)reject) {
753
- int count = [JIM.shared.conversationManager getUnreadCountWithTypes:conversationTypes];
801
+ RCT_EXPORT_METHOD(getUnreadCountWithTypes : (NSArray<NSNumber *> *)
802
+ conversationTypes resolver : (RCTPromiseResolveBlock)
803
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
804
+ int count = [JIM.shared.conversationManager
805
+ getUnreadCountWithTypes:conversationTypes];
754
806
  resolve(@(count));
755
807
  }
756
808
 
@@ -759,43 +811,48 @@ RCT_EXPORT_METHOD(getUnreadCountWithTypes:(NSArray<NSNumber *> *)conversationTyp
759
811
  /**
760
812
  * 向标签添加会话
761
813
  */
762
- RCT_EXPORT_METHOD(addConversationsToTag:(NSArray *)conversationMaps
763
- tagId:(NSString *)tagId
764
- resolver:(RCTPromiseResolveBlock)resolve
765
- rejecter:(RCTPromiseRejectBlock)reject) {
814
+ RCT_EXPORT_METHOD(addConversationsToTag : (NSArray *)conversationMaps tagId : (
815
+ NSString *)tagId resolver : (RCTPromiseResolveBlock)
816
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
766
817
  NSMutableArray<JConversation *> *conversations = [NSMutableArray array];
767
818
  for (NSDictionary *conversationMap in conversationMaps) {
768
- [conversations addObject:[self convertDictionaryToConversation:conversationMap]];
819
+ [conversations
820
+ addObject:[self convertDictionaryToConversation:conversationMap]];
769
821
  }
770
-
822
+
771
823
  [JIM.shared.conversationManager addConversationList:conversations
772
- toTag:tagId
773
- success:^{
774
- resolve(@YES);
775
- } error:^(JErrorCode code) {
776
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
777
- }];
824
+ toTag:tagId
825
+ success:^{
826
+ resolve(@YES);
827
+ }
828
+ error:^(JErrorCode code) {
829
+ reject(@"error",
830
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
831
+ }];
778
832
  }
779
833
 
780
834
  /**
781
835
  * 从标签移除会话
782
836
  */
783
- RCT_EXPORT_METHOD(removeConversationsFromTag:(NSArray *)conversationMaps
784
- tagId:(NSString *)tagId
785
- resolver:(RCTPromiseResolveBlock)resolve
786
- rejecter:(RCTPromiseRejectBlock)reject) {
837
+ RCT_EXPORT_METHOD(removeConversationsFromTag : (NSArray *)
838
+ conversationMaps tagId : (NSString *)tagId resolver : (
839
+ RCTPromiseResolveBlock)
840
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
787
841
  NSMutableArray<JConversation *> *conversations = [NSMutableArray array];
788
842
  for (NSDictionary *conversationMap in conversationMaps) {
789
- [conversations addObject:[self convertDictionaryToConversation:conversationMap]];
843
+ [conversations
844
+ addObject:[self convertDictionaryToConversation:conversationMap]];
790
845
  }
791
-
846
+
792
847
  [JIM.shared.conversationManager removeConversationList:conversations
793
- fromTag:tagId
794
- success:^{
795
- resolve(@YES);
796
- } error:^(JErrorCode code) {
797
- reject(@"error", [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
798
- }];
848
+ fromTag:tagId
849
+ success:^{
850
+ resolve(@YES);
851
+ }
852
+ error:^(JErrorCode code) {
853
+ reject(@"error",
854
+ [NSString stringWithFormat:@"Error code: %ld", (long)code], nil);
855
+ }];
799
856
  }
800
857
 
801
858
  #pragma mark - Helper Methods
@@ -804,404 +861,443 @@ RCT_EXPORT_METHOD(removeConversationsFromTag:(NSArray *)conversationMaps
804
861
  * 将字典转换为会话对象
805
862
  */
806
863
  - (JConversation *)convertDictionaryToConversation:(NSDictionary *)dict {
807
- JConversationType type = (JConversationType)[dict[@"conversationType"] intValue];
864
+ JConversationType type =
865
+ (JConversationType)[dict[@"conversationType"] intValue];
808
866
  NSString *conversationId = dict[@"conversationId"];
809
- return [[JConversation alloc] initWithConversationType:type conversationId:conversationId];
867
+ return [[JConversation alloc] initWithConversationType:type
868
+ conversationId:conversationId];
810
869
  }
811
870
 
812
871
  /**
813
872
  * 发送消息
814
873
  */
815
- RCT_EXPORT_METHOD(sendMessage:(NSDictionary *)messageDict
816
- messageId:(NSString *)messageId
817
- resolver:(RCTPromiseResolveBlock)resolve
818
- rejecter:(RCTPromiseRejectBlock)reject) {
819
- @try {
820
- // 构建消息内容和会话对象
821
- JMessageContent *content = [self convertDictToMessageContent:[messageDict objectForKey:@"content"]];
822
- JConversation *conversation = [self convertDictionaryToConversation:messageDict];
823
-
824
- if (!content) {
825
- reject(@"SEND_MESSAGE_ERROR", @"无效的消息内容", nil);
826
- return;
874
+ RCT_EXPORT_METHOD(sendMessage : (NSDictionary *)messageDict messageId : (
875
+ NSString *)messageId resolver : (RCTPromiseResolveBlock)
876
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
877
+ @try {
878
+ // 构建消息内容和会话对象
879
+ JMessageContent *content = [self
880
+ convertDictToMessageContent:[messageDict objectForKey:@"content"]];
881
+ JConversation *conversation =
882
+ [self convertDictionaryToConversation:messageDict];
883
+
884
+ if (!content) {
885
+ reject(@"SEND_MESSAGE_ERROR", @"无效的消息内容", nil);
886
+ return;
887
+ }
888
+
889
+ // 发送消息
890
+ JMessage *message = [JIM.shared.messageManager sendMessage:content
891
+ inConversation:conversation
892
+ success:^(JMessage *message) {
893
+ [self sendEventWithName:@"onMessageSent"
894
+ body:@{
895
+ @"messageId" : messageId,
896
+ @"message" :
897
+ [self convertMessageToDictionary:message]
898
+ }];
827
899
  }
828
-
829
- // 发送消息
830
- JMessage *message = [JIM.shared.messageManager sendMessage:content
831
- inConversation:conversation
832
- success:^(JMessage *message) {
833
- [self sendEventWithName:@"onMessageSent"
834
- body:@{
835
- @"messageId" : messageId,
836
- @"message" : [self convertMessageToDictionary:message]
837
- }];
838
- } error:^(JErrorCode errorCode, JMessage *message) {
900
+ error:^(JErrorCode errorCode, JMessage *message) {
839
901
  [self sendEventWithName:@"onMessageSentError"
840
- body:@{
841
- @"messageId" : messageId,
842
- @"message" : [self convertMessageToDictionary:message],
843
- @"errorCode" : @(errorCode)
844
- }];
902
+ body:@{
903
+ @"messageId" : messageId,
904
+ @"message" :
905
+ [self convertMessageToDictionary:message],
906
+ @"errorCode" : @(errorCode)
907
+ }];
845
908
  }];
846
- NSMutableDictionary *result = [self convertMessageToDictionary:message];
847
- result[@"messageId"] = messageId;
848
- resolve(result);
849
- } @catch (NSException *exception) {
850
- reject(@"SEND_MESSAGE_ERROR", exception.reason, nil);
851
- }
909
+ NSMutableDictionary *result = [self convertMessageToDictionary:message];
910
+ result[@"messageId"] = messageId;
911
+ resolve(result);
912
+ } @catch (NSException *exception) {
913
+ reject(@"SEND_MESSAGE_ERROR", exception.reason, nil);
914
+ }
852
915
  }
853
916
 
854
917
  /**
855
918
  * 发送图片消息
856
919
  */
857
- RCT_EXPORT_METHOD(sendImageMessage:(NSDictionary *)messageDict
858
- messageId:(NSString *)messageId
859
- resolver:(RCTPromiseResolveBlock)resolve
860
- rejecter:(RCTPromiseRejectBlock)reject) {
861
- @try {
862
- JConversation *conversation = [self convertDictionaryToConversation:messageDict];
863
- JImageMessage *imageMessage = [[JImageMessage alloc] init];
864
-
865
- NSDictionary *contentDict = messageDict[@"content"];
866
- if (contentDict[@"localPath"]) {
867
- imageMessage.localPath = contentDict[@"localPath"];
868
- }
869
- if (contentDict[@"thumbnailLocalPath"]) {
870
- imageMessage.thumbnailLocalPath = contentDict[@"thumbnailLocalPath"];
871
- }
872
- if (contentDict[@"url"]) {
873
- imageMessage.url = contentDict[@"url"];
874
- }
875
- if (contentDict[@"thumbnailUrl"]) {
876
- imageMessage.thumbnailUrl = contentDict[@"thumbnailUrl"];
920
+ RCT_EXPORT_METHOD(sendImageMessage : (NSDictionary *)messageDict messageId : (
921
+ NSString *)messageId resolver : (RCTPromiseResolveBlock)
922
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
923
+ @try {
924
+ JConversation *conversation =
925
+ [self convertDictionaryToConversation:messageDict];
926
+ JImageMessage *imageMessage = [[JImageMessage alloc] init];
927
+
928
+ NSDictionary *contentDict = messageDict[@"content"];
929
+ if (contentDict[@"localPath"]) {
930
+ imageMessage.localPath = contentDict[@"localPath"];
931
+ }
932
+ if (contentDict[@"thumbnailLocalPath"]) {
933
+ imageMessage.thumbnailLocalPath = contentDict[@"thumbnailLocalPath"];
934
+ }
935
+ if (contentDict[@"url"]) {
936
+ imageMessage.url = contentDict[@"url"];
937
+ }
938
+ if (contentDict[@"thumbnailUrl"]) {
939
+ imageMessage.thumbnailUrl = contentDict[@"thumbnailUrl"];
940
+ }
941
+ if (contentDict[@"width"]) {
942
+ imageMessage.width = [contentDict[@"width"] integerValue];
943
+ }
944
+ if (contentDict[@"height"]) {
945
+ imageMessage.height = [contentDict[@"height"] integerValue];
946
+ }
947
+
948
+ JMessage *message = [JIM.shared.messageManager sendMediaMessage:imageMessage
949
+ inConversation:conversation
950
+ progress:^(int progress, JMessage *_Nonnull message) {
951
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
952
+ params[@"messageId"] = messageId;
953
+ params[@"progress"] = @(progress);
954
+ params[@"message"] = [self convertMessageToDictionary:message];
955
+ [self sendEventWithName:@"onMediaMessageProgress" body:params];
877
956
  }
878
- if (contentDict[@"width"]) {
879
- imageMessage.width = [contentDict[@"width"] integerValue];
957
+ success:^(JMessage *_Nonnull message) {
958
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
959
+ params[@"messageId"] = messageId;
960
+ params[@"message"] = [self convertMessageToDictionary:message];
961
+ [self sendEventWithName:@"onMediaMessageSent" body:params];
880
962
  }
881
- if (contentDict[@"height"]) {
882
- imageMessage.height = [contentDict[@"height"] integerValue];
963
+ error:^(JErrorCode errorCode, JMessage *_Nonnull message) {
964
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
965
+ params[@"messageId"] = messageId;
966
+ params[@"message"] = [self convertMessageToDictionary:message];
967
+ params[@"errorCode"] = @(errorCode);
968
+ [self sendEventWithName:@"onMediaMessageSentError" body:params];
883
969
  }
884
-
885
- JMessage *message = [JIM.shared.messageManager sendMediaMessage:imageMessage
886
- inConversation:conversation
887
- progress:^(int progress, JMessage * _Nonnull message) {
888
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
889
- params[@"messageId"] = messageId;
890
- params[@"progress"] = @(progress);
891
- params[@"message"] = [self convertMessageToDictionary:message];
892
- [self sendEventWithName:@"onMediaMessageProgress" body:params];
893
- } success:^(JMessage * _Nonnull message) {
894
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
895
- params[@"messageId"] = messageId;
896
- params[@"message"] = [self convertMessageToDictionary:message];
897
- [self sendEventWithName:@"onMediaMessageSent" body:params];
898
- } error:^(JErrorCode errorCode, JMessage * _Nonnull message) {
899
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
900
- params[@"messageId"] = messageId;
901
- params[@"message"] = [self convertMessageToDictionary:message];
902
- params[@"errorCode"] = @(errorCode);
903
- [self sendEventWithName:@"onMediaMessageSentError" body:params];
904
- } cancel:^(JMessage * _Nonnull message) {
905
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
906
- params[@"messageId"] = messageId;
907
- params[@"message"] = [self convertMessageToDictionary:message];
908
- [self sendEventWithName:@"onMediaMessageCancelled" body:params];
970
+ cancel:^(JMessage *_Nonnull message) {
971
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
972
+ params[@"messageId"] = messageId;
973
+ params[@"message"] = [self convertMessageToDictionary:message];
974
+ [self sendEventWithName:@"onMediaMessageCancelled" body:params];
909
975
  }];
910
-
911
- NSMutableDictionary *result = [self convertMessageToDictionary:message];
912
- result[@"messageId"] = messageId;
913
- resolve(result);
914
- } @catch (NSException *exception) {
915
- reject(@"SEND_IMAGE_MESSAGE_ERROR", exception.reason, nil);
916
- }
976
+
977
+ NSMutableDictionary *result = [self convertMessageToDictionary:message];
978
+ result[@"messageId"] = messageId;
979
+ resolve(result);
980
+ } @catch (NSException *exception) {
981
+ reject(@"SEND_IMAGE_MESSAGE_ERROR", exception.reason, nil);
982
+ }
917
983
  }
918
984
 
919
985
  /**
920
986
  * 发送文件消息
921
987
  */
922
- RCT_EXPORT_METHOD(sendFileMessage:(NSDictionary *)messageDict
923
- messageId:(NSString *)messageId
924
- resolver:(RCTPromiseResolveBlock)resolve
925
- rejecter:(RCTPromiseRejectBlock)reject) {
926
- @try {
927
- JConversation *conversation = [self convertDictionaryToConversation:messageDict];
928
- JFileMessage *fileMessage = [[JFileMessage alloc] init];
929
-
930
- NSDictionary *contentDict = messageDict[@"content"];
931
- if (contentDict[@"localPath"]) {
932
- fileMessage.localPath = contentDict[@"localPath"];
933
- }
934
- if (contentDict[@"url"]) {
935
- fileMessage.url = contentDict[@"url"];
936
- }
937
- if (contentDict[@"name"]) {
938
- fileMessage.name = contentDict[@"name"];
988
+ RCT_EXPORT_METHOD(sendFileMessage : (NSDictionary *)messageDict messageId : (
989
+ NSString *)messageId resolver : (RCTPromiseResolveBlock)
990
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
991
+ @try {
992
+ JConversation *conversation =
993
+ [self convertDictionaryToConversation:messageDict];
994
+ JFileMessage *fileMessage = [[JFileMessage alloc] init];
995
+
996
+ NSDictionary *contentDict = messageDict[@"content"];
997
+ if (contentDict[@"localPath"]) {
998
+ fileMessage.localPath = contentDict[@"localPath"];
999
+ }
1000
+ if (contentDict[@"url"]) {
1001
+ fileMessage.url = contentDict[@"url"];
1002
+ }
1003
+ if (contentDict[@"name"]) {
1004
+ fileMessage.name = contentDict[@"name"];
1005
+ }
1006
+ if (contentDict[@"size"]) {
1007
+ fileMessage.size = [contentDict[@"size"] longLongValue];
1008
+ }
1009
+ if (contentDict[@"type"]) {
1010
+ fileMessage.type = contentDict[@"type"];
1011
+ }
1012
+
1013
+ JMessage *message = [JIM.shared.messageManager sendMediaMessage:fileMessage
1014
+ inConversation:conversation
1015
+ progress:^(int progress, JMessage *_Nonnull message) {
1016
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1017
+ params[@"messageId"] = messageId;
1018
+ params[@"progress"] = @(progress);
1019
+ params[@"message"] = [self convertMessageToDictionary:message];
1020
+ [self sendEventWithName:@"onMediaMessageProgress" body:params];
939
1021
  }
940
- if (contentDict[@"size"]) {
941
- fileMessage.size = [contentDict[@"size"] longLongValue];
1022
+ success:^(JMessage *_Nonnull message) {
1023
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1024
+ params[@"messageId"] = messageId;
1025
+ params[@"message"] = [self convertMessageToDictionary:message];
1026
+ [self sendEventWithName:@"onMediaMessageSent" body:params];
942
1027
  }
943
- if (contentDict[@"type"]) {
944
- fileMessage.type = contentDict[@"type"];
1028
+ error:^(JErrorCode errorCode, JMessage *_Nonnull message) {
1029
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1030
+ params[@"messageId"] = messageId;
1031
+ params[@"message"] = [self convertMessageToDictionary:message];
1032
+ params[@"errorCode"] = @(errorCode);
1033
+ [self sendEventWithName:@"onMediaMessageSentError" body:params];
945
1034
  }
946
-
947
- JMessage *message = [JIM.shared.messageManager sendMediaMessage:fileMessage
948
- inConversation:conversation
949
- progress:^(int progress, JMessage * _Nonnull message) {
950
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
951
- params[@"messageId"] = messageId;
952
- params[@"progress"] = @(progress);
953
- params[@"message"] = [self convertMessageToDictionary:message];
954
- [self sendEventWithName:@"onMediaMessageProgress" body:params];
955
- } success:^(JMessage * _Nonnull message) {
956
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
957
- params[@"messageId"] = messageId;
958
- params[@"message"] = [self convertMessageToDictionary:message];
959
- [self sendEventWithName:@"onMediaMessageSent" body:params];
960
- } error:^(JErrorCode errorCode, JMessage * _Nonnull message) {
961
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
962
- params[@"messageId"] = messageId;
963
- params[@"message"] = [self convertMessageToDictionary:message];
964
- params[@"errorCode"] = @(errorCode);
965
- [self sendEventWithName:@"onMediaMessageSentError" body:params];
966
- } cancel:^(JMessage * _Nonnull message) {
967
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
968
- params[@"messageId"] = messageId;
969
- params[@"message"] = [self convertMessageToDictionary:message];
970
- [self sendEventWithName:@"onMediaMessageCancelled" body:params];
1035
+ cancel:^(JMessage *_Nonnull message) {
1036
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1037
+ params[@"messageId"] = messageId;
1038
+ params[@"message"] = [self convertMessageToDictionary:message];
1039
+ [self sendEventWithName:@"onMediaMessageCancelled" body:params];
971
1040
  }];
972
-
973
- NSMutableDictionary *result = [self convertMessageToDictionary:message];
974
- result[@"messageId"] = messageId;
975
- resolve(result);
976
- } @catch (NSException *exception) {
977
- reject(@"SEND_FILE_MESSAGE_ERROR", exception.reason, nil);
978
- }
1041
+
1042
+ NSMutableDictionary *result = [self convertMessageToDictionary:message];
1043
+ result[@"messageId"] = messageId;
1044
+ resolve(result);
1045
+ } @catch (NSException *exception) {
1046
+ reject(@"SEND_FILE_MESSAGE_ERROR", exception.reason, nil);
1047
+ }
979
1048
  }
980
1049
 
981
1050
  /**
982
1051
  * 发送语音消息
983
1052
  */
984
- RCT_EXPORT_METHOD(sendVoiceMessage:(NSDictionary *)messageDict
985
- messageId:(NSString *)messageId
986
- resolver:(RCTPromiseResolveBlock)resolve
987
- rejecter:(RCTPromiseRejectBlock)reject) {
988
- @try {
989
- JConversation *conversation = [self convertDictionaryToConversation:messageDict];
990
- JVoiceMessage *voiceMessage = [[JVoiceMessage alloc] init];
991
-
992
- NSDictionary *contentDict = messageDict[@"content"];
993
- if (contentDict[@"localPath"]) {
994
- voiceMessage.localPath = contentDict[@"localPath"];
1053
+ RCT_EXPORT_METHOD(sendVoiceMessage : (NSDictionary *)messageDict messageId : (
1054
+ NSString *)messageId resolver : (RCTPromiseResolveBlock)
1055
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
1056
+ @try {
1057
+ JConversation *conversation =
1058
+ [self convertDictionaryToConversation:messageDict];
1059
+ JVoiceMessage *voiceMessage = [[JVoiceMessage alloc] init];
1060
+
1061
+ NSDictionary *contentDict = messageDict[@"content"];
1062
+ if (contentDict[@"localPath"]) {
1063
+ voiceMessage.localPath = contentDict[@"localPath"];
1064
+ }
1065
+ if (contentDict[@"url"]) {
1066
+ voiceMessage.url = contentDict[@"url"];
1067
+ }
1068
+ if (contentDict[@"duration"]) {
1069
+ voiceMessage.duration = [contentDict[@"duration"] integerValue];
1070
+ }
1071
+
1072
+ JMessage *message = [JIM.shared.messageManager sendMediaMessage:voiceMessage
1073
+ inConversation:conversation
1074
+ progress:^(int progress, JMessage *_Nonnull message) {
1075
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1076
+ params[@"messageId"] = messageId;
1077
+ params[@"progress"] = @(progress);
1078
+ params[@"message"] = [self convertMessageToDictionary:message];
1079
+ [self sendEventWithName:@"onMediaMessageProgress" body:params];
995
1080
  }
996
- if (contentDict[@"url"]) {
997
- voiceMessage.url = contentDict[@"url"];
1081
+ success:^(JMessage *_Nonnull message) {
1082
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1083
+ params[@"messageId"] = messageId;
1084
+ params[@"message"] = [self convertMessageToDictionary:message];
1085
+ [self sendEventWithName:@"onMediaMessageSent" body:params];
998
1086
  }
999
- if (contentDict[@"duration"]) {
1000
- voiceMessage.duration = [contentDict[@"duration"] integerValue];
1087
+ error:^(JErrorCode errorCode, JMessage *_Nonnull message) {
1088
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1089
+ params[@"messageId"] = messageId;
1090
+ params[@"message"] = [self convertMessageToDictionary:message];
1091
+ params[@"errorCode"] = @(errorCode);
1092
+ [self sendEventWithName:@"onMediaMessageSentError" body:params];
1001
1093
  }
1002
-
1003
- JMessage *message = [JIM.shared.messageManager sendMediaMessage:voiceMessage
1004
- inConversation:conversation
1005
- progress:^(int progress, JMessage * _Nonnull message) {
1006
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
1007
- params[@"messageId"] = messageId;
1008
- params[@"progress"] = @(progress);
1009
- params[@"message"] = [self convertMessageToDictionary:message];
1010
- [self sendEventWithName:@"onMediaMessageProgress" body:params];
1011
- } success:^(JMessage * _Nonnull message) {
1012
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
1013
- params[@"messageId"] = messageId;
1014
- params[@"message"] = [self convertMessageToDictionary:message];
1015
- [self sendEventWithName:@"onMediaMessageSent" body:params];
1016
- } error:^(JErrorCode errorCode, JMessage * _Nonnull message) {
1017
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
1018
- params[@"messageId"] = messageId;
1019
- params[@"message"] = [self convertMessageToDictionary:message];
1020
- params[@"errorCode"] = @(errorCode);
1021
- [self sendEventWithName:@"onMediaMessageSentError" body:params];
1022
- } cancel:^(JMessage * _Nonnull message) {
1023
- NSMutableDictionary *params = [NSMutableDictionary dictionary];
1024
- params[@"messageId"] = messageId;
1025
- params[@"message"] = [self convertMessageToDictionary:message];
1026
- [self sendEventWithName:@"onMediaMessageCancelled" body:params];
1094
+ cancel:^(JMessage *_Nonnull message) {
1095
+ NSMutableDictionary *params = [NSMutableDictionary dictionary];
1096
+ params[@"messageId"] = messageId;
1097
+ params[@"message"] = [self convertMessageToDictionary:message];
1098
+ [self sendEventWithName:@"onMediaMessageCancelled" body:params];
1027
1099
  }];
1028
-
1029
- NSMutableDictionary *result = [self convertMessageToDictionary:message];
1030
- result[@"messageId"] = messageId;
1031
- resolve(result);
1032
- } @catch (NSException *exception) {
1033
- reject(@"SEND_VOICE_MESSAGE_ERROR", exception.reason, nil);
1034
- }
1100
+
1101
+ NSMutableDictionary *result = [self convertMessageToDictionary:message];
1102
+ result[@"messageId"] = messageId;
1103
+ resolve(result);
1104
+ } @catch (NSException *exception) {
1105
+ reject(@"SEND_VOICE_MESSAGE_ERROR", exception.reason, nil);
1106
+ }
1035
1107
  }
1036
1108
 
1037
1109
  /**
1038
1110
  * 获取历史消息
1039
1111
  */
1040
- RCT_EXPORT_METHOD(getMessages:(NSDictionary *)conversationDict
1041
- direction:(int)direction
1042
- options:(NSDictionary *)options
1043
- resolver:(RCTPromiseResolveBlock)resolve
1044
- rejecter:(RCTPromiseRejectBlock)reject) {
1045
- @try {
1046
- JConversation *conversation = [self convertDictionaryToConversation:conversationDict];
1047
- JGetMessageOptions *getOptions = [[JGetMessageOptions alloc] init];
1048
-
1049
- if (options[@"count"]) {
1050
- getOptions.count = [options[@"count"] integerValue];
1051
- }
1052
- if (options[@"startTime"]) {
1053
- getOptions.startTime = [options[@"startTime"] longLongValue];
1054
- }
1055
-
1056
- JPullDirection pullDirection = direction == 0 ? JPullDirectionOlder : JPullDirectionNewer;
1057
-
1058
- [JIM.shared.messageManager getMessages:conversation
1059
- direction:pullDirection
1060
- option:getOptions
1061
- complete:^(NSArray<JMessage *> *messages, long long timestamp, BOOL hasMore, JErrorCode code) {
1062
- NSMutableArray *messageArray = [NSMutableArray array];
1063
- for (JMessage *msg in messages) {
1064
- [messageArray addObject:[self convertMessageToDictionary:msg]];
1065
- }
1066
- NSLog(@"getMessages complete: %lu messages, timestamp: %lld, hasMore: %d, code: %ld",
1067
- (unsigned long)messages.count, timestamp, hasMore, (long)code);
1068
- NSDictionary *result = @{
1069
- @"messages": messageArray,
1070
- @"timestamp": @(timestamp),
1071
- @"hasMore": @(hasMore),
1072
- @"code": @(code)
1073
- };
1074
-
1075
- resolve(result);
1076
- }];
1077
- } @catch (NSException *exception) {
1078
- reject(@"GET_MESSAGES_ERROR", exception.reason, nil);
1112
+ RCT_EXPORT_METHOD(getMessages : (NSDictionary *)conversationDict direction : (
1113
+ int)direction options : (NSDictionary *)
1114
+ options resolver : (RCTPromiseResolveBlock)
1115
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
1116
+ @try {
1117
+ JConversation *conversation =
1118
+ [self convertDictionaryToConversation:conversationDict];
1119
+ JGetMessageOptions *getOptions = [[JGetMessageOptions alloc] init];
1120
+
1121
+ if (options[@"count"]) {
1122
+ getOptions.count = [options[@"count"] integerValue];
1079
1123
  }
1124
+ if (options[@"startTime"]) {
1125
+ getOptions.startTime = [options[@"startTime"] longLongValue];
1126
+ }
1127
+
1128
+ JPullDirection pullDirection =
1129
+ direction == 0 ? JPullDirectionOlder : JPullDirectionNewer;
1130
+
1131
+ [JIM.shared.messageManager
1132
+ getMessages:conversation
1133
+ direction:pullDirection
1134
+ option:getOptions
1135
+ complete:^(NSArray<JMessage *> *messages, long long timestamp,
1136
+ BOOL hasMore, JErrorCode code) {
1137
+ NSMutableArray *messageArray = [NSMutableArray array];
1138
+ for (JMessage *msg in messages) {
1139
+ [messageArray addObject:[self convertMessageToDictionary:msg]];
1140
+ }
1141
+ NSLog(@"getMessages complete: %lu messages, timestamp: %lld, "
1142
+ @"hasMore: %d, code: %ld",
1143
+ (unsigned long)messages.count, timestamp, hasMore,
1144
+ (long)code);
1145
+ NSDictionary *result = @{
1146
+ @"messages" : messageArray,
1147
+ @"timestamp" : @(timestamp),
1148
+ @"hasMore" : @(hasMore),
1149
+ @"code" : @(code)
1150
+ };
1151
+
1152
+ resolve(result);
1153
+ }];
1154
+ } @catch (NSException *exception) {
1155
+ reject(@"GET_MESSAGES_ERROR", exception.reason, nil);
1156
+ }
1080
1157
  }
1081
1158
 
1082
1159
  /**
1083
1160
  * 撤回消息
1084
1161
  */
1085
- RCT_EXPORT_METHOD(recallMessage:(NSString *)messageId
1086
- extras:(NSDictionary *)extras
1087
- resolver:(RCTPromiseResolveBlock)resolve
1088
- rejecter:(RCTPromiseRejectBlock)reject) {
1089
- @try {
1090
- NSDictionary *extrasDict = extras ?: @{};
1091
-
1092
- [JIM.shared.messageManager recallMessage:messageId
1093
- extras:extrasDict
1094
- success:^(JMessage *message){
1095
- resolve(@YES);
1096
- } error:^(JErrorCode errorCode) {
1097
- reject(@"RECALL_MESSAGE_ERROR", [NSString stringWithFormat:@"Error code: %ld", (long)errorCode], nil);
1162
+ RCT_EXPORT_METHOD(recallMessage : (NSString *)messageId extras : (
1163
+ NSDictionary *)extras resolver : (RCTPromiseResolveBlock)
1164
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
1165
+ @try {
1166
+ NSDictionary *extrasDict = extras ?: @{};
1167
+
1168
+ [JIM.shared.messageManager recallMessage:messageId
1169
+ extras:extrasDict
1170
+ success:^(JMessage *message) {
1171
+ resolve(@YES);
1172
+ }
1173
+ error:^(JErrorCode errorCode) {
1174
+ reject(
1175
+ @"RECALL_MESSAGE_ERROR",
1176
+ [NSString stringWithFormat:@"Error code: %ld", (long)errorCode],
1177
+ nil);
1098
1178
  }];
1099
- } @catch (NSException *exception) {
1100
- reject(@"RECALL_MESSAGE_ERROR", exception.reason, nil);
1101
- }
1179
+ } @catch (NSException *exception) {
1180
+ reject(@"RECALL_MESSAGE_ERROR", exception.reason, nil);
1181
+ }
1102
1182
  }
1103
1183
 
1104
1184
  /**
1105
1185
  * 根据clientMsgNo列表删除消息
1106
1186
  */
1107
- RCT_EXPORT_METHOD(deleteMessagesByClientMsgNoList:(NSDictionary *)conversationMap
1108
- clientMsgNos:(NSArray<NSNumber *> *)clientMsgNos
1109
- resolver:(RCTPromiseResolveBlock)resolve
1110
- rejecter:(RCTPromiseRejectBlock)reject) {
1111
- @try {
1112
- JConversation *conversation = [self convertDictionaryToConversation:conversationMap];
1113
-
1114
- [JIM.shared.messageManager deleteMessagesByClientMsgNoList:clientMsgNos
1115
- conversation:conversation
1116
- success:^{
1117
- resolve(@YES);
1118
- } error:^(JErrorCode errorCode) {
1119
- reject(@"DELETE_MESSAGES_ERROR", [NSString stringWithFormat:@"Error code: %ld", (long)errorCode], nil);
1187
+ RCT_EXPORT_METHOD(deleteMessagesByClientMsgNoList : (
1188
+ NSDictionary *)conversationMap clientMsgNos : (NSArray<NSNumber *> *)
1189
+ clientMsgNos resolver : (RCTPromiseResolveBlock)
1190
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
1191
+ @try {
1192
+ JConversation *conversation =
1193
+ [self convertDictionaryToConversation:conversationMap];
1194
+
1195
+ [JIM.shared.messageManager deleteMessagesByClientMsgNoList:clientMsgNos
1196
+ conversation:conversation
1197
+ success:^{
1198
+ resolve(@YES);
1199
+ }
1200
+ error:^(JErrorCode errorCode) {
1201
+ reject(
1202
+ @"DELETE_MESSAGES_ERROR",
1203
+ [NSString stringWithFormat:@"Error code: %ld", (long)errorCode],
1204
+ nil);
1120
1205
  }];
1121
- } @catch (NSException *exception) {
1122
- reject(@"DELETE_MESSAGES_ERROR", exception.reason, nil);
1123
- }
1206
+ } @catch (NSException *exception) {
1207
+ reject(@"DELETE_MESSAGES_ERROR", exception.reason, nil);
1208
+ }
1124
1209
  }
1125
1210
 
1126
1211
  /**
1127
1212
  * 添加消息反应
1128
1213
  */
1129
- RCT_EXPORT_METHOD(addMessageReaction:(NSDictionary *)messageDict
1130
- reactionId:(NSString *)reactionId
1131
- resolver:(RCTPromiseResolveBlock)resolve
1132
- rejecter:(RCTPromiseRejectBlock)reject) {
1133
- @try {
1134
- NSString *messageId = messageDict[@"messageId"];
1135
- JConversation *conversation = [self convertDictionaryToConversation:messageDict];
1136
-
1137
- [JIM.shared.messageManager addMessageReaction:messageId
1138
- conversation:conversation
1139
- reactionId:reactionId
1140
- success:^{
1141
- resolve(@YES);
1142
- } error:^(JErrorCode errorCode) {
1143
- reject(@"ADD_REACTION_ERROR", [NSString stringWithFormat:@"Error code: %ld", (long)errorCode], nil);
1214
+ RCT_EXPORT_METHOD(
1215
+ addMessageReaction : (NSDictionary *)messageDict reactionId : (NSString *)
1216
+ reactionId resolver : (RCTPromiseResolveBlock)
1217
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
1218
+ @try {
1219
+ NSString *messageId = messageDict[@"messageId"];
1220
+ JConversation *conversation =
1221
+ [self convertDictionaryToConversation:messageDict];
1222
+
1223
+ [JIM.shared.messageManager addMessageReaction:messageId
1224
+ conversation:conversation
1225
+ reactionId:reactionId
1226
+ success:^{
1227
+ resolve(@YES);
1228
+ }
1229
+ error:^(JErrorCode errorCode) {
1230
+ reject(
1231
+ @"ADD_REACTION_ERROR",
1232
+ [NSString stringWithFormat:@"Error code: %ld", (long)errorCode],
1233
+ nil);
1144
1234
  }];
1145
- } @catch (NSException *exception) {
1146
- reject(@"ADD_REACTION_ERROR", exception.reason, nil);
1147
- }
1235
+ } @catch (NSException *exception) {
1236
+ reject(@"ADD_REACTION_ERROR", exception.reason, nil);
1237
+ }
1148
1238
  }
1149
1239
 
1150
1240
  /**
1151
1241
  * 移除消息反应
1152
1242
  */
1153
- RCT_EXPORT_METHOD(removeMessageReaction:(NSDictionary *)messageDict
1154
- reactionId:(NSString *)reactionId
1155
- resolver:(RCTPromiseResolveBlock)resolve
1156
- rejecter:(RCTPromiseRejectBlock)reject) {
1157
- @try {
1158
- NSString *messageId = messageDict[@"messageId"];
1159
- JConversation *conversation = [self convertDictionaryToConversation:messageDict];
1160
-
1161
- [JIM.shared.messageManager removeMessageReaction:messageId
1162
- conversation:conversation
1163
- reactionId:reactionId
1164
- success:^{
1165
- resolve(@YES);
1166
- } error:^(JErrorCode errorCode) {
1167
- reject(@"REMOVE_REACTION_ERROR", @"移除反应失败", [NSError errorWithDomain:@"JuggleIM" code:errorCode userInfo:nil]);
1243
+ RCT_EXPORT_METHOD(removeMessageReaction : (
1244
+ NSDictionary *)messageDict reactionId : (NSString *)
1245
+ reactionId resolver : (RCTPromiseResolveBlock)
1246
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
1247
+ @try {
1248
+ NSString *messageId = messageDict[@"messageId"];
1249
+ JConversation *conversation =
1250
+ [self convertDictionaryToConversation:messageDict];
1251
+
1252
+ [JIM.shared.messageManager removeMessageReaction:messageId
1253
+ conversation:conversation
1254
+ reactionId:reactionId
1255
+ success:^{
1256
+ resolve(@YES);
1257
+ }
1258
+ error:^(JErrorCode errorCode) {
1259
+ reject(@"REMOVE_REACTION_ERROR", @"移除反应失败",
1260
+ [NSError errorWithDomain:@"JuggleIM"
1261
+ code:errorCode
1262
+ userInfo:nil]);
1168
1263
  }];
1169
- } @catch (NSException *exception) {
1170
- reject(@"REMOVE_REACTION_ERROR", exception.reason, nil);
1171
- }
1264
+ } @catch (NSException *exception) {
1265
+ reject(@"REMOVE_REACTION_ERROR", exception.reason, nil);
1266
+ }
1172
1267
  }
1173
1268
 
1174
1269
  // 辅助方法:将字典转换为消息内容
1175
1270
  - (JMessageContent *)convertDictToMessageContent:(NSDictionary *)messageDict {
1176
- NSString *contentType = messageDict[@"contentType"];
1177
-
1178
- if ([contentType isEqualToString:@"jg:text"]) {
1179
- JTextMessage *text = [[JTextMessage alloc] initWithContent:messageDict[@"content"] ?: @""];
1180
- return text;
1181
- } else if ([contentType isEqualToString:@"jg:img"]) {
1182
- JImageMessage *img = [[JImageMessage alloc] init];
1183
- img.url = messageDict[@"url"];
1184
- img.localPath = messageDict[@"localPath"];
1185
- img.thumbnailLocalPath = messageDict[@"thumbnailLocalPath"];
1186
- img.thumbnailUrl = messageDict[@"thumbnailUrl"];
1187
- img.width = [messageDict[@"width"] integerValue];
1188
- img.height = [messageDict[@"height"] integerValue];
1189
- return img;
1190
- } else if ([contentType isEqualToString:@"jg:file"]) {
1191
- JFileMessage *file = [[JFileMessage alloc] init];
1192
- file.url = messageDict[@"url"];
1193
- file.type = messageDict[@"type"];
1194
- file.name = messageDict[@"name"];
1195
- file.size = [messageDict[@"size"] longLongValue];
1196
- return file;
1197
- } else if ([contentType isEqualToString:@"jg:voice"]) {
1198
- JVoiceMessage *voice = [[JVoiceMessage alloc] init];
1199
- voice.url = messageDict[@"url"];
1200
- voice.localPath = messageDict[@"localPath"];
1201
- voice.duration = [messageDict[@"duration"] integerValue];
1202
- return voice;
1203
- }
1204
-
1205
- return nil;
1271
+ NSString *contentType = messageDict[@"contentType"];
1272
+
1273
+ if ([contentType isEqualToString:@"jg:text"]) {
1274
+ JTextMessage *text =
1275
+ [[JTextMessage alloc] initWithContent:messageDict[@"content"] ?: @""];
1276
+ return text;
1277
+ } else if ([contentType isEqualToString:@"jg:img"]) {
1278
+ JImageMessage *img = [[JImageMessage alloc] init];
1279
+ img.url = messageDict[@"url"];
1280
+ img.localPath = messageDict[@"localPath"];
1281
+ img.thumbnailLocalPath = messageDict[@"thumbnailLocalPath"];
1282
+ img.thumbnailUrl = messageDict[@"thumbnailUrl"];
1283
+ img.width = [messageDict[@"width"] integerValue];
1284
+ img.height = [messageDict[@"height"] integerValue];
1285
+ return img;
1286
+ } else if ([contentType isEqualToString:@"jg:file"]) {
1287
+ JFileMessage *file = [[JFileMessage alloc] init];
1288
+ file.url = messageDict[@"url"];
1289
+ file.type = messageDict[@"type"];
1290
+ file.name = messageDict[@"name"];
1291
+ file.size = [messageDict[@"size"] longLongValue];
1292
+ return file;
1293
+ } else if ([contentType isEqualToString:@"jg:voice"]) {
1294
+ JVoiceMessage *voice = [[JVoiceMessage alloc] init];
1295
+ voice.url = messageDict[@"url"];
1296
+ voice.localPath = messageDict[@"localPath"];
1297
+ voice.duration = [messageDict[@"duration"] integerValue];
1298
+ return voice;
1299
+ }
1300
+
1301
+ return nil;
1206
1302
  }
1207
1303
  @end