Skip to content

Commit 3286eb2

Browse files
committed
add chatroom event
1 parent d10f561 commit 3286eb2

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

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: 10 additions & 0 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:

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: 42 additions & 3 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
@@ -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
}
@@ -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)