@@ -204,6 +204,7 @@ - (void)onReceiveMessageDownloadFailed:(JMSGMessage *)message {
204204 * image为{image: ''}
205205 */
206206RCT_EXPORT_METHOD (sendSingleMessage
207+ :(NSString *)appkey
207208 :(NSString *)username
208209 :(NSString *)type
209210 :(NSDictionary *)data
@@ -217,8 +218,9 @@ - (void)onReceiveMessageDownloadFailed:(JMSGMessage *)message {
217218 reject ([@(error.code) stringValue ], error.localizedDescription , error);
218219 return ;
219220 }
220- [self sendMessageWithUserNameOrGID: username
221- isSingle: @YES
221+ [self sendMessageWithUserNameOrGID: appkey
222+ name: username
223+ isSingle: YES
222224 contentType: type
223225 data: data
224226 timeout: 0
@@ -250,8 +252,9 @@ - (void)onReceiveMessageDownloadFailed:(JMSGMessage *)message {
250252 reject ([@(error.code) stringValue ], error.localizedDescription , error);
251253 return ;
252254 }
253- [self sendMessageWithUserNameOrGID: groupId
254- isSingle: @NO
255+ [self sendMessageWithUserNameOrGID: nil
256+ name: groupId
257+ isSingle: NO
255258 contentType: type
256259 data: data
257260 timeout: 0
@@ -302,14 +305,15 @@ - (void)onReceiveMessageDownloadFailed:(JMSGMessage *)message {
302305 switch (conversation.conversationType ) {
303306 case kJMSGConversationTypeSingle :
304307 username = ((JMSGUser*) conversation.target ).username ;
305- isSingle = @ YES ;
308+ isSingle = YES ;
306309 break ;
307310 case kJMSGConversationTypeGroup :
308311 username = ((JMSGGroup*) conversation.target ).gid ;
309- isSingle = @ NO ;
312+ isSingle = NO ;
310313 break ;
311314 }
312- [self sendMessageWithUserNameOrGID: username
315+ [self sendMessageWithUserNameOrGID: nil
316+ name: username
313317 isSingle: isSingle
314318 contentType: type
315319 data: data
@@ -346,21 +350,35 @@ - (void)onReceiveMessageDownloadFailed:(JMSGMessage *)message {
346350 {
347351 JMSGUser *userInfo = conversation.target ;
348352 username = userInfo.username ;
349- cid = [NSString stringWithFormat: @" %@ |%@ " , @(conversation.conversationType), username];
353+ NSData *data = [NSJSONSerialization dataWithJSONObject: @{
354+ @" appkey" : OPTION_NULL (conversation.targetAppKey ),
355+ @" type" : @(conversation.conversationType ),
356+ @" id" : username
357+ }
358+ options: NSJSONWritingPrettyPrinted
359+ error: nil ];
360+ cid = [data base64EncodedStringWithOptions: NSDataBase64Encoding64CharacterLineLength ];
350361 }
351362 break ;
352363 case kJMSGConversationTypeGroup :
353364 {
354365 JMSGGroup *groupInfo = conversation.target ;
355366 groupId = groupInfo.gid ;
356- cid = [NSString stringWithFormat: @" %@ |%@ " , @(conversation.conversationType), groupId];
367+ NSData *data = [NSJSONSerialization dataWithJSONObject: @{
368+ @" appkey" : OPTION_NULL (conversation.targetAppKey ),
369+ @" type" : @(conversation.conversationType ),
370+ @" id" : groupId
371+ }
372+ options: NSJSONWritingPrettyPrinted
373+ error: nil ];
374+ cid = [data base64EncodedStringWithOptions: NSDataBase64Encoding64CharacterLineLength ];
357375 }
358376 break ;
359377 default :
360378 break ;
361379 }
362380
363- [result addObject: @{@" id" : cid,
381+ [result addObject: @{@" id" : OPTION_NULL ( cid) ,
364382 @" type" : @(conversation.conversationType ),
365383 @" typeDesc" : typeDesc,
366384 @" username" : OPTION_NULL (username),
@@ -593,7 +611,8 @@ - (NSDictionary*) getTargetWithMessage:(JMSGMessage *)message {
593611 @param resolve 成功回调
594612 @param reject 失败回调
595613 */
596- - (void ) sendMessageWithUserNameOrGID : (NSString *)name
614+ - (void ) sendMessageWithUserNameOrGID : (NSString *)appkey
615+ name : (NSString *)name
597616 isSingle : (BOOL )isSingle
598617 contentType : (NSString *)type
599618 data : (NSDictionary *)data
@@ -610,7 +629,8 @@ - (void) sendMessageWithUserNameOrGID:(NSString *)name
610629 reject ([@(error.code) stringValue ], error.localizedDescription , error);
611630 return ;
612631 }
613- [self createConversationIsSingle: isSingle
632+ [self createConversationWithAppKey: appkey
633+ isSingle: isSingle
614634 nameOrGID: name
615635 completionHandler: ^(id resultObject, NSError *error) {
616636 if (!error) {
@@ -636,7 +656,8 @@ - (void) sendMessageWithUserNameOrGID:(NSString *)name
636656 reject ([@(error.code) stringValue ], error.localizedDescription , error);
637657 return ;
638658 }
639- [self createConversationIsSingle: isSingle
659+ [self createConversationWithAppKey: appkey
660+ isSingle: isSingle
640661 nameOrGID: name
641662 completionHandler: ^(id resultObject, NSError *error) {
642663 if (!error) {
@@ -654,7 +675,6 @@ - (void) sendMessageWithUserNameOrGID:(NSString *)name
654675 reject ([@(error.code) stringValue ], error.localizedDescription , error);
655676 }
656677 }];
657- NSLog (@" %@ " , imageURL);
658678 } else {
659679 NSError *error = [[NSError alloc ] initWithDomain: @" "
660680 code: kJMSGErrorRNMessageProtocolContentTypeNotSupport
@@ -671,11 +691,16 @@ - (void) sendMessageWithUserNameOrGID:(NSString *)name
671691 @param name 对方用户名(群号)
672692 @param handler 回调
673693 */
674- - (void ) createConversationIsSingle : (BOOL )isSingle
694+ - (void ) createConversationWithAppKey : (NSString *)appkey
695+ isSingle : (BOOL )isSingle
675696 nameOrGID : (NSString *)name
676697 completionHandler : (JMSGCompletionHandler JMSG_NULLABLE)handler {
677698 if (isSingle) {
678- [JMSGConversation createSingleConversationWithUsername: name completionHandler: handler];
699+ if (appkey) {
700+ [JMSGConversation createSingleConversationWithUsername: name appKey: appkey completionHandler: handler];
701+ } else {
702+ [JMSGConversation createSingleConversationWithUsername: name completionHandler: handler];
703+ }
679704 } else {
680705 [JMSGConversation createGroupConversationWithGroupId: name completionHandler: handler];
681706 }
@@ -724,26 +749,33 @@ - (void) detectConversationValidById:(NSString*)cid
724749 userInfo: @{NSLocalizedDescriptionKey : @" 会话无效"
725750 }];
726751
727- NSArray <NSString *> *params = [cid componentsSeparatedByString: @" |" ];
728- if (params.count < 2 ) {
752+ NSData *data = [[NSData alloc ] initWithBase64EncodedString: cid options: NSDataBase64DecodingIgnoreUnknownCharacters ];
753+ NSDictionary * dataDic = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingAllowFragments error: nil ];
754+
755+ NSString *appkey = [dataDic valueForKey: @" appkey" ];
756+ NSNumber *type = [dataDic valueForKey: @" type" ];
757+ NSString *nameOrGID = [dataDic valueForKey: @" id" ];
758+
759+ if (!nameOrGID) {
729760 handler (nil , conversationInvalidError);
730761 return ;
731762 }
732763 BOOL isSingle;
733- NSInteger type = [[params objectAtIndex: 0 ] integerValue ];
734- NSString *nameOrGID = [[params subarrayWithRange: (NSMakeRange (1 , [params count ] - 1 ))] componentsJoinedByString: @" |" ];
735- switch (type) {
764+ switch ([type integerValue ]) {
736765 case kJMSGConversationTypeSingle :
737- isSingle = @ YES ;
766+ isSingle = YES ;
738767 break ;
739768 case kJMSGConversationTypeGroup :
769+ isSingle = NO ;
740770 break ;
741- isSingle = @NO ;
742771 default :
743772 handler (nil , conversationInvalidError);
744773 return ;
745774 }
746- [self createConversationIsSingle: isSingle nameOrGID: nameOrGID completionHandler: ^(id resultObject, NSError *error) {
775+ [self createConversationWithAppKey: appkey
776+ isSingle: isSingle
777+ nameOrGID: nameOrGID
778+ completionHandler: ^(id resultObject, NSError *error) {
747779 if (!error) {
748780 JMSGConversation *conversation = resultObject;
749781 handler (conversation, nil );
0 commit comments