Skip to content

Commit 551bf4e

Browse files
author
wicked-tc130
authored
Merge pull request #145 from wicked-tc130/master
update version code
2 parents 25f2295 + fd87229 commit 551bf4e

File tree

5 files changed

+109
-55
lines changed

5 files changed

+109
-55
lines changed

android/src/io/jchat/android/JMessageModule.java

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class JMessageModule extends ReactContextBaseJavaModule {
100100
private static final int ERR_CODE_CONVERSATION = 2;
101101
private static final int ERR_CODE_MESSAGE = 3;
102102
private static final int ERR_CODE_FILE = 4;
103+
private static final int ERR_CODE_EXCEPTION = -1;
103104

104105
private static final String ERR_MSG_PARAMETER = "Parameters error";
105106
private static final String ERR_MSG_CONVERSATION = "Can't get the conversation";
@@ -2085,49 +2086,87 @@ public void gotResult(int status, String desc) {
20852086
}
20862087

20872088
@ReactMethod
2088-
public void setMsgHaveRead(ReadableMap map, final Callback callback) {
2089-
String userName = map.getString(Constant.USERNAME);
2090-
String appKey = map.getString(Constant.APP_KEY);
2091-
String msgId = map.getString(Constant.ID);
2092-
String serverMsgId = map.getString(Constant.SERVER_ID);
2093-
WritableMap callbackMap = Arguments.createMap();
2094-
if(TextUtils.isEmpty(userName)||
2095-
TextUtils.isEmpty(appKey)||
2096-
TextUtils.isEmpty(msgId)||
2097-
TextUtils.isEmpty(serverMsgId)){
2098-
callbackMap.putInt(Constant.CODE, ERR_CODE_CONVERSATION);
2099-
callbackMap.putString(Constant.DESCRIPTION, ERR_MSG_CONVERSATION);
2100-
callback.invoke(callbackMap);
2101-
return;
2102-
}
2103-
Conversation conversation = JMessageClient.getSingleConversation(userName, appKey);
2104-
if(conversation==null){
2105-
callbackMap.putInt(Constant.CODE, ERR_CODE_CONVERSATION);
2106-
callbackMap.putString(Constant.DESCRIPTION, ERR_MSG_CONVERSATION);
2107-
callback.invoke(callbackMap);
2108-
return;
2109-
}
2110-
//优先使用msgId获取conversation,获取不到再使用serverMsgId获取
2111-
Message message = conversation.getMessage(Integer.parseInt(msgId));
2112-
if(message==null){
2113-
message = conversation.getMessage(Long.parseLong(serverMsgId));
2114-
}
2115-
if (message == null){
2116-
callbackMap.putInt(Constant.CODE, ERR_CODE_MESSAGE);
2117-
callbackMap.putString(Constant.DESCRIPTION, ERR_MSG_MESSAGE);
2118-
callback.invoke(callbackMap);
2119-
return;
2120-
}
2121-
if (!message.haveRead()) {
2089+
public void setMsgHaveRead(ReadableMap map, final Callback successCallback, final Callback failCallback) {
2090+
final WritableMap failMap = Arguments.createMap();
2091+
try {
2092+
String type = map.getString(Constant.TYPE);
2093+
if (TextUtils.isEmpty(type)) {
2094+
failMap.putInt(Constant.CODE, ERR_CODE_PARAMETER);
2095+
failMap.putString(Constant.DESCRIPTION, ERR_MSG_PARAMETER);
2096+
failCallback.invoke(failMap);
2097+
return;
2098+
}
2099+
Conversation conversation;
2100+
switch (type) {
2101+
case Constant.TYPE_SINGLE:
2102+
String userName = map.getString(Constant.USERNAME);
2103+
String appKey = map.getString(Constant.APP_KEY);
2104+
//如果appKey为空则默认取本应用appKey下对应userName用户的会话。
2105+
if (TextUtils.isEmpty(userName)) {
2106+
failMap.putInt(Constant.CODE, ERR_CODE_PARAMETER);
2107+
failMap.putString(Constant.DESCRIPTION, ERR_MSG_PARAMETER);
2108+
failCallback.invoke(failMap);
2109+
return;
2110+
}
2111+
conversation = JMessageClient.getSingleConversation(userName, appKey);
2112+
break;
2113+
case Constant.TYPE_GROUP:
2114+
String groupId = map.getString(Constant.GROUP_ID);
2115+
if (TextUtils.isEmpty(groupId)) {
2116+
failMap.putInt(Constant.CODE, ERR_CODE_PARAMETER);
2117+
failMap.putString(Constant.DESCRIPTION, ERR_MSG_PARAMETER);
2118+
failCallback.invoke(failMap);
2119+
return;
2120+
}
2121+
conversation = JMessageClient.getGroupConversation(Long.parseLong(groupId));
2122+
break;
2123+
case Constant.TYPE_CHAT_ROOM:
2124+
String roomId = map.getString(Constant.ROOM_ID);
2125+
if (TextUtils.isEmpty(roomId)) {
2126+
failMap.putInt(Constant.CODE, ERR_CODE_PARAMETER);
2127+
failMap.putString(Constant.DESCRIPTION, ERR_MSG_PARAMETER);
2128+
failCallback.invoke(failMap);
2129+
return;
2130+
}
2131+
conversation = JMessageClient.getChatRoomConversation(Long.parseLong(roomId));
2132+
break;
2133+
default:
2134+
conversation = null;
2135+
break;
2136+
}
2137+
if (conversation == null) {
2138+
failMap.putInt(Constant.CODE, ERR_CODE_CONVERSATION);
2139+
failMap.putString(Constant.DESCRIPTION, ERR_MSG_CONVERSATION);
2140+
failCallback.invoke(failMap);
2141+
return;
2142+
}
2143+
String messageId = map.getString(Constant.ID);
2144+
Message message = conversation.getMessage(Integer.parseInt(messageId));
2145+
if (message == null) {
2146+
failMap.putInt(Constant.CODE, ERR_CODE_MESSAGE);
2147+
failMap.putString(Constant.DESCRIPTION, ERR_MSG_MESSAGE);
2148+
failCallback.invoke(failMap);
2149+
return;
2150+
}
2151+
if (message.haveRead()) {
2152+
return;
2153+
}
21222154
message.setHaveRead(new BasicCallback() {
21232155
@Override
2124-
public void gotResult(int i, String s) {
2125-
WritableMap map = Arguments.createMap();
2126-
map.putInt(Constant.CODE, i);
2127-
map.putString(Constant.DESCRIPTION, s);
2128-
callback.invoke(map);
2156+
public void gotResult(int code, String message) {
2157+
if (code == 0) {
2158+
successCallback.invoke();
2159+
} else {
2160+
failMap.putInt(Constant.CODE, code);
2161+
failMap.putString(Constant.DESCRIPTION, message);
2162+
failCallback.invoke(failMap);
2163+
}
21292164
}
21302165
});
2166+
}catch (Throwable throwable){
2167+
failMap.putInt(Constant.CODE, ERR_CODE_EXCEPTION);
2168+
failMap.putString(Constant.DESCRIPTION, throwable.getMessage());
2169+
failCallback.invoke(failMap);
21312170
}
21322171
}
21332172

document/API.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ JMessage.createSendMessage({type: 'single', username: 'username', appKey: 'appke
11391139
- isCustomNotificationEnabled: 是否开启自定义接收方通知栏功能,设置为 `true` 后可设置下面的 `notificationTitle``notificationText`。默认未设置。
11401140
- notificationTitle: 设置此条消息在接收方通知栏所展示通知的标题。
11411141
- notificationText: 设置此条消息在接收方通知栏所展示通知的内容。
1142-
- needReadReceipt: 设置这条消息的发送是否需要对方发送已读回执 开启之后,对方收到消息后,如果调用了setMsgHaveRead()接口, 则作为消息发送方,会收到已读消息回执事件通知
1142+
- needReadReceipt: (Android Only)设置这条消息的发送是否需要对方发送已读回执 开启之后,对方收到消息后,如果调用了setMsgHaveRead()接口, 则作为消息发送方,会收到已读消息回执事件通知
11431143

11441144
### sendTextMessage
11451145

@@ -1759,23 +1759,25 @@ JMessage.resetUnreadMessageCount({ type: 'single', username: 'username', appKey:
17591759
17601760
### setMsgHaveRead
17611761
1762-
设置消息已读
1762+
设置消息已读(Android Only)
17631763
17641764
#### 示例
17651765
17661766
```js
1767-
JMessageModule.setMsgHaveRead(params,(result) => {
1767+
JMessageModule.setMsgHaveRead(params,(successCallback) =>{},(failCallback) => {
17681768
var code = result.code
17691769
var desc = result.description
17701770
}
17711771
)
17721772
```
17731773
17741774
#### 参数说明
1775-
- username: 用户的username。
1776-
- appKey: 用户所属应用的appkey。
1777-
- id: 本会话中指定local message id。为空时使用serverMessageId
1778-
- serverMessageId: 本会话中指定server message id。不可为空
1775+
- type: 会话类型。可以为 'single' 或 'group' 或 'chatRoom'。
1776+
- username: 对方用户的用户名。当 `type` 为 'single' 时,`username` 为必填。
1777+
- appKey: 对方用户所属应用的 AppKey。如果不填,默认为当前应用。
1778+
- groupId: 对象群组 id。当 `type` 为 'group' 时,`groupId` 为必填。
1779+
- roomId: 对象聊天室 id。当 `type` 为 'chatRoom' 时,`roomId` 为必填。
1780+
- id: mssageId。必填,不填则无法设置消息已读
17791781
17801782
## 聊天室
17811783
@@ -2130,7 +2132,7 @@ JMessage.removeSyncOfflineMessageListener(listener) // 移除监听(一般在 co
21302132
21312133
#### addReceiptMessageListener
21322134
2133-
已读消息回执事件监听。
2135+
已读消息回执事件监听。(Android Only)
21342136
21352137
##### 示例
21362138

example/app/routes/Chat/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,13 @@ export default class Chat extends Component {
202202

203203
console.log("收到消息"+JSON.stringify(message));
204204
const readParams = {
205-
// ...message,
205+
type: "single",
206206
username: message.from.username,
207207
appKey: message.from.appKey,
208208
id: message.id,
209-
serverMessageId: message.serverMessageId
210209
}
211210

212-
JMessage.setMsgHaveRead(readParams,(result) => {})
211+
JMessage.setMsgHaveRead(readParams,(successCallback) => {},(failCallback) => {})
213212

214213
if (this.conversation.type === 'single') {
215214
if (message.target.type === 'user') {

index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,15 +864,29 @@ export default class JMessage {
864864
/**
865865
* 设置消息已读
866866
* @param {object} params = {
867+
* 必填,不可为空
868+
* ‘type’: String single/group/chatroom
869+
*
870+
* type为single时,除了下面的其他值可缺省
867871
* 'username': String
868872
* 'appKey': String
869873
* 'id': String
870-
* 'serverMessageId': String
874+
*
875+
* type为group时,除了下面的其他值可缺省
876+
* 'groupId': String
877+
*
878+
* type为chatroom时,除了下面的其他值可缺省
879+
* 'roomId': String
880+
*
881+
* 必填,不可为空
882+
* 'id': String
883+
*
871884
* }
872-
* @param {function} result = function ({'code': '错误码', 'description': '错误信息'}) {}
885+
* @param {function} successCallback = function () {}
886+
* @param {function} failCallback = function ({'code': '错误码', 'description': '错误信息'}) {}
873887
*/
874-
static setMsgHaveRead(params,result){
875-
JMessageModule.setMsgHaveRead(params,result)
888+
static setMsgHaveRead(params,successCallback,failCallback){
889+
JMessageModule.setMsgHaveRead(params,successCallback,failCallback)
876890
}
877891

878892
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jmessage-react-plugin",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "a jmessage plugin for react native application",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)