Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hevin committed Jan 15, 2018
2 parents 5b38f4f + 7b52adc commit 3f93923
Show file tree
Hide file tree
Showing 11 changed files with 766 additions and 1,516 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JMessage PhoneGap / Cordova Plugin

[![release](https://img.shields.io/badge/release-3.1.6-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases)
[![release](https://img.shields.io/badge/release-3.1.7-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases)
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-green.svg)](https://github.com/jpush/jmessage-phonegap-plugin)
[![Code Triagers Badge](https://www.codetriage.com/jpush/jmessage-phonegap-plugin/badges/users.svg)](https://www.codetriage.com/jpush/jmessage-phonegap-plugin)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jmessage-phonegap-plugin",
"version": "3.1.6",
"version": "3.1.7",
"description": "JMessage Cordova Plugin.",
"cordova": {
"id": "jmessage-phonegap-plugin",
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="jmessage-phonegap-plugin"
version="3.1.6">
version="3.1.7">

<name>JMessage</name>
<description>集成极光 IM 和推送功能</description>
Expand Down Expand Up @@ -161,6 +161,6 @@
<source-file src="src/android/JMessagePlugin.java" target-dir="src/cn/jiguang/cordova/im"/>
<source-file src="src/android/JMessageUtils.java" target-dir="src/cn/jiguang/cordova/im"/>
<source-file src="src/android/JsonUtils.java" target-dir="src/cn/jiguang/cordova/im"/>
<source-file src="src/android/ChatroomHandler.java" target-dir="src/cn/jiguang/cordova/im"/>
<source-file src="src/android/ChatRoomHandler.java" target-dir="src/cn/jiguang/cordova/im"/>
</platform>
</plugin>
82 changes: 8 additions & 74 deletions src/android/ChatroomHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* 处理聊天室相关 API。
*/

class ChatroomHandler {
class ChatRoomHandler {

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

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

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

try {
Expand Down Expand Up @@ -121,7 +121,7 @@ public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfos)
});
}

static void getChatroomOwner(JSONArray data, final CallbackContext callback) {
static void getChatRoomOwner(JSONArray data, final CallbackContext callback) {
final long roomId;

try {
Expand Down Expand Up @@ -154,7 +154,7 @@ public void gotResult(int status, String desc, List<ChatRoomInfo> chatRoomInfoLi
});
}

static void enterChatroom(JSONArray data, final CallbackContext callback) {
static void enterChatRoom(JSONArray data, final CallbackContext callback) {
final long roomId;

try {
Expand Down Expand Up @@ -186,7 +186,7 @@ public void gotResult(int status, String desc, Conversation conversation) {
});
}

static void exitChatroom(JSONArray data, final CallbackContext callback) {
static void exitChatRoom(JSONArray data, final CallbackContext callback) {
final long roomId;

try {
Expand All @@ -210,27 +210,7 @@ public void gotResult(int status, String desc) {
});
}

static void getChatroomConversation(JSONArray data, final CallbackContext callback) {
final long roomId;

try {
JSONObject params = data.getJSONObject(0);
roomId = Long.parseLong(params.getString("roomId"));
} catch (JSONException e) {
e.printStackTrace();
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
return;
}

Conversation conversation = JMessageClient.getChatRoomConversation(roomId);
if (conversation != null) {
callback.success(toJson(conversation));
} else {
handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, callback);
}
}

static void getChatroomConversationList(JSONArray data, final CallbackContext callback) {
static void getChatRoomConversationList(JSONArray data, final CallbackContext callback) {
List<Conversation> conversations = JMessageClient.getChatRoomConversationList();
JSONArray result = new JSONArray();

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

static void createChatroomConversation(JSONArray data, CallbackContext callback) {
long roomId;

try {
JSONObject params = data.getJSONObject(0);
roomId = Long.parseLong(params.getString("roomId"));
} catch (JSONException e) {
e.printStackTrace();
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
return;
}

Conversation conversation = Conversation.createChatRoomConversation(roomId);
if (conversation != null) {
callback.success(toJson(conversation));
} else {
handleResult(ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION, callback);
}
}

static void deleteChatroomConversation(JSONArray data, CallbackContext callback) {
long roomId;

try {
JSONObject params = data.getJSONObject(0);
roomId = Long.parseLong(params.getString("roomId"));
} catch (JSONException e) {
e.printStackTrace();
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, callback);
return;
}

boolean isSuccess = JMessageClient.deleteChatRoomConversation(roomId);
if (isSuccess) {
callback.success();
} else {
JSONObject error = new JSONObject();
try {
error.put("code", 10);
error.put("description", "Conversation delete failed.");
} catch (JSONException e) {
e.printStackTrace();
}
callback.error(error);
}
}
}
63 changes: 23 additions & 40 deletions src/android/JMessagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;

import cn.jpush.im.android.api.ChatRoomManager;
import cn.jpush.im.android.api.ContactManager;
import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.callback.CreateGroupCallback;
Expand Down Expand Up @@ -1829,18 +1830,7 @@ public void gotResult(int status, String desc, Integer integer) {
void createConversation(JSONArray data, CallbackContext callback) {
try {
JSONObject params = data.getJSONObject(0);
String type = params.getString("type");
Conversation conversation = null;

if (type.equals("single")) {
String username = params.getString("username");
String appKey = params.has("appKey") ? params.getString("appKey") : "";
conversation = Conversation.createSingleConversation(username, appKey);

} else if (type.equals("group")) {
String groupId = params.getString("groupId");
conversation = Conversation.createGroupConversation(Long.parseLong(groupId));
}
Conversation conversation = JMessageUtils.createConversation(params);

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

} else if (type.equals("chatRoom")) {
long roomId = Long.parseLong(params.getString("roomId"));
JMessageClient.deleteChatRoomConversation(roomId);

} else {
handleResult(ERR_CODE_PARAMETER, "Conversation type is error", callback);
return;
Expand Down Expand Up @@ -1972,51 +1966,40 @@ void setConversationExtras(JSONArray data, CallbackContext callback) {
}

String extraStr = extra == null ? "" : extra.toString();
boolean isSuccess = conversation.updateConversationExtra(extraStr);
conversation.updateConversationExtra(extraStr);
handleResult(toJson(conversation), 0, null, callback);
}

// 聊天会话 - end

// 聊天室 - start

void getChatroomInfoListOfApp(JSONArray data, CallbackContext callback) {
ChatroomHandler.getChatroomInfoListOfApp(data, callback);
}

void getChatroomInfoListOfUser(JSONArray data, CallbackContext callback) {
ChatroomHandler.getChatroomInfoListOfUser(data, callback);
}

void getChatroomInfoListById(JSONArray data, CallbackContext callback) {
ChatroomHandler.getChatroomInfoListById(data, callback);
}

void getChatroomOwner(JSONArray data, CallbackContext callback) {
ChatroomHandler.getChatroomOwner(data, callback);
void getChatRoomInfoListOfApp(JSONArray data, CallbackContext callback) {
ChatRoomHandler.getChatRoomInfoListOfApp(data, callback);
}

void enterChatroom(JSONArray data, CallbackContext callback) {
ChatroomHandler.enterChatroom(data, callback);
void getChatRoomInfoListOfUser(JSONArray data, CallbackContext callback) {
ChatRoomHandler.getChatRoomInfoListOfUser(data, callback);
}

void exitChatroom(JSONArray data, CallbackContext callback) {
ChatroomHandler.exitChatroom(data, callback);
void getChatRoomInfoListById(JSONArray data, CallbackContext callback) {
ChatRoomHandler.getChatRoomInfoListById(data, callback);
}

void getChatroomConversation(JSONArray data, CallbackContext callback) {
ChatroomHandler.getChatroomConversation(data, callback);
void getChatRoomOwner(JSONArray data, CallbackContext callback) {
ChatRoomHandler.getChatRoomOwner(data, callback);
}

void getChatroomConversationList(JSONArray data, CallbackContext callback) {
ChatroomHandler.getChatroomConversationList(data, callback);
void enterChatRoom(JSONArray data, CallbackContext callback) {
ChatRoomHandler.enterChatRoom(data, callback);
}

void createChatroomConversation(JSONArray data, CallbackContext callback) {
ChatroomHandler.createChatroomConversation(data, callback);
void exitChatRoom(JSONArray data, CallbackContext callback) {
ChatRoomHandler.exitChatRoom(data, callback);
}

void deleteChatroomConversation(JSONArray data, CallbackContext callback) {
ChatroomHandler.deleteChatroomConversation(data, callback);
void getChatRoomConversationList(JSONArray data, CallbackContext callback) {
ChatRoomHandler.getChatRoomConversationList(data, callback);
}

// 聊天室 - end
Expand Down Expand Up @@ -2288,7 +2271,7 @@ public void onEvent(ChatRoomMessageEvent event) {
e.printStackTrace();
}

JSONObject eventJson = toJson("receiveChatroomMessage", result);
JSONObject eventJson = toJson("receiveChatRoomMessage", result);
eventSuccess(eventJson);
}

Expand Down
4 changes: 2 additions & 2 deletions src/android/JMessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static Conversation createConversation(JSONObject params) throws JSONException {
String groupId = params.getString("groupId");
conversation = Conversation.createGroupConversation(Long.parseLong(groupId));

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

} else if (type.equals("chatroom")) {
} else if (type.equals("chatRoom")) {
long roomId = Long.parseLong(params.getString("roomId"));
conversation = JMessageClient.getChatRoomConversation(roomId);
}
Expand Down
12 changes: 8 additions & 4 deletions src/android/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ static Message JsonToMessage(JSONObject json) {
String username;
String appKey;

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

} else { // 当前用户为消息接收方。
} else { // 当前用户为消息接收方,则聊天对象为消息发送方
JSONObject opposite = json.getJSONObject("from");
username = opposite.getString("username");
appKey = opposite.has("appKey") ? opposite.getString("appKey") : null;
Expand All @@ -235,6 +235,10 @@ static Message JsonToMessage(JSONObject json) {
} else if (target.getString("type").equals("group")) {
long groupId = Long.parseLong(target.getString("id"));
conversation = JMessageClient.getGroupConversation(groupId);

} else if (target.getString("type").equals("chatroom")) {
long roomId = Long.parseLong(target.getString("roomId"));
conversation = JMessageClient.getChatRoomConversation(roomId);
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down Expand Up @@ -316,14 +320,14 @@ static JSONObject toJson(String eventName, JSONArray value) {

static JSONObject toJson(ChatRoomInfo chatRoomInfo) throws JSONException {
JSONObject json = new JSONObject();
json.put("type", "chatroom");
json.put("type", "chatRoom");
json.put("roomId", String.valueOf(chatRoomInfo.getRoomID())); // 配合 iOS,将 long 转成 String。
json.put("name", chatRoomInfo.getName());
json.put("appKey", chatRoomInfo.getAppkey());
json.put("description", chatRoomInfo.getDescription());
json.put("createTime", chatRoomInfo.getCreateTime()); // 创建日期,单位秒。
json.put("maxMemberCount", chatRoomInfo.getMaxMemberCount()); // 最大成员数。
json.put("currentMemberCount", chatRoomInfo.getTotalMemberCount()); // 当前成员数。
json.put("memberCount", chatRoomInfo.getTotalMemberCount()); // 当前成员数。
return json;
}
}
8 changes: 4 additions & 4 deletions src/ios/Plugins/JMessageHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ -(NSMutableDictionary*)conversationToDictionary{
case kJMSGConversationTypeChatRoom:{
JMSGChatRoom *chatroom = self.target;
dict[@"target"] = [chatroom chatRoomToDictionary];
dict[@"conversationType"] = @"chatroom";
dict[@"conversationType"] = @"chatRoom";
break;
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ - (NSMutableDictionary *)messageToDictionary {
dict[@"extras"] = self.content.extras;
}

dict[@"isSend"] = @(self.isReceived);
dict[@"isSend"] = @(!self.isReceived);
switch (self.targetType) {
case kJMSGConversationTypeSingle:{
JMSGUser *user = self.target;
Expand Down Expand Up @@ -529,14 +529,14 @@ - (NSString *)getFullPathWith:(NSString *) path {
@implementation JMSGChatRoom (JMessage)
- (NSMutableDictionary *)chatRoomToDictionary {
NSMutableDictionary *dict = @{}.mutableCopy;
dict[@"type"] = @"chatroom";
dict[@"type"] = @"chatRoom";
dict[@"roomId"] = self.roomID;
dict[@"name"] = self.name;
dict[@"appKey"] = self.appkey;
dict[@"description"] = self.description;
dict[@"createTime"] = self.ctime;
dict[@"maxMemberCount"] = @([self.maxMemberCount integerValue]);
dict[@"currentMemberCount"] = @(self.totalMemberCount);
dict[@"memberCount"] = @(self.totalMemberCount);

return dict;
}
Expand Down
2 changes: 0 additions & 2 deletions src/ios/Plugins/JMessagePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
- (void)exitChatroom:(CDVInvokedUrlCommand *)command;
- (void)getChatroomConversation:(CDVInvokedUrlCommand *)command;
- (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command;
- (void)createChatroomConversation:(CDVInvokedUrlCommand *)command;
- (void)deleteChatroomConversation:(CDVInvokedUrlCommand *)command;
- (void)getChatroomOwner:(CDVInvokedUrlCommand *)command;

@end
Loading

0 comments on commit 3f93923

Please sign in to comment.