Skip to content

Commit 4e93cb0

Browse files
guangyaoguangyao
authored andcommitted
add custom message
1 parent 2687258 commit 4e93cb0

File tree

10 files changed

+63
-21
lines changed

10 files changed

+63
-21
lines changed

im/Session.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ class Session {
185185
sendBankTransferMessage(amount, comments, serialNo){
186186
return RNNeteaseIm.sendBankTransferMessage(amount, comments, serialNo)
187187
}
188+
/**
189+
* 发送自定义消息
190+
* @param attachment 自定义消息内容{Width:260,Height:100,pushContent:'发来一条自定义消息',recentContent:'[自定义消息]'}
191+
* Width 消息宽度,Height:消息高度, pushContent:推送消息内容, recentContent:最近会话显示的内容,
192+
* @returns {*}
193+
*/
194+
sendCustomMessage(attachment){
195+
return RNNeteaseIm.sendCustomMessage(attachment);
196+
}
188197
/**
189198
* 开启录音权限
190199
* @returns {*}

ios/RNNeteaseIm/RNNeteaseIm.xcodeproj/xcuserdata/Dowin.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>RNNeteaseIm.xcscheme</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>55</integer>
10+
<integer>15</integer>
1111
</dict>
1212
</dict>
1313
<key>SuppressBuildableAutocreation</key>

ios/RNNeteaseIm/RNNeteaseIm/ConversationViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef void(^Errors)(id erro);
3636
//发送视频
3737
-(void)sendTextMessage:( NSString *)path duration:( NSString *)duration width:( NSString *)width height:( NSString *)height displayName:( NSString *)displayName;
3838
//发送自定义消息
39-
-(void)sendCustomMessage:( NSString *)attachment config:( NSString *)config;
39+
-(void)sendCustomMessage:(NSDictionary *)dataDict;
4040
//发送地理位置消息
4141
-(void)sendLocationMessage:( NSString *)latitude longitude:( NSString *)longitude address:( NSString *)address;
4242
//发送提醒消息

ios/RNNeteaseIm/RNNeteaseIm/ConversationViewController.m

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ - (void)resendMessage:(NSString *)messageID{
9090
}
9191
}
9292
}
93-
93+
//聊天界面历史记录
9494
-(void)localSession:(NSInteger)index cerrentmessageId:(NSString *)currentMessageID success:(Success)succe err:(Errors)err{
9595
_index = index;
9696
[[NIMSDK sharedSDK].conversationManager markAllMessagesReadInSession:_session];
@@ -320,6 +320,12 @@ -(NSMutableArray *)setTimeArr:(NSArray *)messageArr{
320320
[dic setObject:@"card" forKey:@"msgType"];
321321
}
322322
break;
323+
case CustomMessgeTypeCustom://自定义
324+
{
325+
[dic setObject:obj.dataDict forKey:@"extend"];
326+
[dic setObject:@"custom" forKey:@"msgType"];
327+
}
328+
break;
323329
default:
324330
{
325331
[dic setObject:obj.dataDict forKey:@"extend"];
@@ -418,16 +424,27 @@ -(void)sendTextMessage:( NSString *)path duration:( NSString *)duration width:
418424
}
419425

420426
//发送自定义消息
421-
-(void)sendCustomMessage:( NSString *)attachment config:( NSString *)config{
427+
-(void)sendCustomMessage:(NSDictionary *)dataDict{
428+
NSString *strW = [dataDict objectForKey:@"Width"] ? [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"Width"]] : @"0";
429+
NSString *strH = [dataDict objectForKey:@"Height"] ? [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"Height"]] : @"0";
430+
[dataDict setValue:strW forKey:@"Width"];
431+
[dataDict setValue:strH forKey:@"Height"];
432+
[self sendCustomMessage:CustomMessgeTypeCustom data:dataDict];
433+
}
434+
435+
//发送自定义消息2
436+
-(void)sendCustomMessage:(NSInteger )custType data:(NSDictionary *)dataDict{
422437
NIMMessage *message;
423-
NIMObject *obj = [NIMObject initNIMObject];
424-
obj.attachment =attachment;
425-
message = [NIMMessageMaker msgWithCustom:obj andeSession:_session];
438+
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
439+
obj.custType = custType;
440+
obj.dataDict = dataDict;
441+
message = [NIMMessageMaker msgWithCustomAttachment:obj andeSession:_session];
426442
if ([self isFriendToSendMessage:message]) {
427443
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
428444
}
429445
}
430446

447+
431448
//发送地理位置消息
432449
-(void)sendLocationMessage:( NSString *)latitude longitude:( NSString *)longitude address:( NSString *)address{
433450
NIMLocationObject *locaObj = [[NIMLocationObject alloc]initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue] title:address];
@@ -437,17 +454,6 @@ -(void)sendLocationMessage:( NSString *)latitude longitude:( NSString *)longit
437454
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
438455
}
439456
}
440-
//发送自定义消息2
441-
-(void)sendCustomMessage:(NSInteger )custType data:(NSDictionary *)dataDict{
442-
NIMMessage *message;
443-
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
444-
obj.custType = custType;
445-
obj.dataDict = dataDict;
446-
message = [NIMMessageMaker msgWithCustomAttachment:obj andeSession:_session];
447-
if ([self isFriendToSendMessage:message]) {
448-
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
449-
}
450-
}
451457

452458
//发送提醒消息
453459
-(void)sendTipMessage:( NSString *)content{
@@ -943,7 +949,6 @@ -(void)refrashMessage:(NIMMessage *)message From:(NSString *)from {
943949
[dic2 setObject:notiObj forKey:@"extend"];
944950

945951
}else if (message.messageType == NIMMessageTypeCustom) {
946-
// [dic setObject:@"custom" forKey:@"msgType"];
947952
NIMCustomObject *customObject = message.messageObject;
948953
DWCustomAttachment *obj = customObject.attachment;
949954
if (obj) {
@@ -992,6 +997,12 @@ -(void)refrashMessage:(NIMMessage *)message From:(NSString *)from {
992997
[dic2 setObject:@"card" forKey:@"msgType"];
993998
}
994999
break;
1000+
case CustomMessgeTypeCustom://自定义
1001+
{
1002+
[dic2 setObject:obj.dataDict forKey:@"extend"];
1003+
[dic2 setObject:@"custom" forKey:@"msgType"];
1004+
}
1005+
break;
9951006
default:
9961007
{
9971008
[dic2 setObject:obj.dataDict forKey:@"extend"];

ios/RNNeteaseIm/RNNeteaseIm/DWCustomAttachment.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ - (NSString *)encodeAttachment{
3131
case CustomMessgeTypeBusinessCard:
3232
strType = @"card";
3333
break;
34+
case CustomMessgeTypeCustom:
35+
strType = @"custom";
36+
break;
3437
default:
3538
strType = @"unknown";
3639
break;

ios/RNNeteaseIm/RNNeteaseIm/DWCustomAttachmentDecoder.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ @implementation DWCustomAttachmentDecoder
3535
custType = CustomMessgeTypeRedPacketOpenMessage;
3636
}else if([strType isEqualToString:@"card"]){//名片
3737
custType = CustomMessgeTypeBusinessCard;
38+
}else if([strType isEqualToString:@"custom"]){//自定义
39+
custType = CustomMessgeTypeCustom;
3840
}else{//未知消息类型
3941
custType = CustomMessgeTypeUnknown;
4042
}

ios/RNNeteaseIm/RNNeteaseIm/NIMViewController.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,11 @@ - (NSString *)getCustomType:(NIMMessage *)message{
397397
}
398398
}
399399
break;
400+
case CustomMessgeTypeCustom: //自定义
401+
{
402+
text = [self dealWithCustomData:obj.dataDict];
403+
}
404+
break;
400405
default:
401406
text = @"[未知消息]";
402407
break;
@@ -405,6 +410,12 @@ - (NSString *)getCustomType:(NIMMessage *)message{
405410
return text;
406411
}
407412

413+
//处理自定义消息
414+
- (NSString *)dealWithCustomData:(NSDictionary *)dict{
415+
NSString *recentContent = [self stringFromKey:@"recentContent" andDict:dict];
416+
return recentContent;
417+
}
418+
408419
//处理拆红包消息
409420
- (NSString *)dealWithData:(NSDictionary *)dict{
410421
NSString *strOpenId = [self stringFromKey:@"openId" andDict:dict];

ios/RNNeteaseIm/RNNeteaseIm/PrefixHeader.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ static DDLogLevel ddLogLevel = DDLogLevelInfo;
4040
#define CustomMessgeTypeAccountNotice 8 //账户通知,与账户金额相关变动 account_notice
4141
#define CustomMessgeTypeRedPacketOpenMessage 9 //发送拆红包
4242
#define CustomMessgeTypeBusinessCard 10 //名片
43+
#define CustomMessgeTypeCustom 102 //名片
4344

4445
#endif /* PrefixHeader_pch */

ios/RNNeteaseIm/RNNeteaseIm/RNNeteaseIm.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ - (void)removAllRecentSessions{
336336
[[ConversationViewController initWithConversationViewController]sendAudioMessage:file duration:duration];
337337
}
338338
//发送自定义消息
339-
RCT_EXPORT_METHOD(sendCustomMessage:(nonnull NSString *)attachment config:(nonnull NSString *)config){
340-
[[ConversationViewController initWithConversationViewController]sendCustomMessage:attachment config:config];
339+
RCT_EXPORT_METHOD(sendCustomMessage:(nonnull NSDictionary *)attachment){
340+
[[ConversationViewController initWithConversationViewController]sendCustomMessage:attachment];
341341
}
342342
//发送视频消息
343343
RCT_EXPORT_METHOD(sendVideoMessage:(nonnull NSString *)file duration:(nonnull NSString *)duration width:(nonnull NSString *)width height:(nonnull NSString *)height displayName:(nonnull NSString *)displayName){

ios/RNNeteaseIm/RNNeteaseIm/Util/NIMMessageMaker.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ + (NIMMessage*)msgWithCustomAttachment:(DWCustomAttachment *)attachment andeSess
8484
text = [NSString stringWithFormat:@"[名片]%@", [attachment.dataDict objectForKey:@"name"]];
8585
}
8686
break;
87+
case CustomMessgeTypeCustom: //自定义
88+
{
89+
text = [NSString stringWithFormat:@"%@", [attachment.dataDict objectForKey:@"pushContent"]];
90+
}
91+
break;
8792
default:
8893
text = @"发来了一条未知消息";
8994
break;

0 commit comments

Comments
 (0)