Skip to content

Commit 3f93923

Browse files
author
Hevin
committed
Merge branch 'dev'
2 parents 5b38f4f + 7b52adc commit 3f93923

File tree

11 files changed

+766
-1516
lines changed

11 files changed

+766
-1516
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JMessage PhoneGap / Cordova Plugin
22

3-
[![release](https://img.shields.io/badge/release-3.1.6-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases)
3+
[![release](https://img.shields.io/badge/release-3.1.7-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases)
44
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-green.svg)](https://github.com/jpush/jmessage-phonegap-plugin)
55
[![Code Triagers Badge](https://www.codetriage.com/jpush/jmessage-phonegap-plugin/badges/users.svg)](https://www.codetriage.com/jpush/jmessage-phonegap-plugin)
66
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jmessage-phonegap-plugin",
3-
"version": "3.1.6",
3+
"version": "3.1.7",
44
"description": "JMessage Cordova Plugin.",
55
"cordova": {
66
"id": "jmessage-phonegap-plugin",

plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="jmessage-phonegap-plugin"
5-
version="3.1.6">
5+
version="3.1.7">
66

77
<name>JMessage</name>
88
<description>集成极光 IM 和推送功能</description>
@@ -161,6 +161,6 @@
161161
<source-file src="src/android/JMessagePlugin.java" target-dir="src/cn/jiguang/cordova/im"/>
162162
<source-file src="src/android/JMessageUtils.java" target-dir="src/cn/jiguang/cordova/im"/>
163163
<source-file src="src/android/JsonUtils.java" target-dir="src/cn/jiguang/cordova/im"/>
164-
<source-file src="src/android/ChatroomHandler.java" target-dir="src/cn/jiguang/cordova/im"/>
164+
<source-file src="src/android/ChatRoomHandler.java" target-dir="src/cn/jiguang/cordova/im"/>
165165
</platform>
166166
</plugin>

src/android/ChatroomHandler.java

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
* 处理聊天室相关 API。
2828
*/
2929

30-
class ChatroomHandler {
30+
class ChatRoomHandler {
3131

32-
static void getChatroomInfoListOfApp(JSONArray data, final CallbackContext callback) {
32+
static void getChatRoomInfoListOfApp(JSONArray data, final CallbackContext callback) {
3333
int start, count;
3434
try {
3535
JSONObject params = data.getJSONObject(0);
@@ -62,7 +62,7 @@ public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfos)
6262
});
6363
}
6464

65-
static void getChatroomInfoListOfUser(JSONArray data, final CallbackContext callback) {
65+
static void getChatRoomInfoListOfUser(JSONArray data, final CallbackContext callback) {
6666
ChatRoomManager.getChatRoomListByUser(new RequestCallback<List<ChatRoomInfo>>() {
6767
@Override
6868
public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfoList) {
@@ -84,7 +84,7 @@ public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfoLi
8484
});
8585
}
8686

87-
static void getChatroomInfoListById(JSONArray data, final CallbackContext callback) {
87+
static void getChatRoomInfoListById(JSONArray data, final CallbackContext callback) {
8888
Set<Long> roomIds = new HashSet<Long>(); // JS 层为了和 iOS 统一,因此 roomId 类型为 String,在原生做转换。
8989

9090
try {
@@ -121,7 +121,7 @@ public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfos)
121121
});
122122
}
123123

124-
static void getChatroomOwner(JSONArray data, final CallbackContext callback) {
124+
static void getChatRoomOwner(JSONArray data, final CallbackContext callback) {
125125
final long roomId;
126126

127127
try {
@@ -154,7 +154,7 @@ public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfoLi
154154
});
155155
}
156156

157-
static void enterChatroom(JSONArray data, final CallbackContext callback) {
157+
static void enterChatRoom(JSONArray data, final CallbackContext callback) {
158158
final long roomId;
159159

160160
try {
@@ -186,7 +186,7 @@ public void gotResult(int status, String desc, Conversation conversation) {
186186
});
187187
}
188188

189-
static void exitChatroom(JSONArray data, final CallbackContext callback) {
189+
static void exitChatRoom(JSONArray data, final CallbackContext callback) {
190190
final long roomId;
191191

192192
try {
@@ -210,27 +210,7 @@ public void gotResult(int status, String desc) {
210210
});
211211
}
212212

213-
static void getChatroomConversation(JSONArray data, final CallbackContext callback) {
214-
final long roomId;
215-
216-
try {
217-
JSONObject params = data.getJSONObject(0);
218-
roomId = Long.parseLong(params.getString("roomId"));
219-
} catch (JSONException e) {
220-
e.printStackTrace();
221-
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
222-
return;
223-
}
224-
225-
Conversation conversation = JMessageClient.getChatRoomConversation(roomId);
226-
if (conversation != null) {
227-
callback.success(toJson(conversation));
228-
} else {
229-
handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, callback);
230-
}
231-
}
232-
233-
static void getChatroomConversationList(JSONArray data, final CallbackContext callback) {
213+
static void getChatRoomConversationList(JSONArray data, final CallbackContext callback) {
234214
List<Conversation> conversations = JMessageClient.getChatRoomConversationList();
235215
JSONArray result = new JSONArray();
236216

@@ -240,50 +220,4 @@ static void getChatroomConversationList(JSONArray data, final CallbackContext ca
240220
callback.success(result);
241221
}
242222

243-
static void createChatroomConversation(JSONArray data, CallbackContext callback) {
244-
long roomId;
245-
246-
try {
247-
JSONObject params = data.getJSONObject(0);
248-
roomId = Long.parseLong(params.getString("roomId"));
249-
} catch (JSONException e) {
250-
e.printStackTrace();
251-
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
252-
return;
253-
}
254-
255-
Conversation conversation = Conversation.createChatRoomConversation(roomId);
256-
if (conversation != null) {
257-
callback.success(toJson(conversation));
258-
} else {
259-
handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, callback);
260-
}
261-
}
262-
263-
static void deleteChatroomConversation(JSONArray data, CallbackContext callback) {
264-
long roomId;
265-
266-
try {
267-
JSONObject params = data.getJSONObject(0);
268-
roomId = Long.parseLong(params.getString("roomId"));
269-
} catch (JSONException e) {
270-
e.printStackTrace();
271-
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
272-
return;
273-
}
274-
275-
boolean isSuccess = JMessageClient.deleteChatRoomConversation(roomId);
276-
if (isSuccess) {
277-
callback.success();
278-
} else {
279-
JSONObject error = new JSONObject();
280-
try {
281-
error.put("code", 10);
282-
error.put("description", "Conversation delete failed.");
283-
} catch (JSONException e) {
284-
e.printStackTrace();
285-
}
286-
callback.error(error);
287-
}
288-
}
289223
}

src/android/JMessagePlugin.java

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Map;
2828

29+
import cn.jpush.im.android.api.ChatRoomManager;
2930
import cn.jpush.im.android.api.ContactManager;
3031
import cn.jpush.im.android.api.JMessageClient;
3132
import cn.jpush.im.android.api.callback.CreateGroupCallback;
@@ -1829,18 +1830,7 @@ public void gotResult(int status, String desc, Integer integer) {
18291830
void createConversation(JSONArray data, CallbackContext callback) {
18301831
try {
18311832
JSONObject params = data.getJSONObject(0);
1832-
String type = params.getString("type");
1833-
Conversation conversation = null;
1834-
1835-
if (type.equals("single")) {
1836-
String username = params.getString("username");
1837-
String appKey = params.has("appKey") ? params.getString("appKey") : "";
1838-
conversation = Conversation.createSingleConversation(username, appKey);
1839-
1840-
} else if (type.equals("group")) {
1841-
String groupId = params.getString("groupId");
1842-
conversation = Conversation.createGroupConversation(Long.parseLong(groupId));
1843-
}
1833+
Conversation conversation = JMessageUtils.createConversation(params);
18441834

18451835
if (conversation != null) {
18461836
callback.success(toJson(conversation));
@@ -1872,6 +1862,10 @@ void deleteConversation(JSONArray data, CallbackContext callback) {
18721862
long groupId = Long.parseLong(params.getString("groupId"));
18731863
JMessageClient.deleteGroupConversation(groupId);
18741864

1865+
} else if (type.equals("chatRoom")) {
1866+
long roomId = Long.parseLong(params.getString("roomId"));
1867+
JMessageClient.deleteChatRoomConversation(roomId);
1868+
18751869
} else {
18761870
handleResult(ERR_CODE_PARAMETER, "Conversation type is error", callback);
18771871
return;
@@ -1972,51 +1966,40 @@ void setConversationExtras(JSONArray data, CallbackContext callback) {
19721966
}
19731967

19741968
String extraStr = extra == null ? "" : extra.toString();
1975-
boolean isSuccess = conversation.updateConversationExtra(extraStr);
1969+
conversation.updateConversationExtra(extraStr);
1970+
handleResult(toJson(conversation), 0, null, callback);
19761971
}
19771972

19781973
// 聊天会话 - end
19791974

19801975
// 聊天室 - start
19811976

1982-
void getChatroomInfoListOfApp(JSONArray data, CallbackContext callback) {
1983-
ChatroomHandler.getChatroomInfoListOfApp(data, callback);
1984-
}
1985-
1986-
void getChatroomInfoListOfUser(JSONArray data, CallbackContext callback) {
1987-
ChatroomHandler.getChatroomInfoListOfUser(data, callback);
1988-
}
1989-
1990-
void getChatroomInfoListById(JSONArray data, CallbackContext callback) {
1991-
ChatroomHandler.getChatroomInfoListById(data, callback);
1992-
}
1993-
1994-
void getChatroomOwner(JSONArray data, CallbackContext callback) {
1995-
ChatroomHandler.getChatroomOwner(data, callback);
1977+
void getChatRoomInfoListOfApp(JSONArray data, CallbackContext callback) {
1978+
ChatRoomHandler.getChatRoomInfoListOfApp(data, callback);
19961979
}
19971980

1998-
void enterChatroom(JSONArray data, CallbackContext callback) {
1999-
ChatroomHandler.enterChatroom(data, callback);
1981+
void getChatRoomInfoListOfUser(JSONArray data, CallbackContext callback) {
1982+
ChatRoomHandler.getChatRoomInfoListOfUser(data, callback);
20001983
}
20011984

2002-
void exitChatroom(JSONArray data, CallbackContext callback) {
2003-
ChatroomHandler.exitChatroom(data, callback);
1985+
void getChatRoomInfoListById(JSONArray data, CallbackContext callback) {
1986+
ChatRoomHandler.getChatRoomInfoListById(data, callback);
20041987
}
20051988

2006-
void getChatroomConversation(JSONArray data, CallbackContext callback) {
2007-
ChatroomHandler.getChatroomConversation(data, callback);
1989+
void getChatRoomOwner(JSONArray data, CallbackContext callback) {
1990+
ChatRoomHandler.getChatRoomOwner(data, callback);
20081991
}
20091992

2010-
void getChatroomConversationList(JSONArray data, CallbackContext callback) {
2011-
ChatroomHandler.getChatroomConversationList(data, callback);
1993+
void enterChatRoom(JSONArray data, CallbackContext callback) {
1994+
ChatRoomHandler.enterChatRoom(data, callback);
20121995
}
20131996

2014-
void createChatroomConversation(JSONArray data, CallbackContext callback) {
2015-
ChatroomHandler.createChatroomConversation(data, callback);
1997+
void exitChatRoom(JSONArray data, CallbackContext callback) {
1998+
ChatRoomHandler.exitChatRoom(data, callback);
20161999
}
20172000

2018-
void deleteChatroomConversation(JSONArray data, CallbackContext callback) {
2019-
ChatroomHandler.deleteChatroomConversation(data, callback);
2001+
void getChatRoomConversationList(JSONArray data, CallbackContext callback) {
2002+
ChatRoomHandler.getChatRoomConversationList(data, callback);
20202003
}
20212004

20222005
// 聊天室 - end
@@ -2288,7 +2271,7 @@ public void onEvent(ChatRoomMessageEvent event) {
22882271
e.printStackTrace();
22892272
}
22902273

2291-
JSONObject eventJson = toJson("receiveChatroomMessage", result);
2274+
JSONObject eventJson = toJson("receiveChatRoomMessage", result);
22922275
eventSuccess(eventJson);
22932276
}
22942277

src/android/JMessageUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static Conversation createConversation(JSONObject params) throws JSONException {
124124
String groupId = params.getString("groupId");
125125
conversation = Conversation.createGroupConversation(Long.parseLong(groupId));
126126

127-
} else if (type.equals("chatroom")) {
127+
} else if (type.equals("chatRoom")) {
128128
long roomId = Long.parseLong(params.getString("roomId"));
129129
conversation = Conversation.createChatRoomConversation(roomId);
130130
}
@@ -145,7 +145,7 @@ static Conversation getConversation(JSONObject params) throws JSONException {
145145
String groupId = params.getString("groupId");
146146
conversation = JMessageClient.getGroupConversation(Long.parseLong(groupId));
147147

148-
} else if (type.equals("chatroom")) {
148+
} else if (type.equals("chatRoom")) {
149149
long roomId = Long.parseLong(params.getString("roomId"));
150150
conversation = JMessageClient.getChatRoomConversation(roomId);
151151
}

src/android/JsonUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ static Message JsonToMessage(JSONObject json) {
220220
String username;
221221
String appKey;
222222

223-
if (isSend) { // 消息由当前用户发送。
223+
if (isSend) { // 消息由当前用户发送,则聊天对象为消息接收方
224224
username = target.getString("username");
225225
appKey = target.has("appKey") ? target.getString("appKey") : null;
226226

227-
} else { // 当前用户为消息接收方。
227+
} else { // 当前用户为消息接收方,则聊天对象为消息发送方
228228
JSONObject opposite = json.getJSONObject("from");
229229
username = opposite.getString("username");
230230
appKey = opposite.has("appKey") ? opposite.getString("appKey") : null;
@@ -235,6 +235,10 @@ static Message JsonToMessage(JSONObject json) {
235235
} else if (target.getString("type").equals("group")) {
236236
long groupId = Long.parseLong(target.getString("id"));
237237
conversation = JMessageClient.getGroupConversation(groupId);
238+
239+
} else if (target.getString("type").equals("chatroom")) {
240+
long roomId = Long.parseLong(target.getString("roomId"));
241+
conversation = JMessageClient.getChatRoomConversation(roomId);
238242
}
239243
} catch (JSONException e) {
240244
e.printStackTrace();
@@ -316,14 +320,14 @@ static JSONObject toJson(String eventName, JSONArray value) {
316320

317321
static JSONObject toJson(ChatRoomInfo chatRoomInfo) throws JSONException {
318322
JSONObject json = new JSONObject();
319-
json.put("type", "chatroom");
323+
json.put("type", "chatRoom");
320324
json.put("roomId", String.valueOf(chatRoomInfo.getRoomID())); // 配合 iOS,将 long 转成 String。
321325
json.put("name", chatRoomInfo.getName());
322326
json.put("appKey", chatRoomInfo.getAppkey());
323327
json.put("description", chatRoomInfo.getDescription());
324328
json.put("createTime", chatRoomInfo.getCreateTime()); // 创建日期,单位秒。
325329
json.put("maxMemberCount", chatRoomInfo.getMaxMemberCount()); // 最大成员数。
326-
json.put("currentMemberCount", chatRoomInfo.getTotalMemberCount()); // 当前成员数。
330+
json.put("memberCount", chatRoomInfo.getTotalMemberCount()); // 当前成员数。
327331
return json;
328332
}
329333
}

src/ios/Plugins/JMessageHelper.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ -(NSMutableDictionary*)conversationToDictionary{
265265
case kJMSGConversationTypeChatRoom:{
266266
JMSGChatRoom *chatroom = self.target;
267267
dict[@"target"] = [chatroom chatRoomToDictionary];
268-
dict[@"conversationType"] = @"chatroom";
268+
dict[@"conversationType"] = @"chatRoom";
269269
break;
270270
}
271271
}
@@ -362,7 +362,7 @@ - (NSMutableDictionary *)messageToDictionary {
362362
dict[@"extras"] = self.content.extras;
363363
}
364364

365-
dict[@"isSend"] = @(self.isReceived);
365+
dict[@"isSend"] = @(!self.isReceived);
366366
switch (self.targetType) {
367367
case kJMSGConversationTypeSingle:{
368368
JMSGUser *user = self.target;
@@ -529,14 +529,14 @@ - (NSString *)getFullPathWith:(NSString *) path {
529529
@implementation JMSGChatRoom (JMessage)
530530
- (NSMutableDictionary *)chatRoomToDictionary {
531531
NSMutableDictionary *dict = @{}.mutableCopy;
532-
dict[@"type"] = @"chatroom";
532+
dict[@"type"] = @"chatRoom";
533533
dict[@"roomId"] = self.roomID;
534534
dict[@"name"] = self.name;
535535
dict[@"appKey"] = self.appkey;
536536
dict[@"description"] = self.description;
537537
dict[@"createTime"] = self.ctime;
538538
dict[@"maxMemberCount"] = @([self.maxMemberCount integerValue]);
539-
dict[@"currentMemberCount"] = @(self.totalMemberCount);
539+
dict[@"memberCount"] = @(self.totalMemberCount);
540540

541541
return dict;
542542
}

src/ios/Plugins/JMessagePlugin.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
- (void)exitChatroom:(CDVInvokedUrlCommand *)command;
7979
- (void)getChatroomConversation:(CDVInvokedUrlCommand *)command;
8080
- (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command;
81-
- (void)createChatroomConversation:(CDVInvokedUrlCommand *)command;
82-
- (void)deleteChatroomConversation:(CDVInvokedUrlCommand *)command;
8381
- (void)getChatroomOwner:(CDVInvokedUrlCommand *)command;
8482

8583
@end

0 commit comments

Comments
 (0)