Skip to content

Commit 9ce7846

Browse files
committed
添加发送名片消息
1 parent b6b2c2c commit 9ce7846

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed

android/src/main/java/com/netease/im/MessageConstant.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class MsgType {
2222
public final static String RED_PACKET = "redpacket";
2323
public final static String RED_PACKET_OPEN = "redpacketOpen";
2424
public final static String LINK = "url";
25+
public final static String CARD = "card";
2526
public final static String CUSTON = "custom";
2627
}
2728

@@ -119,6 +120,13 @@ public static class RedPacketOpen {
119120

120121
}
121122

123+
public static class Card{
124+
public final static String type = "type";
125+
public final static String name = "name";
126+
public final static String imgPath = "imgPath";
127+
public final static String sessionId = "sessionId";
128+
}
129+
122130
public static class Opt {
123131
public final static String MESSAGE = "message";
124132
public final static String OPT = "opt";

android/src/main/java/com/netease/im/RNNeteaseImModule.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,17 @@ public int onResult(int code, IMMessage message) {
11381138
});
11391139
}
11401140

1141+
@ReactMethod
1142+
public void sendCardMessage(String type, String name, String imgPath,String sessionId, final Promise promise){
1143+
sessionService.sendCardMessage(type, name, imgPath, sessionId, new SessionService.OnSendMessageListener() {
1144+
@Override
1145+
public int onResult(int code, IMMessage message) {
1146+
return 0;
1147+
}
1148+
});
1149+
1150+
}
1151+
11411152
//5.发送自定义消息
11421153
// attachment, // 自定义消息附件
11431154
// config // 自定义消息的参数配置选项

android/src/main/java/com/netease/im/ReactCache.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.netease.im.login.LoginService;
1212
import com.netease.im.session.extension.AccountNoticeAttachment;
1313
import com.netease.im.session.extension.BankTransferAttachment;
14+
import com.netease.im.session.extension.CardAttachment;
1415
import com.netease.im.session.extension.CustomAttachment;
1516
import com.netease.im.session.extension.CustomAttachmentType;
1617
import com.netease.im.session.extension.DefaultCustomAttachment;
@@ -257,6 +258,17 @@ public static Object createRecentList(List<RecentContact> recents, int unreadNum
257258
}
258259
}
259260
break;
261+
case CustomAttachmentType.Card:
262+
if (attachment instanceof RedPacketOpenAttachement) {
263+
String str = "";
264+
if (fromAccount.equals(LoginService.getInstance().getAccount())) {
265+
str = "推荐了";
266+
} else {
267+
str = "向你推荐了";
268+
}
269+
content = str + ((CardAttachment) attachment).getName();
270+
}
271+
break;
260272
default:
261273
if (attachment instanceof DefaultCustomAttachment) {
262274
content = ((DefaultCustomAttachment) attachment).getDigst();
@@ -774,6 +786,9 @@ static String getMessageType(IMMessage item) {
774786
case CustomAttachmentType.RedPacketOpen:
775787
type = MessageConstant.MsgType.RED_PACKET_OPEN;
776788
break;
789+
case CustomAttachmentType.Card:
790+
type = MessageConstant.MsgType.CARD;
791+
break;
777792
default:
778793
type = MessageConstant.MsgType.CUSTON;
779794
break;
@@ -966,6 +981,12 @@ public static WritableMap createMessage(IMMessage item) {
966981
itemMap.putMap(MESSAGE_EXTEND, rpOpen.toReactNative());
967982
}
968983
break;
984+
case CustomAttachmentType.Card:
985+
if (attachment instanceof CardAttachment) {
986+
CardAttachment cardAttachment = (CardAttachment) attachment;
987+
itemMap.putMap(MESSAGE_EXTEND, cardAttachment.toReactNative());
988+
}
989+
break;
969990
default:
970991
if (attachment instanceof DefaultCustomAttachment) {
971992
DefaultCustomAttachment defaultCustomAttachment = (DefaultCustomAttachment) attachment;

android/src/main/java/com/netease/im/session/SessionService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.netease.im.ReactCache;
1717
import com.netease.im.login.LoginService;
1818
import com.netease.im.session.extension.BankTransferAttachment;
19+
import com.netease.im.session.extension.CardAttachment;
1920
import com.netease.im.session.extension.CustomAttachment;
2021
import com.netease.im.session.extension.CustomAttachmentType;
2122
import com.netease.im.session.extension.DefaultCustomAttachment;
@@ -99,6 +100,7 @@ public class SessionService {
99100
private SessionService() {
100101
}
101102

103+
102104
static class InstanceHolder {
103105
final static SessionService instance = new SessionService();
104106
}
@@ -759,6 +761,14 @@ public void sendRedPacketMessage(String type, String comments, String serialNo,
759761
sendMessageSelf(message, onSendMessageListener, false);
760762
}
761763

764+
public void sendCardMessage(String type, String name, String imgPath, String sessionId, OnSendMessageListener onSendMessageListener) {
765+
CustomMessageConfig config = new CustomMessageConfig();
766+
CardAttachment attachment = new CardAttachment();
767+
attachment.setParams(type, name, imgPath, sessionId);
768+
IMMessage message = MessageBuilder.createCustomMessage(sessionId, sessionTypeEnum, "[名片] " + name, attachment, config);
769+
sendMessageSelf(message, onSendMessageListener, false);
770+
}
771+
762772
public void sendBankTransferMessage(String amount, String comments, String serialNo, OnSendMessageListener onSendMessageListener) {
763773
CustomMessageConfig config = new CustomMessageConfig();
764774
BankTransferAttachment attachment = new BankTransferAttachment();
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.netease.im.session.extension;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import com.facebook.react.bridge.Arguments;
5+
import com.facebook.react.bridge.WritableMap;
6+
import com.netease.im.MessageConstant;
7+
8+
/**
9+
* Created by dowin on 2017/10/23.
10+
*/
11+
12+
public class CardAttachment extends CustomAttachment {
13+
14+
private String type;
15+
private String name;
16+
private String imgPath;
17+
private String sessionId;
18+
19+
public CardAttachment() {
20+
super(CustomAttachmentType.Card);
21+
}
22+
23+
@Override
24+
protected void parseData(JSONObject data) {
25+
type = data.getString(MessageConstant.Card.type);
26+
name = data.getString(MessageConstant.Card.name);
27+
imgPath = data.getString(MessageConstant.Card.imgPath);
28+
sessionId = data.getString(MessageConstant.Card.sessionId);
29+
}
30+
31+
public void setParams(String type, String name, String imgPath, String sessionId) {
32+
this.type = type;
33+
this.name = name;
34+
this.imgPath = imgPath;
35+
this.sessionId = sessionId;
36+
}
37+
38+
@Override
39+
public String getType() {
40+
return type;
41+
}
42+
43+
public String getName() {
44+
return name;
45+
}
46+
47+
public String getImgPath() {
48+
return imgPath;
49+
}
50+
51+
@Override
52+
protected JSONObject packData() {
53+
JSONObject object = new JSONObject();
54+
object.put(MessageConstant.Card.type, type);
55+
object.put(MessageConstant.Card.name, name);
56+
object.put(MessageConstant.Card.imgPath, imgPath);
57+
object.put(MessageConstant.Card.sessionId, sessionId);
58+
return object;
59+
}
60+
61+
@Override
62+
public WritableMap toReactNative() {
63+
WritableMap writableMap = Arguments.createMap();
64+
writableMap.putString(MessageConstant.Card.type, type);
65+
writableMap.putString(MessageConstant.Card.name, name);
66+
writableMap.putString(MessageConstant.Card.imgPath, imgPath);
67+
writableMap.putString(MessageConstant.Card.sessionId, sessionId);
68+
return writableMap;
69+
}
70+
}

android/src/main/java/com/netease/im/session/extension/CustomAttachParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public MsgAttachment parse(String json) {
3939
case CustomAttachmentType.AccountNotice:
4040
attachment = new AccountNoticeAttachment();
4141
break;
42+
case CustomAttachmentType.Card:
43+
attachment = new CardAttachment();
44+
break;
4245
default:
4346
attachment = new DefaultCustomAttachment(type);
4447
break;

android/src/main/java/com/netease/im/session/extension/CustomAttachmentType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ public interface CustomAttachmentType {
1919

2020
String LinkUrl = "url";//链接
2121
String AccountNotice = "account_notice";//账户变动通知
22+
String Card = "card";//账户变动通知
2223

2324
}

0 commit comments

Comments
 (0)