Skip to content

Commit 29523e2

Browse files
committed
update iOS plugin add chatroom api
1 parent ffe20d0 commit 29523e2

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

ios/RCTJMessageModule/JMessageHelper.m

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,25 @@ @implementation JMSGConversation (JMessage)
252252
-(NSMutableDictionary*)conversationToDictionary{
253253
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
254254

255-
if (self.conversationType == kJMSGConversationTypeSingle) {
256-
JMSGUser *user = self.target;
257-
dict[@"target"] = [user userToDictionary];
258-
dict[@"conversationType"] = @"single";
259-
260-
} else {
261-
JMSGGroup *group = self.target;
262-
dict[@"target"] = [group groupToDictionary];
263-
dict[@"conversationType"] = @"group";
255+
switch (self.conversationType) {
256+
case kJMSGConversationTypeSingle:{
257+
JMSGUser *user = self.target;
258+
dict[@"target"] = [user userToDictionary];
259+
dict[@"conversationType"] = @"single";
260+
break;
261+
}
262+
case kJMSGConversationTypeGroup:{
263+
JMSGGroup *group = self.target;
264+
dict[@"target"] = [group groupToDictionary];
265+
dict[@"conversationType"] = @"group";
266+
break;
267+
}
268+
case kJMSGConversationTypeChatRoom:{
269+
JMSGChatRoom *chatRoom = self.target;
270+
dict[@"target"] = [chatRoom chatRoomToDictionary];
271+
dict[@"conversationType"] = @"chatRoom";
272+
break;
273+
}
264274
}
265275

266276
dict[@"latestMessage"] = [self.latestMessage messageToDictionary];
@@ -355,12 +365,23 @@ - (NSMutableDictionary *)messageToDictionary {
355365
dict[@"extras"] = self.content.extras;
356366
}
357367

358-
if (self.targetType == kJMSGConversationTypeSingle) {
359-
JMSGUser *user = self.target;
360-
dict[@"target"] = [user userToDictionary];
361-
} else {
362-
JMSGGroup *group = self.target;
363-
dict[@"target"] = [group groupToDictionary];
368+
switch (self.targetType) {
369+
case kJMSGConversationTypeSingle: {
370+
JMSGUser *user = self.target;
371+
dict[@"target"] = [user userToDictionary];
372+
break;
373+
}
374+
375+
case kJMSGConversationTypeGroup:{
376+
JMSGGroup *group = self.target;
377+
dict[@"target"] = [group groupToDictionary];
378+
break;
379+
}
380+
case kJMSGConversationTypeChatRoom:{
381+
JMSGChatRoom *chatRoom= self.target;
382+
dict[@"target"] = [chatRoom chatRoomToDictionary];
383+
break;
384+
}
364385
}
365386

366387
dict[@"createTime"] = self.timestamp;
@@ -520,7 +541,7 @@ - (NSDictionary *)errorToDictionary {
520541
@implementation JMSGChatRoom (JMessage)
521542
- (NSMutableDictionary *)chatRoomToDictionary {
522543
NSMutableDictionary *dict = @{}.mutableCopy;
523-
dict[@"type"] = @"chatroom";
544+
dict[@"type"] = @"chatRoom";
524545
dict[@"roomId"] = self.roomID;
525546
dict[@"roomName"] = self.name;
526547
dict[@"appKey"] = self.appkey;

ios/RCTJMessageModule/RCTJMessageModule.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ - (JMSGConversationType)convertStringToConvsersationType:(NSString *)str {
326326
return kJMSGConversationTypeGroup;
327327
}
328328

329-
if ([str isEqualToString:@"chatroom"]) {
329+
if ([str isEqualToString:@"chatRoom"]) {
330330
return kJMSGConversationTypeChatRoom;
331331
}
332332

@@ -1726,15 +1726,13 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
17261726
return;
17271727
}
17281728

1729-
if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) {
1729+
if (([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) ||
1730+
([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) ||
1731+
([param[@"type"] isEqual: @"chatRoom"] && param[@"roomId"] != nil)) {
17301732

17311733
} else {
1732-
if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) {
1733-
1734-
} else {
1735-
failCallback(@[[self getParamError]]);
1736-
return;
1737-
}
1734+
failCallback(@[[self getParamError]]);
1735+
return;
17381736
}
17391737

17401738
NSString *appKey = nil;
@@ -2264,15 +2262,18 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
22642262
NSNumber *start = nil;
22652263
NSNumber *count = nil;
22662264
if (!param[@"start"]) {
2267-
start = param[@"start"];
2265+
failCallback(@[[self getParamError]]);
22682266
return;
22692267
}
22702268

22712269
if (!param[@"count"]) {
2272-
count = param[@"count"];
2270+
failCallback(@[[self getParamError]]);
22732271
return;
22742272
}
22752273

2274+
start = param[@"start"];
2275+
count = param[@"count"];
2276+
22762277
NSString *appKey = nil;
22772278
if (param[@"appKey"]) {
22782279
appKey = param[@"appKey"];
@@ -2301,8 +2302,7 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
23012302
* @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {}
23022303
*/
23032304
//static getChatRoomListByUser(success, error) {
2304-
RCT_EXPORT_METHOD(getChatRoomListByUser:(NSDictionary *)param
2305-
successCallback:(RCTResponseSenderBlock)successCallback
2305+
RCT_EXPORT_METHOD(getChatRoomListByUser:(RCTResponseSenderBlock)successCallback
23062306
failCallBack:(RCTResponseSenderBlock)failCallback) {
23072307
[JMSGChatRoom getMyChatRoomListCompletionHandler:^(id resultObject, NSError *error) {
23082308
if (error) {

0 commit comments

Comments
 (0)