Skip to content

Commit 3102983

Browse files
KenChoiKenChoi
authored andcommitted
Merge branch 'dev' of github.com:jpush/jmessage-react-plugin into dev
2 parents 38a7a7d + 29523e2 commit 3102983

File tree

5 files changed

+125
-46
lines changed

5 files changed

+125
-46
lines changed

example/app/routes/Chat/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ export default class Chat extends Component {
9090
auroraMsg.msgType = "video"
9191
}
9292

93+
if (jmessage.type === 'event') {
94+
// auroraMsg.mediaPath = jmessage.path
95+
// auroraMsg.duration = jmessage.duration
96+
Alert.alert('event' , jmessage.eventType)
97+
auroraMsg.text = jmessage.eventType
98+
}
99+
93100
var user = {
94101
userId: "1",
95102
displayName: "",

ios/RCTJMessageModule/JMessageHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <JMessage/JMessage.h>
1111

1212
#define kJJMessageReceiveMessage @"kJJMessageReceiveMessage"
13+
#define kJJMessageReceiveChatRoomMessage @"kJJMessageReceiveChatRoomMessage"
1314
#define kJJMessageSendMessageRespone @"kJJMessageSendMessageRespone"
1415

1516
//Conversation 回调

ios/RCTJMessageModule/JMessageHelper.m

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ - (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{
7878
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageReceiveMessage object:dict];
7979
}
8080

81+
- (void)onReceiveChatRoomConversation:(JMSGConversation *)conversation messages:(NSArray<__kindof JMSGMessage *> *)messages {
82+
83+
NSArray *msgDicArr = [messages mapObjectsUsingBlock:^id(id obj, NSUInteger idx) {
84+
JMSGMessage *msg = obj;
85+
return [msg messageToDictionary];
86+
}];
87+
88+
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageReceiveChatRoomMessage object:msgDicArr];
89+
}
90+
8191
- (void)onReceiveNotificationEvent:(JMSGNotificationEvent *)event {
8292
switch (event.eventType) {
8393
case kJMSGEventNotificationLoginKicked:
@@ -242,15 +252,25 @@ @implementation JMSGConversation (JMessage)
242252
-(NSMutableDictionary*)conversationToDictionary{
243253
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
244254

245-
if (self.conversationType == kJMSGConversationTypeSingle) {
246-
JMSGUser *user = self.target;
247-
dict[@"target"] = [user userToDictionary];
248-
dict[@"conversationType"] = @"single";
249-
250-
} else {
251-
JMSGGroup *group = self.target;
252-
dict[@"target"] = [group groupToDictionary];
253-
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+
}
254274
}
255275

256276
dict[@"latestMessage"] = [self.latestMessage messageToDictionary];
@@ -345,12 +365,23 @@ - (NSMutableDictionary *)messageToDictionary {
345365
dict[@"extras"] = self.content.extras;
346366
}
347367

348-
if (self.targetType == kJMSGConversationTypeSingle) {
349-
JMSGUser *user = self.target;
350-
dict[@"target"] = [user userToDictionary];
351-
} else {
352-
JMSGGroup *group = self.target;
353-
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+
}
354385
}
355386

356387
dict[@"createTime"] = self.timestamp;
@@ -391,63 +422,63 @@ - (NSMutableDictionary *)messageToDictionary {
391422

392423
switch (eventContent.eventType) {
393424
case kJMSGEventNotificationAcceptedFriendInvitation: {
394-
dict[@"evenType"] = @"acceptedFriendInvitation";
425+
dict[@"eventType"] = @"acceptedFriendInvitation";
395426
break;
396427
}
397428
case kJMSGEventNotificationAddGroupMembers: {
398-
dict[@"evenType"] = @"group_member_added";
429+
dict[@"eventType"] = @"group_member_added";
399430
break;
400431
}
401432
case kJMSGEventNotificationCreateGroup: {
402-
dict[@"evenType"] = @"createGroup";
433+
dict[@"eventType"] = @"createGroup";
403434
break;
404435
}
405436
case kJMSGEventNotificationCurrentUserInfoChange: {
406-
dict[@"evenType"] = @"currentUserInfoChange";
437+
dict[@"eventType"] = @"currentUserInfoChange";
407438
break;
408439
}
409440
case kJMSGEventNotificationDeclinedFriendInvitation: {
410-
dict[@"evenType"] = @"declinedFriendInvitation";
441+
dict[@"eventType"] = @"declinedFriendInvitation";
411442
break;
412443
}
413444
case kJMSGEventNotificationDeletedFriend: {
414-
dict[@"evenType"] = @"deletedFriend";
445+
dict[@"eventType"] = @"deletedFriend";
415446
break;
416447
}
417448
case kJMSGEventNotificationExitGroup: {
418-
dict[@"evenType"] = @"group_member_exit";
449+
dict[@"eventType"] = @"group_member_exit";
419450
break;
420451
}
421452
case kJMSGEventNotificationLoginKicked: {
422-
dict[@"evenType"] = @"loginKicked";
453+
dict[@"eventType"] = @"loginKicked";
423454
break;
424455
}
425456
case kJMSGEventNotificationMessageRetract: {
426-
dict[@"evenType"] = @"messageRetract";
457+
dict[@"eventType"] = @"messageRetract";
427458
break;
428459
}
429460
case kJMSGEventNotificationReceiveFriendInvitation: {
430-
dict[@"evenType"] = @"receiveFriendInvitation";
461+
dict[@"eventType"] = @"receiveFriendInvitation";
431462
break;
432463
}
433464
case kJMSGEventNotificationReceiveServerFriendUpdate: {
434-
dict[@"evenType"] = @"receiveServerFriendUpdate";
465+
dict[@"eventType"] = @"receiveServerFriendUpdate";
435466
break;
436467
}
437468
case kJMSGEventNotificationRemoveGroupMembers: {
438-
dict[@"evenType"] = @"group_member_removed";
469+
dict[@"eventType"] = @"group_member_removed";
439470
break;
440471
}
441472
case kJMSGEventNotificationServerAlterPassword: {
442-
dict[@"evenType"] = @"serverAlterPassword";
473+
dict[@"eventType"] = @"serverAlterPassword";
443474
break;
444475
}
445476
case kJMSGEventNotificationUpdateGroupInfo: {
446-
dict[@"evenType"] = @"updateGroupInfo";
477+
dict[@"eventType"] = @"updateGroupInfo";
447478
break;
448479
}
449480
case kJMSGEventNotificationUserLoginStatusUnexpected: {
450-
dict[@"evenType"] = @"userLoginStatusUnexpected";
481+
dict[@"eventType"] = @"userLoginStatusUnexpected";
451482
break;
452483
}
453484
default:
@@ -510,7 +541,7 @@ - (NSDictionary *)errorToDictionary {
510541
@implementation JMSGChatRoom (JMessage)
511542
- (NSMutableDictionary *)chatRoomToDictionary {
512543
NSMutableDictionary *dict = @{}.mutableCopy;
513-
dict[@"type"] = @"chatroom";
544+
dict[@"type"] = @"chatRoom";
514545
dict[@"roomId"] = self.roomID;
515546
dict[@"roomName"] = self.name;
516547
dict[@"appKey"] = self.appkey;

ios/RCTJMessageModule/RCTJMessageModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
#define receiveMsgEvent @"JMessage.ReceiveMsgEvent" // 接收到消息事件
21+
#define receiveChatRoomMsgEvent @"JMessage.ReceiveChatRoomMsgEvent" // 接收到消息事件
2122
#define conversationChangeEvent @"JMessage.conversationChange" // 会话变更事件
2223
#define loginStateChangedEvent @"JMessage.LoginStateChanged" //
2324
#define clickMessageNotificationEvent @"JMessage.ClickMessageNotification" // 点击推送 Android Only

ios/RCTJMessageModule/RCTJMessageModule.m

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,21 @@ -(void)initNotifications {
6262
[[NSNotificationCenter defaultCenter] removeObserver:self];
6363

6464
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
65-
// have
6665
[defaultCenter addObserver:self
6766
selector:@selector(didReceiveJMessageMessage:)
6867
name:kJJMessageReceiveMessage
6968
object:nil];
7069

70+
[defaultCenter addObserver:self
71+
selector:@selector(didReceiveJMessageChatRoomMessage:)
72+
name:kJJMessageReceiveChatRoomMessage
73+
object:nil];
74+
7175
[defaultCenter addObserver:self
7276
selector:@selector(conversationChanged:)
7377
name:kJJMessageConversationChanged
7478
object:nil];
75-
// have
79+
7680
[defaultCenter addObserver:self
7781
selector:@selector(didSendMessage:)
7882
name:kJJMessageSendMessageRespone
@@ -82,7 +86,7 @@ -(void)initNotifications {
8286
// selector:@selector(unreadChanged:)
8387
// name:kJJMessageUnreadChanged
8488
// object:nil];
85-
// have
89+
8690
[defaultCenter addObserver:self
8791
selector:@selector(loginStateChanged:)
8892
name:kJJMessageLoginStateChanged
@@ -322,7 +326,7 @@ - (JMSGConversationType)convertStringToConvsersationType:(NSString *)str {
322326
return kJMSGConversationTypeGroup;
323327
}
324328

325-
if ([str isEqualToString:@"chatroom"]) {
329+
if ([str isEqualToString:@"chatRoom"]) {
326330
return kJMSGConversationTypeChatRoom;
327331
}
328332

@@ -399,6 +403,11 @@ - (void)didReceiveJMessageMessage:(NSNotification *)notification {
399403
[self.bridge.eventDispatcher sendAppEventWithName:receiveMsgEvent body:notification.object];
400404
}
401405

406+
- (void)didReceiveJMessageChatRoomMessage:(NSNotification *)notification {
407+
[self.bridge.eventDispatcher sendAppEventWithName:receiveChatRoomMsgEvent body:notification.object];
408+
}
409+
410+
402411
- (void)conversationChanged:(NSNotification *)notification {
403412
[self.bridge.eventDispatcher sendAppEventWithName:conversationChangeEvent body:notification.object];
404413
}
@@ -1717,15 +1726,13 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
17171726
return;
17181727
}
17191728

1720-
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)) {
17211732

17221733
} else {
1723-
if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) {
1724-
1725-
} else {
1726-
failCallback(@[[self getParamError]]);
1727-
return;
1728-
}
1734+
failCallback(@[[self getParamError]]);
1735+
return;
17291736
}
17301737

17311738
NSString *appKey = nil;
@@ -2255,15 +2262,18 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
22552262
NSNumber *start = nil;
22562263
NSNumber *count = nil;
22572264
if (!param[@"start"]) {
2258-
start = param[@"start"];
2265+
failCallback(@[[self getParamError]]);
22592266
return;
22602267
}
22612268

22622269
if (!param[@"count"]) {
2263-
count = param[@"count"];
2270+
failCallback(@[[self getParamError]]);
22642271
return;
22652272
}
22662273

2274+
start = param[@"start"];
2275+
count = param[@"count"];
2276+
22672277
NSString *appKey = nil;
22682278
if (param[@"appKey"]) {
22692279
appKey = param[@"appKey"];
@@ -2292,8 +2302,7 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
22922302
* @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {}
22932303
*/
22942304
//static getChatRoomListByUser(success, error) {
2295-
RCT_EXPORT_METHOD(getChatRoomListByUser:(NSDictionary *)param
2296-
successCallback:(RCTResponseSenderBlock)successCallback
2305+
RCT_EXPORT_METHOD(getChatRoomListByUser:(RCTResponseSenderBlock)successCallback
22972306
failCallBack:(RCTResponseSenderBlock)failCallback) {
22982307
[JMSGChatRoom getMyChatRoomListCompletionHandler:^(id resultObject, NSError *error) {
22992308
if (error) {
@@ -2416,5 +2425,35 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
24162425
}];
24172426
}
24182427

2428+
RCT_EXPORT_METHOD(getChatRoomOwner:(NSDictionary *)param
2429+
successCallback:(RCTResponseSenderBlock)successCallback
2430+
failCallBack:(RCTResponseSenderBlock)failCallback) {
2431+
if (!param[@"roomId"]) {
2432+
failCallback(@[[self getParamError]]);
2433+
return;
2434+
}
2435+
2436+
[JMSGChatRoom getChatRoomInfosWithRoomIds:@[param[@"roomId"]] completionHandler:^(id resultObject, NSError *error) {
2437+
if (error) {
2438+
failCallback(@[[error errorToDictionary]]);
2439+
return;
2440+
}
2441+
NSArray *chatRoomArr = resultObject;
2442+
if (chatRoomArr == nil || chatRoomArr.count == 0) {
2443+
failCallback(@[[self getErrorWithLog:@"cann't found chat room from this roomId!"]]);
2444+
return;
2445+
}
2446+
JMSGChatRoom *chatRoom = chatRoomArr[0];
2447+
[chatRoom getChatRoomOwnerInfo:^(id resultObject, NSError *error) {
2448+
if (error) {
2449+
failCallback(@[[error errorToDictionary]]);
2450+
return;
2451+
}
2452+
JMSGUser *user = resultObject;
2453+
successCallback(@[[user userToDictionary]]);
2454+
}];
2455+
}];
2456+
}
2457+
24192458

24202459
@end

0 commit comments

Comments
 (0)