Skip to content

Commit 6b07b33

Browse files
guangyaoguangyao
authored andcommitted
2 parents 750d84a + ce822ca commit 6b07b33

File tree

7 files changed

+223
-75
lines changed

7 files changed

+223
-75
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package com.netease.im;
2+
3+
/**
4+
* Created by dowin on 2017/8/28.
5+
*/
6+
7+
public class MessageConstant {
8+
9+
public class MsgType {
10+
public final static String TEXT = "text";
11+
public final static String VOICE = "voice";
12+
public final static String IMAGE = "image";
13+
public final static String VIDEO = "video";
14+
public final static String FILE = "file";
15+
public final static String ROBOT = "robot";
16+
public final static String BANK_TRANSFER = "bank_transfer";
17+
public final static String ACCOUNT_NOTICE = "account_notice";
18+
public final static String EVENT = "event";
19+
public final static String LOCATION = "location";
20+
public final static String NOTIFICATION = "notification";
21+
public final static String TIP = "tip";
22+
public final static String RED_PACKET = "redpacket";
23+
public final static String RED_PACKET_OPEN = "redpacketOpen";
24+
public final static String LINK = "url";
25+
public final static String CUSTON = "custom";
26+
}
27+
28+
public class MsgStatus {
29+
public final static String SEND_FAILED = "send_failed";
30+
public final static String SEND_GOING = "send_going";
31+
public final static String RECEIVE_FAILED = "receive_failed";
32+
public final static String RECEIVE_SUCCESS = "receive_success";
33+
public final static String RECEIVE_READED = "readed";
34+
}
35+
36+
public class Message {
37+
38+
public static final String MSG_ID = "msgId";
39+
public static final String MSG_TYPE = "msgType";
40+
public static final String IS_OUTGOING = "isOutgoing";
41+
public static final String TIME_STRING = "timeString";
42+
public static final String MSG_TEXT = "text";
43+
public static final String STATUS = "status";
44+
45+
public static final String FROM_USER = "fromUser";
46+
public static final String EXTEND = "extend";
47+
48+
public static final String IS_REMOTE_READ = "isRemoteRead";
49+
public static final String ATTACH_STATUS = "attachStatus";
50+
public static final String SESSION_TYPE = "sessionType";
51+
public static final String SESSION_ID = "sessionId";
52+
53+
54+
public static final String TIME = "time";
55+
}
56+
57+
58+
public static class User {
59+
public static final String USER_ID = "_id";
60+
public static final String DISPLAY_NAME = "name";
61+
public static final String AVATAR_PATH = "avatar";
62+
}
63+
64+
public static class AccountNotice {
65+
public final static String TITLE = "title";
66+
public final static String TIME = "time";
67+
public final static String DATE = "date";
68+
public final static String AMOUNT = "amount";
69+
public final static String BODY = "body";
70+
public final static String SERIA_NO = "serialNo";
71+
}
72+
73+
public static class BankTransfer {
74+
public final static String AMOUNT = "amount";
75+
public final static String SERIA_NO = "serialNo";
76+
public final static String COMMENTS = "comments";
77+
}
78+
79+
public static class Link {
80+
public final static String TITLE = "title";
81+
public final static String DESCRIBE = "describe";
82+
public final static String IMAGE = "image";
83+
public final static String LINK_URL = "linkUrl";
84+
}
85+
86+
public static class Location {
87+
public final static String LATITUDE = "latitude";
88+
public final static String LONGITUDE = "longitude";
89+
public final static String ADDRESS = "address";
90+
}
91+
92+
public static class MediaFile {
93+
public final static String HEIGHT = "height";
94+
public final static String WIDTH = "width";
95+
public final static String DISPLAY_NAME = "displayName";
96+
public final static String DURATION = "duration";
97+
public final static String THUMB_PATH = "thumbPath";
98+
public final static String PATH = "path";
99+
public final static String URL = "url";
100+
101+
public final static String SIZE = "size";
102+
}
103+
104+
public static class RedPacket {
105+
public final static String TYPE = "type";
106+
public final static String COMMENTS = "comments";
107+
public final static String SERIA_NO = "seriaNo";
108+
}
109+
110+
public static class RedPacketOpen {
111+
public final static String HAS_RED_PACKET = "hasRedPacket";
112+
public final static String SERIA_NO = "seriaNo";
113+
public final static String TIP_MSG = "tipMsg";
114+
115+
public final static String SEND_ID = "sendId";
116+
public final static String OPEN_ID = "openId";
117+
118+
}
119+
120+
public static class Opt {
121+
public final static String MESSAGE = "message";
122+
public final static String OPT = "opt";
123+
public final static String REVOKE = "revoke";
124+
public final static String DELETE = "delete";
125+
public final static String RESEND = "resend";
126+
}
127+
128+
public static class Voice {
129+
public final static String MEDIA_PATH = "mediaPath";
130+
public final static String DURATION = "duration";
131+
public final static String STATUS = "status";
132+
public final static String DB = "db";
133+
public final static String TIME = "time";
134+
}
135+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
1919
new RNNeteaseImModule(reactContext));
2020
}
2121

22-
@Override
2322
public List<Class<? extends JavaScriptModule>> createJSModules() {
2423
return Collections.emptyList();
2524
}

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

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -700,38 +700,49 @@ static String boolean2String(boolean bool) {
700700

701701

702702
/**
703+
* case text
704+
* case image
705+
* case voice
706+
* case video
707+
* case location
708+
* case notification
709+
* case redpacket
710+
* case transfer
711+
* case url
712+
* case account_notice
713+
* case redpacketOpen
703714
*
704715
* @return
705716
*/
706717
static String getMessageType(IMMessage item) {
707-
String type = "";
718+
String type = MessageConstant.MsgType.CUSTON;
708719
switch (item.getMsgType()) {
709720
case text:
710-
type = "text";
721+
type = MessageConstant.MsgType.TEXT;
711722
break;
712723
case image:
713-
type = "image";
724+
type = MessageConstant.MsgType.IMAGE;
714725
break;
715726
case audio:
716-
type = "voice";
727+
type = MessageConstant.MsgType.VOICE;
717728
break;
718729
case video:
719-
type = "video";
730+
type = MessageConstant.MsgType.VIDEO;
720731
break;
721732
case location:
722-
type = "location";
733+
type = MessageConstant.MsgType.LOCATION;
723734
break;
724735
case file:
725-
type = "file";
736+
type = MessageConstant.MsgType.FILE;
726737
break;
727738
case notification:
728-
type = "notification";
739+
type = MessageConstant.MsgType.NOTIFICATION;
729740
break;
730741
case tip:
731-
type = "tip";
742+
type = MessageConstant.MsgType.TIP;
732743
break;
733744
case robot:
734-
type = "robot";
745+
type = MessageConstant.MsgType.ROBOT;
735746
break;
736747
case custom:
737748
CustomAttachment attachment = null;
@@ -743,33 +754,39 @@ static String getMessageType(IMMessage item) {
743754
if (attachment != null) {
744755
switch (attachment.getType()) {
745756
case CustomAttachmentType.RedPacket:
746-
type = "red_packet";
757+
type = MessageConstant.MsgType.RED_PACKET;
747758
break;
748759

749760
case CustomAttachmentType.BankTransfer:
750-
type = "bank_transfer";
761+
type = MessageConstant.MsgType.BANK_TRANSFER;
751762
break;
752763
case CustomAttachmentType.AccountNotice:
753-
type = "account_notice";
764+
type = MessageConstant.MsgType.ACCOUNT_NOTICE;
754765
break;
755766
case CustomAttachmentType.LinkUrl:
756-
type = "link";
767+
type = MessageConstant.MsgType.LINK;
757768
break;
758769
case CustomAttachmentType.RedPacketOpen:
759-
type = "red_packet_open";
770+
type = MessageConstant.MsgType.RED_PACKET_OPEN;
760771
break;
761772
default:
773+
type = MessageConstant.MsgType.CUSTON;
774+
break;
762775
}
776+
}else {
777+
type = MessageConstant.MsgType.CUSTON;
763778
}
764779
break;
765780
default:
781+
type = MessageConstant.MsgType.CUSTON;
766782
break;
767783
}
768784

769785
return type;
770786
}
771787

772-
final static String MESSAGE_EXTEND = "extend";
788+
final static String MESSAGE_EXTEND = MessageConstant.Message.EXTEND;
789+
773790
/**
774791
* <br/>uuid 消息ID
775792
* <br/>sessionId 会话id
@@ -787,17 +804,17 @@ static String getMessageType(IMMessage item) {
787804
*/
788805
public static WritableMap createMessage(IMMessage item) {
789806
WritableMap itemMap = Arguments.createMap();
790-
itemMap.putString("_id", item.getUuid());
807+
itemMap.putString(MessageConstant.Message.MSG_ID, item.getUuid());
791808

792-
itemMap.putString("msgType", getMessageType(item));
793-
itemMap.putString("createdAt", Long.toString(item.getTime() / 1000));
794-
itemMap.putString("sessionId", item.getSessionId());
795-
itemMap.putString("sessionType", Integer.toString(item.getSessionType().getValue()));
809+
itemMap.putString(MessageConstant.Message.MSG_TYPE, getMessageType(item));
810+
itemMap.putString(MessageConstant.Message.TIME_STRING, Long.toString(item.getTime() / 1000));
811+
itemMap.putString(MessageConstant.Message.SESSION_ID, item.getSessionId());
812+
itemMap.putString(MessageConstant.Message.SESSION_TYPE, Integer.toString(item.getSessionType().getValue()));
796813

797-
itemMap.putString("direct", Integer.toString(item.getDirect().getValue()));
798-
itemMap.putString("status", Integer.toString(item.getStatus().getValue()));
799-
itemMap.putString("attachStatus", Integer.toString(item.getAttachStatus().getValue()));
800-
itemMap.putString("isRemoteRead", boolean2String(receiveReceiptCheck(item)));
814+
itemMap.putString(MessageConstant.Message.IS_OUTGOING, Integer.toString(item.getDirect().getValue()));
815+
itemMap.putString(MessageConstant.Message.STATUS, Integer.toString(item.getStatus().getValue()));
816+
itemMap.putString(MessageConstant.Message.ATTACH_STATUS, Integer.toString(item.getAttachStatus().getValue()));
817+
itemMap.putString(MessageConstant.Message.IS_REMOTE_READ, boolean2String(receiveReceiptCheck(item)));
801818

802819
WritableMap user = Arguments.createMap();
803820
String fromAccount = item.getFromAccount();
@@ -807,17 +824,16 @@ public static WritableMap createMessage(IMMessage item) {
807824
} catch (Exception e) {
808825
e.printStackTrace();
809826
}
810-
user.putString("_id", fromAccount);
827+
user.putString(MessageConstant.User.USER_ID, fromAccount);
811828

812829
if (item.getSessionType() == SessionTypeEnum.Team && !TextUtils.equals(LoginService.getInstance().getAccount(), fromAccount)) {
813-
user.putString("name", getTeamUserDisplayName(item.getSessionId(), fromAccount));
830+
user.putString(MessageConstant.User.DISPLAY_NAME, getTeamUserDisplayName(item.getSessionId(), fromAccount));
814831
} else {
815-
user.putString("name", !TextUtils.isEmpty(fromNick) ? fromNick : NimUserInfoCache.getInstance().getUserDisplayName(fromAccount));
832+
user.putString(MessageConstant.User.DISPLAY_NAME, !TextUtils.isEmpty(fromNick) ? fromNick : NimUserInfoCache.getInstance().getUserDisplayName(fromAccount));
816833
}
817834
String avatar = NimUserInfoCache.getInstance().getAvatar(fromAccount);
818-
user.putString("avatar", avatar);
819-
user.putString("avatarLocal", ImageLoaderKit.getMemoryCachedAvatar(avatar));
820-
itemMap.putMap("user", user);
835+
user.putString(MessageConstant.User.AVATAR_PATH, avatar);
836+
itemMap.putMap(MessageConstant.Message.FROM_USER, user);
821837

822838
MsgAttachment attachment = item.getAttachment();
823839
String text = "";
@@ -828,54 +844,49 @@ public static WritableMap createMessage(IMMessage item) {
828844
if (attachment instanceof ImageAttachment) {
829845
ImageAttachment imageAttachment = (ImageAttachment) attachment;
830846
if (item.getDirect() == MsgDirectionEnum.Out) {
831-
imageObj.putString("thumbPath2", imageAttachment.getPathForSave());
832-
imageObj.putString("thumbPath", imageAttachment.getPath());
847+
imageObj.putString(MessageConstant.MediaFile.THUMB_PATH, imageAttachment.getPath());
833848
} else {
834-
imageObj.putString("thumbPath2", imageAttachment.getThumbPathForSave());
835-
imageObj.putString("thumbPath", imageAttachment.getThumbPath());
849+
imageObj.putString(MessageConstant.MediaFile.THUMB_PATH, imageAttachment.getThumbPath());
836850
}
837-
imageObj.putString("path2", imageAttachment.getPathForSave());
838-
imageObj.putString("path", imageAttachment.getPath());
839-
imageObj.putString("url", imageAttachment.getUrl());
840-
imageObj.putString("displayName", imageAttachment.getDisplayName());
841-
imageObj.putString("height", Integer.toString(imageAttachment.getHeight()));
842-
imageObj.putString("width", Integer.toString(imageAttachment.getWidth()));
851+
imageObj.putString(MessageConstant.MediaFile.PATH, imageAttachment.getPath());
852+
imageObj.putString(MessageConstant.MediaFile.URL, imageAttachment.getUrl());
853+
imageObj.putString(MessageConstant.MediaFile.DISPLAY_NAME, imageAttachment.getDisplayName());
854+
imageObj.putString(MessageConstant.MediaFile.HEIGHT, Integer.toString(imageAttachment.getHeight()));
855+
imageObj.putString(MessageConstant.MediaFile.WIDTH, Integer.toString(imageAttachment.getWidth()));
843856
}
844857
itemMap.putMap(MESSAGE_EXTEND, imageObj);
845858
} else if (item.getMsgType() == MsgTypeEnum.audio) {
846859
WritableMap audioObj = Arguments.createMap();
847860
if (attachment instanceof AudioAttachment) {
848861
AudioAttachment audioAttachment = (AudioAttachment) attachment;
849-
audioObj.putString("path", audioAttachment.getPath());
850-
audioObj.putString("thumbPath", audioAttachment.getThumbPath());
851-
audioObj.putString("url", audioAttachment.getUrl());
852-
audioObj.putString("duration", Long.toString(audioAttachment.getDuration()));
862+
audioObj.putString(MessageConstant.MediaFile.PATH, audioAttachment.getPath());
863+
audioObj.putString(MessageConstant.MediaFile.THUMB_PATH, audioAttachment.getThumbPath());
864+
audioObj.putString(MessageConstant.MediaFile.URL, audioAttachment.getUrl());
865+
audioObj.putString(MessageConstant.MediaFile.DURATION, Long.toString(audioAttachment.getDuration()));
853866
}
854867
itemMap.putMap(MESSAGE_EXTEND, audioObj);
855868
} else if (item.getMsgType() == MsgTypeEnum.video) {
856869
WritableMap videoDic = Arguments.createMap();
857870
if (attachment instanceof VideoAttachment) {
858871
VideoAttachment videoAttachment = (VideoAttachment) attachment;
859-
videoDic.putString("url", videoAttachment.getUrl());
860-
videoDic.putString("path2", videoAttachment.getPathForSave());
861-
videoDic.putString("path", videoAttachment.getPath());
862-
videoDic.putString("displayName", videoAttachment.getDisplayName());
863-
videoDic.putString("height", Integer.toString(videoAttachment.getHeight()));
864-
videoDic.putString("width", Integer.toString(videoAttachment.getWidth()));
865-
videoDic.putString("duration", Long.toString(videoAttachment.getDuration()));
866-
videoDic.putString("fileLength", Long.toString(videoAttachment.getSize()));
867-
868-
videoDic.putString("thumbPath", videoAttachment.getThumbPath());
869-
videoDic.putString("coverPath", videoAttachment.getThumbPathForSave());
872+
videoDic.putString(MessageConstant.MediaFile.URL, videoAttachment.getUrl());
873+
videoDic.putString(MessageConstant.MediaFile.PATH, videoAttachment.getPath());
874+
videoDic.putString(MessageConstant.MediaFile.DISPLAY_NAME, videoAttachment.getDisplayName());
875+
videoDic.putString(MessageConstant.MediaFile.HEIGHT, Integer.toString(videoAttachment.getHeight()));
876+
videoDic.putString(MessageConstant.MediaFile.WIDTH, Integer.toString(videoAttachment.getWidth()));
877+
videoDic.putString(MessageConstant.MediaFile.DURATION, Long.toString(videoAttachment.getDuration()));
878+
videoDic.putString(MessageConstant.MediaFile.SIZE, Long.toString(videoAttachment.getSize()));
879+
880+
videoDic.putString(MessageConstant.MediaFile.THUMB_PATH, videoAttachment.getThumbPath());
870881
}
871882
itemMap.putMap(MESSAGE_EXTEND, videoDic);
872883
} else if (item.getMsgType() == MsgTypeEnum.location) {
873884
WritableMap locationObj = Arguments.createMap();
874885
if (attachment instanceof LocationAttachment) {
875886
LocationAttachment locationAttachment = (LocationAttachment) attachment;
876-
locationObj.putString("latitude", Double.toString(locationAttachment.getLatitude()));
877-
locationObj.putString("longitude", Double.toString(locationAttachment.getLongitude()));
878-
locationObj.putString("address", locationAttachment.getAddress());
887+
locationObj.putString(MessageConstant.Location.LATITUDE, Double.toString(locationAttachment.getLatitude()));
888+
locationObj.putString(MessageConstant.Location.LONGITUDE, Double.toString(locationAttachment.getLongitude()));
889+
locationObj.putString(MessageConstant.Location.ADDRESS, locationAttachment.getAddress());
879890
}
880891
itemMap.putMap(MESSAGE_EXTEND, locationObj);
881892
} else if (item.getMsgType() == MsgTypeEnum.notification) {
@@ -959,7 +970,7 @@ public static WritableMap createMessage(IMMessage item) {
959970
}
960971

961972
}
962-
itemMap.putString("content", text);
973+
itemMap.putString(MessageConstant.Message.MSG_TEXT, text);
963974

964975
return itemMap;
965976
}

0 commit comments

Comments
 (0)