From c9ef26cd09753f5a4d4266b44f6f374c89a112fd Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Thu, 11 Jan 2018 12:08:12 +0800 Subject: [PATCH 1/8] fix issend --- src/ios/Plugins/JMessageHelper.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/Plugins/JMessageHelper.m b/src/ios/Plugins/JMessageHelper.m index b338878..7f51cdb 100644 --- a/src/ios/Plugins/JMessageHelper.m +++ b/src/ios/Plugins/JMessageHelper.m @@ -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; From f41c5484155e58057119d15633a1e8b22dd22b52 Mon Sep 17 00:00:00 2001 From: Hevin Date: Thu, 11 Jan 2018 13:56:16 +0800 Subject: [PATCH 2/8] Add comment to JS APIs about chatroom --- src/android/JMessagePlugin.java | 3 +- www/JMessagePlugin.js | 224 +++++++++++++++++--------------- 2 files changed, 120 insertions(+), 107 deletions(-) diff --git a/src/android/JMessagePlugin.java b/src/android/JMessagePlugin.java index 454fc4b..2b99160 100644 --- a/src/android/JMessagePlugin.java +++ b/src/android/JMessagePlugin.java @@ -1972,7 +1972,8 @@ 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 diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index ba81aed..8562c5b 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -117,7 +117,7 @@ var JMessagePlugin = { /** * 获取用户信息,此接口可用来获取不同 appKey 下用户的信息,如果 appKey 为空,则默认获取当前 appKey 下的用户信息。 * - * @param {object} params = {'username': string, 'appKey': string} + * @param {object} params = {'username': String, 'appKey': string} * @param {function} success = function (userInfo) {} // 通过参数返回用户对象。 * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ @@ -125,7 +125,7 @@ var JMessagePlugin = { exec(success, error, PLUGIN_NAME, 'getUserInfo', [params]) }, /** - * @param {object} params = {'oldPwd': string, 'newPwd': string} + * @param {object} params = {'oldPwd': String, 'newPwd': string} */ updateMyPassword: function (params, success, error) { exec(success, error, PLUGIN_NAME, 'updateMyPassword', [params]) @@ -202,10 +202,11 @@ var JMessagePlugin = { * 增加或更新扩展字段,可扩展会话属性,比如:会话置顶、标识特殊会话等 * * @param {object} params = { - * 'type': String, // 'single' / 'group' + * 'type': String, // 'single' / 'group' / 'chatroom' * 'groupId': String, // 目标群组 id。 * 'username': String, // 目标用户名。 * 'appKey': String, // 目标用户所属 AppKey。 + * 'roomId': String // 聊天室 id。 * } * @param {function} success = function (conversation) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -216,10 +217,11 @@ var JMessagePlugin = { /** * @param {object} params = { - * 'type': String, // 'single' / 'group' - * 'groupId': String, // 当 type = group 时,groupId 不能为空 - * 'username': String, // 当 type = single 时,username 不能为空 - * 'appKey': String, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 + * 'username': String, // 当 type 为 'single' 时,username 不能为空 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 * 'text': String, // 消息内容 * 'extras': Object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象 @@ -232,11 +234,12 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空 - * 'username': string, // 当 type = single 时,username 不能为空 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'path': string, // 本地图片绝对路径。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 + * 'username': String, // 当 type 为 'single' 时,username 不能为空 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'path': String, // 本地图片绝对路径。 * 'extras': object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象 * } @@ -251,11 +254,12 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空 - * 'username': string, // 当 type = single 时,username 不能为空 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'path': string, // 本地语音文件路径。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 + * 'username': String, // 当 type 为 'single' 时,username 不能为空 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'path': String, // 本地语音文件路径。 * 'extras': object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象。 * } @@ -267,10 +271,11 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空 - * 'username': string, // 当 type = single 时,username 不能为空 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 + * 'username': String, // 当 type 为 'single' 时,username 不能为空 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 * 'customObject': {'key1': 'value1'} // Optional. 自定义键值对 * } * @param {function} success = function (msg) {} // 以参数形式返回消息对象。 @@ -281,14 +286,15 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空 - * 'username': string, // 当 type = single 时,username 不能为空 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 + * 'username': String, // 当 type 为 'single' 时,username 不能为空 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 * 'latitude': Number, // 纬度信息 * 'longitude': Number, // 经度信息 * 'scale': Number, // 地图缩放比例 - * 'address': string, // 详细地址信息 + * 'address': String, // 详细地址信息 * 'extras': object // Optional. 自定义键值对 = {'key1': 'value1'} * } * @param {function} success = function (msg) {} // 以参数形式返回消息对象。 @@ -299,11 +305,12 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空。 - * 'username': string, // 当 type = single 时,username 不能为空。 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'path': string, // 本地文件路径。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空。 + * 'username': String, // 当 type 为 'single' 时,username 不能为空。 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'path': String, // 本地文件路径。 * 'extras': object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象。 * } @@ -317,10 +324,11 @@ var JMessagePlugin = { * 消息撤回。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空。 - * 'username': string, // 当 type = single 时,username 不能为空。 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空。 + * 'username': String, // 当 type 为 'single' 时,username 不能为空。 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空。 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 * 'messageId': string // 消息 id。 * } * @param {function} success = function () {} @@ -335,10 +343,11 @@ var JMessagePlugin = { * 例如:当 from = 0 && limit = -1 时,返回所有历史消息。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 当 type = group 时,groupId 不能为空。 - * 'username': string, // 当 type = single 时,username 不能为空。 - * 'appKey': string, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空。 + * 'username': String, // 当 type 为 'single' 时,username 不能为空。 + * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 + * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空。 * 'from': Number, // 开始的消息下标。 * 'limit': Number // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 的 10 条历史消息。 * } @@ -352,10 +361,11 @@ var JMessagePlugin = { * 根据消息 id 获取消息对象。 * * @param {object} params = { - * type: string, // 'single' / 'group' - * groupId: string, // 当 type = 'group' 时,groupId 必填。 - * username: string, // 当 type = 'single' 时,username 必填。 - * appKey: string, // 当 type = 'single' 时,用于指定对象所属应用的 appKey。如果未空,则默认为当前应用。 + * type: String, // 'single' / 'group' / 'chatroom' + * groupId: String, // 当 type = 'group' 时,groupId 必填。 + * username: String, // 当 type = 'single' 时,username 必填。 + * appKey: String, // 当 type = 'single' 时,用于指定对象所属应用的 appKey。如果未空,则默认为当前应用。 + * roomId: String, // 当 type 为 'chatroom' 时,roomId 不能为空。 * messageId: string // 消息 Id。 * } */ @@ -386,8 +396,8 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'username': string, // 对方用户用户名。 - * 'appKey': string, // 对方用户所属应用的 AppKey。 + * 'username': String, // 对方用户用户名。 + * 'appKey': String, // 对方用户所属应用的 AppKey。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -397,8 +407,8 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'username': string, // 对方用户用户名。 - * 'appKey': string, // 对方用户所属应用的 AppKey。 + * 'username': String, // 对方用户用户名。 + * 'appKey': String, // 对方用户所属应用的 AppKey。 * 'reason': string // 拒绝原因。 * } * @param {function} success = function () {} @@ -409,8 +419,8 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'username': string, // 好友用户名。 - * 'appKey': string, // 好友所属应用的 AppKey。 + * 'username': String, // 好友用户名。 + * 'appKey': String, // 好友所属应用的 AppKey。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -420,8 +430,8 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'username': string, // 好友用户名。 - * 'appKey': string, // 好友所属应用的 AppKey。 + * 'username': String, // 好友用户名。 + * 'appKey': String, // 好友所属应用的 AppKey。 * 'noteName': string // 备注名。 * } * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -431,8 +441,8 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'username': string, // 好友用户名。 - * 'appKey': string, // 好友所属应用的 AppKey。 + * 'username': String, // 好友用户名。 + * 'appKey': String, // 好友所属应用的 AppKey。 * 'noteText': string // 备注信息。 * } * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -544,10 +554,10 @@ var JMessagePlugin = { * 设置某个用户或群组是否免打扰。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * 'isNoDisturb': boolean // 是否免打扰。 * } * @param {function} success = function () {} @@ -630,8 +640,8 @@ var JMessagePlugin = { /** * 下载用户头像缩略图,如果已经下载,不会重复下载。 * - * @param {object} params = {'username': string, 'appKey': string} - * @param {function} success = function ({'username': string, 'appKey': string, 'filePath': string}) {} + * @param {object} params = {'username': String, 'appKey': string} + * @param {function} success = function ({'username': String, 'appKey': String, 'filePath': string}) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ downloadThumbUserAvatar: function (params, success, error) { @@ -641,8 +651,8 @@ var JMessagePlugin = { * 下载用户头像原图,如果已经下载,不会重复下载。 * 如果用户未设置头像,则返回的 filePath 为空字符串。 * - * @param {object} params = {'username': string, 'appKey': string} - * @param {function} success = function ({'username': string, 'appKey': string, 'filePath': string}) {} + * @param {object} params = {'username': String, 'appKey': string} + * @param {function} success = function ({'username': String, 'appKey': String, 'filePath': string}) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ downloadOriginalUserAvatar: function (params, success, error) { @@ -652,13 +662,13 @@ var JMessagePlugin = { * 下载图片消息的缩略图,如果已下载,会直接返回本地文件路径,不会重复下载。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * 'messageId': string // 指定消息 id。 * } - * @param {function} success = function ({'messageId': string, 'filePath': string}) {} + * @param {function} success = function ({'messageId': String, 'filePath': string}) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ downloadThumbImage: function (params, success, error) { @@ -668,13 +678,13 @@ var JMessagePlugin = { * 下载指定图片消息的原图,如果已经下载,会直接返回本地文件路径,不会重复下载。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * 'messageId': string // 指定消息 id。 * } - * @param {function} success = function ({'messageId': string, 'filePath': string}) {} + * @param {function} success = function ({'messageId': String, 'filePath': string}) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ downloadOriginalImage: function (params, success, error) { @@ -684,13 +694,13 @@ var JMessagePlugin = { * 下载语音消息文件,如果已经下载,会直接返回本地文件路径,不会重复下载。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * 'messageId': string // 指定消息 id。 * } - * @param {function} success = function ({'messageId': string, 'filePath': string}) {} + * @param {function} success = function ({'messageId': String, 'filePath': string}) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ downloadVoiceFile: function (params, success, error) { @@ -700,13 +710,13 @@ var JMessagePlugin = { * 下载文件消息文件,如果已经下载,会直接返回本地文件路径,不会重复下载。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * 'messageId': string // 指定消息 id。 * } - * @param {function} success = function ({'messageId': string, 'filePath': string}) {} + * @param {function} success = function ({'messageId': String, 'filePath': string}) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ downloadFile: function (params, success, error) { @@ -716,10 +726,10 @@ var JMessagePlugin = { * 创建聊天会话。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * } * @param {function} success = function (conversation) {} // 以参数形式返回聊天会话对象。 * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -731,10 +741,10 @@ var JMessagePlugin = { * 删除聊天会话,同时会删除本地聊天记录。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -746,10 +756,10 @@ var JMessagePlugin = { * 进入聊天会话。可以在进入聊天会话页面时调用该方法,这样在收到当前聊天用户的消息时,不会显示通知。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -766,10 +776,11 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' / 'roomId' + * 'groupId': String, // 目标群组 id。当 type 为 'group' 时必填。 + * 'username': String, // 目标用户名。当 type 为 'single' 时必填。 + * 'appKey': String, // 目标用户所属 AppKey。如果不传或为空字符串,则默认为当前应用。 + * 'roomId': String // 聊天室 id。当 type 为 'roomId' 时必填。 * } * @param {function} success = function (conversation) {} // 以参数形式返回聊天会话对象。 * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -788,10 +799,11 @@ var JMessagePlugin = { * 重置单个会话的未读消息数。 * * @param {object} params = { - * 'type': string, // 'single' / 'group' - * 'groupId': string, // 目标群组 id。 - * 'username': string, // 目标用户名。 - * 'appKey': string, // 目标用户所属 AppKey。 + * 'type': String, // 'single' / 'group' / 'chatroom' + * 'groupId': String, // 目标群组 id。 + * 'username': String, // 目标用户名。 + * 'appKey': String, // 目标用户所属 AppKey。 + * 'roomId': String // 聊天室 id。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -914,7 +926,7 @@ var JMessagePlugin = { * * @param {function} listener = function (message) {} // 以参数形式返回消息对象。 * message = { - * 'id': string, + * 'id': String, * 'from': object, // 消息发送者信息对象。 * 'target': object, // 消息接收方信息(可能为用户或者群组)。 * 'type': string // 'text' / 'image' / 'voice' / 'location' / 'file' / 'custom' / 'event' @@ -980,7 +992,7 @@ var JMessagePlugin = { * * @param {function} listener = function (event) {} // 以参数形式返回事件信息。 * event = { - * 'type': string, // 'user_password_change' / 'user_logout' / 'user_deleted' / 'user_login_status_unexpected' + * 'type': String, // 'user_password_change' / 'user_logout' / 'user_deleted' / 'user_login_status_unexpected' * } */ addLoginStateChangedListener: function (listener) { @@ -997,9 +1009,9 @@ var JMessagePlugin = { * * @param {function} listener = function (event) {} // 以参数形式返回事件信息。 * event = { - * 'type': string, // 'invite_received' / 'invite_accepted' / 'invite_declined' / 'contact_deleted' - * 'reason': string, // 事件发生的理由,该字段由对方发起请求时所填,对方如果未填则返回默认字符串。 - * 'fromUsername': string, // 事件发送者的 username。 + * 'type': String, // 'invite_received' / 'invite_accepted' / 'invite_declined' / 'contact_deleted' + * 'reason': String, // 事件发生的理由,该字段由对方发起请求时所填,对方如果未填则返回默认字符串。 + * 'fromUsername': String, // 事件发送者的 username。 * 'fromUserAppKey': string // 事件发送者的 AppKey。 * } */ From 602a31b14b34b55fded10fdfc07a23e83aa8ca55 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Thu, 11 Jan 2018 17:21:55 +0800 Subject: [PATCH 3/8] update to reconstruct ios --- src/ios/Plugins/JMessagePlugin.m | 1732 ++++++++++-------------------- 1 file changed, 548 insertions(+), 1184 deletions(-) diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index 79e2ed0..945cd8f 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -26,6 +26,9 @@ #define ResultSuccess(method) [NSString stringWithFormat:@"success - %@",method] #define ResultFailed(method) [NSString stringWithFormat:@"failed - %@",method] + +typedef void (^JMSGConversationCallback)(JMSGConversation *conversation,NSError *error); + @interface JMessagePlugin () @property(strong,nonatomic)CDVInvokedUrlCommand *callBack; @property(strong,nonatomic)NSMutableDictionary *SendMsgCallbackDic;//{@"msgid": @"", @"callbackID": @""} @@ -159,6 +162,226 @@ -(void)initNotifications { object:nil]; } +- (void)getConversationWithDictionary:(NSDictionary *)param callback:(JMSGConversationCallback)callback { + if (param[@"type"] == nil) { + NSError *error = [NSError errorWithDomain:@"param error!" code: 1 userInfo: nil]; + callback(nil,error); + return; + } + + if (param[@"text"] == nil) { + NSError *error = [NSError errorWithDomain:@"param error!" code: 1 userInfo: nil]; + callback(nil,error); + return; + } + + NSString *appKey = nil; + if (param[@"appKey"]) { + appKey = param[@"appKey"]; + } else { + appKey = [JMessageHelper shareInstance].JMessageAppKey; + } + JMSGConversationType conversationType = [self convertStringToConvsersationType:param[@"type"]]; + switch (conversationType) { + case kJMSGConversationTypeSingle:{ + [JMSGConversation createSingleConversationWithUsername:param[@"username"] + appKey:appKey + completionHandler:^(id resultObject, NSError *error) { + if (error) { + callback(nil, error); + return; + } + + JMSGConversation *conversation = resultObject; + callback(conversation,nil); + }]; + break; + } + case kJMSGConversationTypeGroup:{ + [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { + if (error) { + callback(nil, error); + return; + } + + JMSGConversation *conversation = resultObject; + callback(conversation,nil); + }]; + break; + } + case kJMSGConversationTypeChatRoom:{ + [JMSGConversation createChatRoomConversationWithRoomId:param[@"roomId"] completionHandler:^(id resultObject, NSError *error) { + if (error) { + callback(nil, error); + return; + } + + JMSGConversation *conversation = resultObject; + callback(conversation,nil); + }]; + break; + } + } +} + +- (JMSGMessage *)createMessageWithDictionary:(NSDictionary *)param type:(JMSGContentType)type { + + if (param[@"type"] == nil) { + return nil; + } + + NSString *appKey = nil; + if (param[@"appKey"]) { + appKey = param[@"appKey"]; + } else { + appKey = [JMessageHelper shareInstance].JMessageAppKey; + } + + JMSGOptionalContent *messageSendingOptions = nil; + if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { + messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; + } + + JMSGMessage *message = nil; + JMSGAbstractContent *content = nil; + switch (type) { + case kJMSGContentTypeText:{ + content = [[JMSGTextContent alloc] initWithText:param[@"text"]]; + break; + } + case kJMSGContentTypeImage:{ + NSString *mediaPath = param[@"path"]; + if([[NSFileManager defaultManager] fileExistsAtPath: mediaPath]){ + mediaPath = mediaPath; + } else { + return nil; + } + content = [[JMSGImageContent alloc] initWithImageData: [NSData dataWithContentsOfFile: mediaPath]]; + + break; + } + case kJMSGContentTypeVoice:{ + NSString *mediaPath = param[@"path"]; + double duration = 0; + if([[NSFileManager defaultManager] fileExistsAtPath: mediaPath]){ + mediaPath = mediaPath; + + NSError *error = nil; + AVAudioPlayer *avAudioPlayer = [[AVAudioPlayer alloc] initWithData:[NSData dataWithContentsOfFile:mediaPath] error: &error]; + if (error) { + return nil; + } + + duration = avAudioPlayer.duration; + avAudioPlayer = nil; + + } else { + + return nil; + } + content = [[JMSGVoiceContent alloc] initWithVoiceData:[NSData dataWithContentsOfFile: mediaPath] voiceDuration:@(duration)]; + break; + } + case kJMSGContentTypeLocation:{ + content = [[JMSGLocationContent alloc] initWithLatitude:param[@"latitude"] longitude:param[@"longitude"] scale:param[@"scale"] address: param[@"address"]]; + break; + } + case kJMSGContentTypeFile:{ + NSString *mediaPath = param[@"path"]; + if([[NSFileManager defaultManager] fileExistsAtPath: mediaPath]){ + mediaPath = mediaPath; + } else { + return nil; + } + + NSString *fileName = @""; + if (param[@"fileName"]) { + fileName = param[@"fileName"]; + } + + content = [[JMSGFileContent alloc] initWithFileData:[NSData dataWithContentsOfFile: mediaPath] fileName: fileName]; + break; + } + case kJMSGContentTypeCustom:{ + content = [[JMSGCustomContent alloc] initWithCustomDictionary: param[@"customObject"]]; + break; + } + + default: + return nil; + } + + JMSGConversationType targetType = [self convertStringToConvsersationType:param[@"type"]]; + + switch (targetType) { + case kJMSGConversationTypeSingle:{ + message = [JMSGMessage createSingleMessageWithContent:content username:param[@"username"]]; + break; + } + case kJMSGConversationTypeGroup:{ + message = [JMSGMessage createGroupMessageWithContent:content groupId:param[@"groupId"]]; + break; + } + + case kJMSGConversationTypeChatRoom:{ + message = [JMSGMessage createChatRoomMessageWithContent:content chatRoomId:param[@"roomId"]]; + break; + } + } + + if (message) { + if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { + NSDictionary *extras = param[@"extras"]; + for (NSString *key in extras.allKeys) { + [message.content addStringExtra:extras[key] forKey:key]; + } + } + return message; + } else { + return nil; + } +} + +- (JMSGContentType)convertStringToContentType:(NSString *)str { + if ([str isEqualToString:@"text"]) { + return kJMSGContentTypeText; + } + + if ([str isEqualToString:@"image"]) { + return kJMSGContentTypeImage; + } + + if ([str isEqualToString:@"voice"]) { + return kJMSGContentTypeVoice; + } + + if ([str isEqualToString:@"location"]) { + return kJMSGContentTypeLocation; + } + + if ([str isEqualToString:@"file"]) { + return kJMSGContentTypeFile; + } + + if ([str isEqualToString:@"custom"]) { + return kJMSGContentTypeCustom; + } + + return kJMSGContentTypeUnknown; +} + +- (JMSGConversationType)convertStringToConvsersationType:(NSString *)str { + if ([str isEqualToString:@"group"]) { + return kJMSGConversationTypeGroup; + } + + if ([str isEqualToString:@"chatroom"]) { + return kJMSGConversationTypeChatRoom; + } + + return kJMSGConversationTypeSingle; +} + #pragma mark IM - Events - (void)onSyncOfflineMessage: (NSNotification *) notification { CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK @@ -581,529 +804,200 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic { } - (void)sendTextMessage:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; - return; - } - - if (param[@"text"] == nil) { - [self returnParamError:command]; + NSDictionary * param = [command argumentAtIndex:0]; + + JMSGOptionalContent *messageSendingOptions = nil; + if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { + messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; + } + + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeText]; + if (!message) { + [self returnErrorWithLog:@"cannot create message, check your params" command:command]; + return; + } + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command:command error: error]; return; } - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; + self.SendMsgCallbackDic[message.msgId] = command.callbackId; + if (messageSendingOptions) { + [conversation sendMessage:message optionalContent:messageSendingOptions]; } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; + [conversation sendMessage:message]; } - + }]; +} + +- (void)sendImageMessage:(CDVInvokedUrlCommand *)command { + NSDictionary * param = [command argumentAtIndex:0]; + JMSGOptionalContent *messageSendingOptions = nil; if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; } + + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeImage]; + if (!message) { + [self returnErrorWithLog:@"cannot create message, check your params" command:command]; + return; + } + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command:command error: error]; + return; + } - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - JMSGTextContent *content = [[JMSGTextContent alloc] initWithText:param[@"text"]]; - JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command:command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [conversation sendMessage:message optionalContent:messageSendingOptions]; - } else { - [conversation sendMessage: message]; - } - }]; - - } else if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - JMSGTextContent *content = [[JMSGTextContent alloc] initWithText:param[@"text"]]; - JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [JMSGMessage sendMessage:message optionalContent:messageSendingOptions]; - } else { - [JMSGMessage sendMessage:message]; - } - + self.SendMsgCallbackDic[message.msgId] = command.callbackId; + if (messageSendingOptions) { + [conversation sendMessage:message optionalContent:messageSendingOptions]; } else { - [self returnParamError:command]; + [conversation sendMessage:message]; } + }]; } -- (void)sendImageMessage:(CDVInvokedUrlCommand *)command { +- (void)sendVoiceMessage:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - if (param[@"type"] == nil) { - [self returnParamError:command]; - return; + JMSGOptionalContent *messageSendingOptions = nil; + if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { + messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; } - - if (param[@"path"] == nil) { - [self returnParamError:command]; - return; + + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeVoice]; + if (!message) { + [self returnErrorWithLog:@"cannot create message, check your params and make sure the media resource is valid" command:command]; + return; } - - NSString *mediaPath = param[@"path"]; - if([[NSFileManager defaultManager] fileExistsAtPath: mediaPath]){ - mediaPath = mediaPath; - } else { - [self returnMediaFileError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command:command error: error]; return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } + } + + self.SendMsgCallbackDic[message.msgId] = command.callbackId; + if (messageSendingOptions) { + [conversation sendMessage:message optionalContent:messageSendingOptions]; + } else { + [conversation sendMessage:message]; + } + }]; +} + +- (void)sendCustomMessage:(CDVInvokedUrlCommand *)command { + NSDictionary * param = [command argumentAtIndex:0]; JMSGOptionalContent *messageSendingOptions = nil; if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - JMSGImageContent *content = [[JMSGImageContent alloc] initWithImageData: [NSData dataWithContentsOfFile: mediaPath]]; - JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [conversation sendMessage:message optionalContent:messageSendingOptions]; - } else { - [conversation sendMessage: message]; - } - }]; + + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeCustom]; + if (!message) { + [self returnErrorWithLog:@"cannot create message, check your params and make sure the media resource is valid" command:command]; + return; + } + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command:command error: error]; + return; + } - } else if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - JMSGImageContent *content = [[JMSGImageContent alloc] initWithImageData: [NSData dataWithContentsOfFile: mediaPath]]; - JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [JMSGMessage sendMessage:message optionalContent:messageSendingOptions]; - } else { - [JMSGMessage sendMessage:message]; - } + self.SendMsgCallbackDic[message.msgId] = command.callbackId; + if (messageSendingOptions) { + [conversation sendMessage:message optionalContent:messageSendingOptions]; } else { - [self returnParamError:command]; + [conversation sendMessage:message]; } + }]; } -- (void)sendVoiceMessage:(CDVInvokedUrlCommand *)command { +- (void)sendLocationMessage:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; - return; + + JMSGOptionalContent *messageSendingOptions = nil; + if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { + messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; } - - if (param[@"path"] == nil) { - [self returnErrorWithLog:@"media file not exit!" command: command]; - return; + + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeLocation]; + if (!message) { + [self returnErrorWithLog:@"cannot create message, check your params and make sure the media resource is valid" command:command]; + return; } - - NSString *mediaPath = param[@"path"]; - double duration = 0; - if([[NSFileManager defaultManager] fileExistsAtPath: mediaPath]){ - mediaPath = mediaPath; - - NSError *error = nil; - AVAudioPlayer *avAudioPlayer = [[AVAudioPlayer alloc] initWithData:[NSData dataWithContentsOfFile:mediaPath] error: &error]; - if (error) { - [self returnErrorWithLog:@"音频资源读取失败" command: command]; - } - - duration = avAudioPlayer.duration; - avAudioPlayer = nil; - - } else { - [self returnMediaFileError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command:command error: error]; return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - JMSGOptionalContent *messageSendingOptions = nil; - if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { - messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - // send single text message - JMSGVoiceContent *content = [[JMSGVoiceContent alloc] initWithVoiceData:[NSData dataWithContentsOfFile: mediaPath] voiceDuration:@(duration)]; - JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command:command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [conversation sendMessage:message optionalContent:messageSendingOptions]; - } else { - [conversation sendMessage: message]; - } - }]; - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - // send group text message - JMSGVoiceContent *content = [[JMSGVoiceContent alloc] initWithVoiceData:[NSData dataWithContentsOfFile: mediaPath] voiceDuration:@(duration)]; - JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [JMSGMessage sendMessage:message optionalContent:messageSendingOptions]; - } else { - [JMSGMessage sendMessage:message]; - } - } else { - [self returnParamError:command]; - } - } -} - -- (void)sendCustomMessage:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; - return;} - - if (param[@"customObject"] == nil || ![param[@"customObject"] isKindOfClass:[NSDictionary class]]) { - [self returnParamError:command]; - return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - JMSGOptionalContent *messageSendingOptions = nil; - if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { - messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - // send single text message - JMSGCustomContent *content = [[JMSGCustomContent alloc] initWithCustomDictionary: param[@"customObject"]]; - JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]]; - - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [conversation sendMessage:message optionalContent:messageSendingOptions]; - } else { - [conversation sendMessage: message]; - } - }]; - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - // send group text message - JMSGCustomContent *content = [[JMSGCustomContent alloc] initWithCustomDictionary: param[@"customObject"]]; - JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]]; - - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [JMSGMessage sendMessage:message optionalContent:messageSendingOptions]; - } else { - [JMSGMessage sendMessage:message]; - } - } else { - [self returnParamError:command]; - } - } -} - -- (void)sendLocationMessage:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil || - param[@"latitude"] == nil || - param[@"longitude"] == nil || - param[@"scale"] == nil || - param[@"address"] == nil) { - [self returnParamError:command]; - return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - JMSGOptionalContent *messageSendingOptions = nil; - if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { - messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - JMSGLocationContent *content = [[JMSGLocationContent alloc] initWithLatitude:param[@"latitude"] longitude:param[@"longitude"] scale:param[@"scale"] address: param[@"address"]]; - JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [conversation sendMessage:message optionalContent:messageSendingOptions]; - } else { - [conversation sendMessage: message]; - } - }]; - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - JMSGLocationContent *content = [[JMSGLocationContent alloc] initWithLatitude:param[@"latitude"] - longitude:param[@"longitude"] - scale:param[@"scale"] - address:param[@"address"]]; - JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId:param[@"groupId"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [JMSGMessage sendMessage:message optionalContent:messageSendingOptions]; - } else { - [JMSGMessage sendMessage:message]; - } - } else { - [self returnParamError:command]; - } - } + } + + self.SendMsgCallbackDic[message.msgId] = command.callbackId; + if (messageSendingOptions) { + [conversation sendMessage:message optionalContent:messageSendingOptions]; + } else { + [conversation sendMessage:message]; + } + }]; } - (void)sendFileMessage:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil || - param[@"path"] == nil) { - [self returnParamError:command]; - return; - } - NSString *fileName = @""; - if (param[@"fileName"]) { - fileName = param[@"fileName"]; - } - NSString *mediaPath = param[@"path"]; - if([[NSFileManager defaultManager] fileExistsAtPath: mediaPath]){ - mediaPath = mediaPath; - } else { - [self returnMediaFileError:command]; - return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - + JMSGOptionalContent *messageSendingOptions = nil; if (param[@"messageSendingOptions"] && [param[@"messageSendingOptions"] isKindOfClass: [NSDictionary class]]) { - messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - // send single text message - JMSGFileContent *content = [[JMSGFileContent alloc] initWithFileData:[NSData dataWithContentsOfFile: mediaPath] fileName: fileName]; - JMSGMessage *message = [JMSGMessage createSingleMessageWithContent:content username: param[@"username"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [conversation sendMessage:message optionalContent:messageSendingOptions]; - } else { - [conversation sendMessage: message]; - } - }]; - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - // send group text message - JMSGFileContent *content = [[JMSGFileContent alloc] initWithFileData:[NSData dataWithContentsOfFile: mediaPath] fileName: fileName]; - JMSGMessage *message = [JMSGMessage createGroupMessageWithContent: content groupId: param[@"groupId"]]; - if (param[@"extras"] && [param[@"extras"] isKindOfClass: [NSDictionary class]]) { - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras.allKeys) { - [message.content addStringExtra:extras[key] forKey:key]; - } - } - - self.SendMsgCallbackDic[message.msgId] = command.callbackId; - if (messageSendingOptions) { - [JMSGMessage sendMessage:message optionalContent:messageSendingOptions]; - } else { - [JMSGMessage sendMessage:message]; - } - } else { - [self returnParamError:command]; - } + messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; } -} - -- (void)getHistoryMessages:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - if (param[@"type"] == nil || - param[@"from"] == nil || - param[@"limit"] == nil) { - [self returnParamError:command]; - return; - } - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeLocation]; + if (!message) { + [self returnErrorWithLog:@"cannot create message, check your params and make sure the media resource is valid" command:command]; + return; + } - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { if (error) { - [self handleResultWithDictionary:@{} command: command error:error]; + [self handleResultWithDictionary: nil command:command error: error]; return; } - JMSGConversation *conversation = resultObject; - - NSNumber *limit = param[@"limit"]; - if ([limit isEqualToNumber:@(-1)]) { - limit = nil; - } - NSArray *messageList = [conversation messageArrayFromNewestWithOffset:param[@"from"] limit:limit]; - - NSMutableArray *messageDicList = @[].mutableCopy; - for (JMSGMessage *message in messageList) { - [messageDicList addObject:[message messageToDictionary]]; + self.SendMsgCallbackDic[message.msgId] = command.callbackId; + if (messageSendingOptions) { + [conversation sendMessage:message optionalContent:messageSendingOptions]; + } else { + [conversation sendMessage:message]; } - [self handleResultWithArray:messageDicList command:command error:error]; - }]; - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary:@{} command: command error:error]; - return; - } - - JMSGConversation *conversation = resultObject; - - NSNumber *limit = param[@"limit"]; - if ([limit isEqualToNumber:@(-1)]) { - limit = nil; - } - - NSArray *messageList = [conversation messageArrayFromNewestWithOffset:param[@"from"] limit:limit]; - - NSMutableArray *messageDicList = @[].mutableCopy; - for (JMSGMessage *message in messageList) { - [messageDicList addObject:[message messageToDictionary]]; - } - [self handleResultWithArray:messageDicList command:command error:error]; - - }]; - - } else { - [self returnParamError:command]; +} + +//change +- (void)getHistoryMessages:(CDVInvokedUrlCommand *)command { + NSDictionary * param = [command argumentAtIndex:0]; + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary:@{} command: command error:error]; return; } - } + + NSNumber *limit = param[@"limit"]; + if ([limit isEqualToNumber:@(-1)]) { + limit = nil; + } + NSArray *messageList = [conversation messageArrayFromNewestWithOffset:param[@"from"] limit:limit]; + + NSArray *messageDicArr = [messageList mapObjectsUsingBlock:^id(id obj, NSUInteger idx) { + JMSGMessage *message = obj; + return messageDicArr; + }]; + [self handleResultWithArray:messageDicArr command:command error:error]; + }]; } - (void)sendSingleTransCommand:(CDVInvokedUrlCommand *)command { @@ -1864,444 +1758,152 @@ - (void)downloadOriginalUserAvatar:(CDVInvokedUrlCommand *)command { - (void)downloadThumbImage:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - if (param[@"messageId"] == nil || - param[@"type"] == nil) { - [self returnParamError:command]; - return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; + return; + } - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; + JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; + if (message == nil) { + [self returnErrorWithLog:@"cann't find this message" command: command]; return; } - } + + if (message.contentType != kJMSGContentTypeImage) { + [self returnErrorWithLog:@"It is not voice message" command:command]; + return; + } else { + JMSGImageContent *content = (JMSGImageContent *) message.content; + + [content thumbImageData:^(NSData *data, NSString *objectId, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; + return; + } + + [self handleResultWithDictionary:@{@"messageId": message.msgId, + @"filePath": content.thumbImageLocalPath} + command:command error:error]; + }]; + } + }]; +} + +- (void)downloadOriginalImage:(CDVInvokedUrlCommand *)command { + NSDictionary * param = [command argumentAtIndex:0]; - if ([param[@"type"] isEqual: @"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { [self handleResultWithDictionary: nil command: command error: error]; return; - } - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeImage) { - [self returnErrorWithLog:@"It is not voice message" command:command]; - return; - } else { - JMSGImageContent *content = (JMSGImageContent *) message.content; - - [content thumbImageData:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath": content.thumbImageLocalPath} - command:command error:error]; - }]; - } - }]; - } else { - [JMSGGroup groupInfoWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGGroup *group = resultObject; - [JMSGConversation createGroupConversationWithGroupId:group.gid completionHandler:^(id resultObject, NSError *error) { - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeVoice) { - [self returnErrorWithLog:@"It is not image message" command:command]; - return; - } else { - JMSGImageContent *content = (JMSGImageContent *) message.content; - [content thumbImageData:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath": content.thumbImageLocalPath} - command:command error:error]; - }]; - } - }]; - }]; - } -} -- (void)downloadOriginalImage:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - if (param[@"messageId"] == nil || - param[@"type"] == nil) { - [self returnParamError:command]; - return; } - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; + JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; + if (message == nil) { + [self returnErrorWithLog:@"cann't find this message" command: command]; + return; } - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - + if (message.contentType != kJMSGContentTypeImage) { + [self returnErrorWithLog:@"It is not voice message" command:command]; + return; } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; + JMSGImageContent *content = (JMSGImageContent *) message.content; + [content largeImageDataWithProgress:^(float percent, NSString *msgId) { + + } completionHandler:^(NSData *data, NSString *objectId, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; + return; } + + JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; + [self handleResultWithDictionary:@{@"messageId": message.msgId, + @"filePath": [mediaContent originMediaLocalPath]} + command:command error:error]; + }]; } - - if ([param[@"type"] isEqual: @"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeImage) { - [self returnErrorWithLog:@"It is not voice message" command:command]; - return; - } else { - JMSGImageContent *content = (JMSGImageContent *) message.content; - [content largeImageDataWithProgress:^(float percent, NSString *msgId) { - - } completionHandler:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath": [mediaContent originMediaLocalPath]} - command:command error:error]; - }]; - } - }]; - } else { - [JMSGGroup groupInfoWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGGroup *group = resultObject; - [JMSGConversation createGroupConversationWithGroupId:group.gid completionHandler:^(id resultObject, NSError *error) { - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeVoice) { - [self returnErrorWithLog:@"It is not image message" command:command]; - return; - } else { - JMSGImageContent *content = (JMSGImageContent *) message.content; - [content largeImageDataWithProgress:^(float percent, NSString *msgId) { - - } completionHandler:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath": [mediaContent originMediaLocalPath]} - command:command error:error]; - }]; - } - }]; - }]; - } + }]; } - (void)downloadVoiceFile:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"messageId"] == nil || - param[@"type"] == nil) { - [self returnParamError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; + } + + JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; + + if (message == nil) { + [self returnErrorWithLog:@"cann't find this message" command: command]; + return; + } + + if (message.contentType != kJMSGContentTypeVoice) { + [self returnErrorWithLog:@"It is not image message" command:command]; + return; + } else { + JMSGVoiceContent *content = (JMSGVoiceContent *) message.content; + [content voiceData:^(NSData *data, NSString *objectId, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; return; - } - } - - if ([param[@"type"] isEqual: @"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeVoice) { - [self returnErrorWithLog:@"It is not image message" command:command]; - return; - } else { - JMSGVoiceContent *content = (JMSGVoiceContent *) message.content; - [content voiceData:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath": [mediaContent originMediaLocalPath]} - command:command error:error]; - }]; - } - }]; - } else { - [JMSGGroup groupInfoWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGGroup *group = resultObject; - [JMSGConversation createGroupConversationWithGroupId:group.gid completionHandler:^(id resultObject, NSError *error) { - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeVoice) { - [self returnErrorWithLog:@"It is not voice message" command:command]; - return; - } else { - JMSGVoiceContent *content = (JMSGVoiceContent *) message.content; - [content voiceData:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *)message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath": [mediaContent originMediaLocalPath]} - command:command - error:error]; - }]; - } - }]; + } + + JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content; + [self handleResultWithDictionary:@{@"messageId": message.msgId, + @"filePath": [mediaContent originMediaLocalPath]} + command:command error:error]; }]; - } + } + }]; } - (void)downloadFile:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"messageId"] == nil || - param[@"type"] == nil) { - [self returnParamError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; + + if (message == nil) { + [self returnErrorWithLog:@"cann't find this message" command: command]; return; - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; + } + + if (message.contentType != kJMSGContentTypeFile) { + [self returnErrorWithLog:@"It is not file message" command:command]; + return; + } else { + JMSGFileContent *content = (JMSGFileContent *) message.content; + [content fileData:^(NSData *data, NSString *objectId, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; return; - } - } - - if ([param[@"type"] isEqual: @"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] appKey:appKey completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - - if (message == nil) { - [self returnErrorWithLog:@"cann't find this message" command: command]; - return; - } - - if (message.contentType != kJMSGContentTypeFile) { - [self returnErrorWithLog:@"It is not file message" command:command]; - return; - } else { - JMSGFileContent *content = (JMSGFileContent *) message.content; - [content fileData:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGFileContent *fileContent = (JMSGFileContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath":[fileContent originMediaLocalPath]} - command:command error:error]; - }]; - } - }]; - } else { - [JMSGGroup groupInfoWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGGroup *group = (JMSGGroup *) resultObject; - [JMSGConversation createGroupConversationWithGroupId:group.gid completionHandler:^(id resultObject, NSError *error) { - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - - if (message == nil) { - [self returnErrorWithLog:@"Can't find the message" command:command]; - return; - } - - if (message.contentType != kJMSGContentTypeFile) { - [self returnErrorWithLog:@"It is not a file message" command:command]; - return; - - } else { - JMSGFileContent *content = (JMSGFileContent *) message.content; - [content fileData:^(NSData *data, NSString *objectId, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGFileContent *fileContent = (JMSGFileContent *) message.content; - [self handleResultWithDictionary:@{@"messageId": message.msgId, - @"filePath":[fileContent originMediaLocalPath]} - command:command error:error]; - }]; - } - }]; + } + JMSGFileContent *fileContent = (JMSGFileContent *) message.content; + [self handleResultWithDictionary:@{@"messageId": message.msgId, + @"filePath":[fileContent originMediaLocalPath]} + command:command error:error]; }]; - } + } + }]; } - (void)createConversation:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; return; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; - } - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqualToString:@"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; - } else { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; - } - + } + + [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; + }]; } - (void)deleteConversation:(CDVInvokedUrlCommand *)command { @@ -2341,52 +1943,15 @@ - (void)deleteConversation:(CDVInvokedUrlCommand *)command { - (void)getConversation:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; return; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; - } - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqualToString:@"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; - } else { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; - } + } + + [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; + }]; } - (void)getConversations:(CDVInvokedUrlCommand *)command { @@ -2411,124 +1976,35 @@ - (void)getConversations:(CDVInvokedUrlCommand *)command { - (void)resetUnreadMessageCount:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; return; } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; - } - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqualToString:@"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - [conversation clearUnreadCount]; - [self handleResultWithDictionary:nil command:command error:error]; - }]; - - } else { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - [conversation clearUnreadCount]; - [self handleResultWithDictionary:nil command:command error:error]; - }]; - } + [conversation clearUnreadCount]; + [self handleResultWithDictionary:nil command:command error:error]; + }]; } - +//change - (void)retractMessage:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - - if (param[@"type"] == nil) { - [self returnParamError:command]; - return;} - - if (param[@"messageId"] == nil) { - [self returnParamError:command]; + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command:command error: error]; return; } - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - // send single text message - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command:command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - if (message == nil) { - [self returnErrorWithLog:@"cann't found this message" command:command]; - return; - } - - [conversation retractMessage:message completionHandler:^(id resultObject, NSError *error) { - [self handleResultWithDictionary:@{} command:command error:error]; - }]; - }]; - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - // send group text message - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] - completionHandler:^(id resultObject, NSError *error) { - - if (error) { - [self handleResultWithDictionary: nil command:command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; - if (message == nil) { - [self returnErrorWithLog:@"cann't found this message" command:command]; - return; - } - - [conversation retractMessage:message completionHandler:^(id resultObject, NSError *error) { - [self handleResultWithDictionary:@{} command:command error:error]; - }]; - }]; - } else { - [self returnParamError:command]; - } + JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]]; + if (message == nil) { + [self returnErrorWithLog:@"cann't found this message" command:command]; + return; } + [conversation retractMessage:message completionHandler:^(id resultObject, NSError *error) { + [self handleResultWithDictionary:@{} command:command error:error]; + }]; + }]; } - (void)updateGroupAvatar:(CDVInvokedUrlCommand *)command { @@ -2596,7 +2072,7 @@ - (void)downloadOriginalGroupAvatar:(CDVInvokedUrlCommand *)command { }]; }]; } - +//change - (void)setConversationExtras:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"type"]) { @@ -2626,167 +2102,55 @@ - (void)setConversationExtras:(CDVInvokedUrlCommand *)command { } else { appKey = [JMessageHelper shareInstance].JMessageAppKey; } - - if ([param[@"type"] isEqualToString:@"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras) { - [conversation setExtraValue:extras[key] forKey:key]; - } - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; - } else { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - JMSGConversation *conversation = resultObject; - NSDictionary *extras = param[@"extras"]; - for (NSString *key in extras) { - [conversation setExtraValue:extras[key] forKey:key]; - } - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; - } + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; + NSDictionary *extras = param[@"extras"]; + for (NSString *key in extras) { + [conversation setExtraValue:extras[key] forKey:key]; + } + [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; + return; + } + }]; } - (void)getMessageById:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - if (!param[@"type"]) { - [self returnParamError:command]; - return; - } - if (!param[@"messageId"]) { - [self returnParamError:command]; - return; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; - } - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } - - if ([param[@"type"] isEqualToString:@"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - JMSGMessage *msg = [conversation messageWithMessageId:param[@"messageId"]]; - if (msg != nil) { - [self handleResultWithDictionary:[msg messageToDictionary] command:command error:error]; - } else { - [self handleResultNilWithCommand:command error:error]; - } - - }]; - } else { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - JMSGMessage *msg = [conversation messageWithMessageId:param[@"messageId"]]; - if (msg != nil) { - [self handleResultWithDictionary:[msg messageToDictionary] command:command error:error]; - } else { - [self handleResultNilWithCommand:command error:error]; - } - }]; - } + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; + return; + } + + JMSGMessage *msg = [conversation messageWithMessageId:param[@"messageId"]]; + if (msg != nil) { + [self handleResultWithDictionary:[msg messageToDictionary] command:command error:error]; + } else { + [self handleResultNilWithCommand:command error:error]; + } + }]; } - (void)deleteMessageById:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; - if (!param[@"type"]) { - [self returnParamError:command]; - return; - } - if (!param[@"messageId"]) { - [self returnParamError:command]; - return; - } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - - } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; - } - } - - NSString *appKey = nil; - if (param[@"appKey"]) { - appKey = param[@"appKey"]; - } else { - appKey = [JMessageHelper shareInstance].JMessageAppKey; - } + + [self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) { + if (error) { + [self handleResultWithDictionary: nil command: command error: error]; + return; + } - if ([param[@"type"] isEqualToString:@"single"]) { - [JMSGConversation createSingleConversationWithUsername:param[@"username"] - appKey:appKey - completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - BOOL result = [conversation deleteMessageWithMessageId:param[@"messageId"]]; - - if (result) { - [self handleResultNilWithCommand:command error:nil]; - } else { - [self handleResultNilWithCommand:command error:[NSError errorWithDomain:@"message message fail" code: 3 userInfo: nil]]; - } - }]; - } else { - [JMSGConversation createGroupConversationWithGroupId:param[@"groupId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - BOOL result = [conversation deleteMessageWithMessageId:param[@"messageId"]]; - if (result) { - [self handleResultNilWithCommand:command error:nil]; - } else { - [self handleResultNilWithCommand:command error:[NSError errorWithDomain:@"message message fail" code: 3 userInfo: nil]]; - } - }]; - } + BOOL result = [conversation deleteMessageWithMessageId:param[@"messageId"]]; + + if (result) { + [self handleResultNilWithCommand:command error:nil]; + } else { + [self handleResultNilWithCommand:command error:[NSError errorWithDomain:@"message message fail" code: 3 userInfo: nil]]; + } + }]; } - (void)getChatroomInfoListOfApp:(CDVInvokedUrlCommand *)command { From 163ddc627df253ae6921867e1528f94963a98d34 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Fri, 12 Jan 2018 14:04:59 +0800 Subject: [PATCH 4/8] fix send message bug --- src/ios/Plugins/JMessagePlugin.m | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index 945cd8f..ae094e6 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -169,12 +169,6 @@ - (void)getConversationWithDictionary:(NSDictionary *)param callback:(JMSGConver return; } - if (param[@"text"] == nil) { - NSError *error = [NSError errorWithDomain:@"param error!" code: 1 userInfo: nil]; - callback(nil,error); - return; - } - NSString *appKey = nil; if (param[@"appKey"]) { appKey = param[@"appKey"]; @@ -956,7 +950,7 @@ - (void)sendFileMessage:(CDVInvokedUrlCommand *)command { messageSendingOptions = [self convertDicToJMSGOptionalContent:param[@"messageSendingOptions"]]; } - JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeLocation]; + JMSGMessage *message = [self createMessageWithDictionary:param type:kJMSGContentTypeFile]; if (!message) { [self returnErrorWithLog:@"cannot create message, check your params and make sure the media resource is valid" command:command]; return; @@ -994,7 +988,7 @@ - (void)getHistoryMessages:(CDVInvokedUrlCommand *)command { NSArray *messageDicArr = [messageList mapObjectsUsingBlock:^id(id obj, NSUInteger idx) { JMSGMessage *message = obj; - return messageDicArr; + return [message messageToDictionary]; }]; [self handleResultWithArray:messageDicArr command:command error:error]; }]; From e943c235d6d8719d8d04bea74f4262b24e00bee8 Mon Sep 17 00:00:00 2001 From: Hevin Date: Mon, 15 Jan 2018 11:14:06 +0800 Subject: [PATCH 5/8] Optimize chatRoom APIs - Changed the spelling of chat room - Merge the `createChatRoomConversation` with `createConversation` --- src/android/ChatroomHandler.java | 82 ++----------------- src/android/JMessagePlugin.java | 60 +++++--------- src/android/JMessageUtils.java | 4 +- src/android/JsonUtils.java | 10 ++- www/JMessagePlugin.js | 133 ++++++++++++++----------------- 5 files changed, 99 insertions(+), 190 deletions(-) diff --git a/src/android/ChatroomHandler.java b/src/android/ChatroomHandler.java index d39a4fc..72aa5db 100644 --- a/src/android/ChatroomHandler.java +++ b/src/android/ChatroomHandler.java @@ -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); @@ -62,7 +62,7 @@ public void gotResult(int status, String desc, List chatRoomInfos) }); } - static void getChatroomInfoListOfUser(JSONArray data, final CallbackContext callback) { + static void getChatRoomInfoListOfUser(JSONArray data, final CallbackContext callback) { ChatRoomManager.getChatRoomListByUser(new RequestCallback>() { @Override public void gotResult(int status, String desc, List chatRoomInfoList) { @@ -84,7 +84,7 @@ public void gotResult(int status, String desc, List chatRoomInfoLi }); } - static void getChatroomInfoListById(JSONArray data, final CallbackContext callback) { + static void getChatRoomInfoListById(JSONArray data, final CallbackContext callback) { Set roomIds = new HashSet(); // JS 层为了和 iOS 统一,因此 roomId 类型为 String,在原生做转换。 try { @@ -121,7 +121,7 @@ public void gotResult(int status, String desc, List chatRoomInfos) }); } - static void getChatroomOwner(JSONArray data, final CallbackContext callback) { + static void getChatRoomOwner(JSONArray data, final CallbackContext callback) { final long roomId; try { @@ -154,7 +154,7 @@ public void gotResult(int status, String desc, List chatRoomInfoLi }); } - static void enterChatroom(JSONArray data, final CallbackContext callback) { + static void enterChatRoom(JSONArray data, final CallbackContext callback) { final long roomId; try { @@ -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 { @@ -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 conversations = JMessageClient.getChatRoomConversationList(); JSONArray result = new JSONArray(); @@ -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); - } - } } diff --git a/src/android/JMessagePlugin.java b/src/android/JMessagePlugin.java index 2b99160..7d1d67e 100644 --- a/src/android/JMessagePlugin.java +++ b/src/android/JMessagePlugin.java @@ -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; @@ -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)); @@ -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; @@ -1980,44 +1974,32 @@ void setConversationExtras(JSONArray data, CallbackContext callback) { // 聊天室 - 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 @@ -2289,7 +2271,7 @@ public void onEvent(ChatRoomMessageEvent event) { e.printStackTrace(); } - JSONObject eventJson = toJson("receiveChatroomMessage", result); + JSONObject eventJson = toJson("receiveChatRoomMessage", result); eventSuccess(eventJson); } diff --git a/src/android/JMessageUtils.java b/src/android/JMessageUtils.java index fd180b2..156c3b0 100644 --- a/src/android/JMessageUtils.java +++ b/src/android/JMessageUtils.java @@ -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); } @@ -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); } diff --git a/src/android/JsonUtils.java b/src/android/JsonUtils.java index e53f3ff..f1ac1e9 100644 --- a/src/android/JsonUtils.java +++ b/src/android/JsonUtils.java @@ -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; @@ -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(); @@ -316,7 +320,7 @@ 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()); diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index 8562c5b..26506da 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -11,7 +11,7 @@ var EventHandlers = { contactNotify: [], retractMessage: [], receiveTransCommand: [], // 透传命令 - receiveChatroomMessage: [] // 聊天室消息 + receiveChatRoomMessage: [] // 聊天室消息 } var JMessagePlugin = { @@ -202,7 +202,7 @@ var JMessagePlugin = { * 增加或更新扩展字段,可扩展会话属性,比如:会话置顶、标识特殊会话等 * * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 目标群组 id。 * 'username': String, // 目标用户名。 * 'appKey': String, // 目标用户所属 AppKey。 @@ -217,11 +217,11 @@ var JMessagePlugin = { /** * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 * 'username': String, // 当 type 为 'single' 时,username 不能为空 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空 * 'text': String, // 消息内容 * 'extras': Object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象 @@ -234,11 +234,11 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 * 'username': String, // 当 type 为 'single' 时,username 不能为空 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空 * 'path': String, // 本地图片绝对路径。 * 'extras': object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象 @@ -258,7 +258,7 @@ var JMessagePlugin = { * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 * 'username': String, // 当 type 为 'single' 时,username 不能为空 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空 * 'path': String, // 本地语音文件路径。 * 'extras': object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象。 @@ -271,10 +271,10 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 * 'username': String, // 当 type 为 'single' 时,username 不能为空 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 * 'customObject': {'key1': 'value1'} // Optional. 自定义键值对 * } @@ -286,11 +286,11 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空 * 'username': String, // 当 type 为 'single' 时,username 不能为空 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空 * 'latitude': Number, // 纬度信息 * 'longitude': Number, // 经度信息 * 'scale': Number, // 地图缩放比例 @@ -305,11 +305,11 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空。 * 'username': String, // 当 type 为 'single' 时,username 不能为空。 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空 * 'path': String, // 本地文件路径。 * 'extras': object, // Optional. 自定义键值对 = {'key1': 'value1'} * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象。 @@ -324,10 +324,10 @@ var JMessagePlugin = { * 消息撤回。 * * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空。 * 'username': String, // 当 type 为 'single' 时,username 不能为空。 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空。 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空。 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 * 'messageId': string // 消息 id。 * } @@ -343,11 +343,11 @@ var JMessagePlugin = { * 例如:当 from = 0 && limit = -1 时,返回所有历史消息。 * * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 当 type 为 'group' 时,groupId 不能为空。 * 'username': String, // 当 type 为 'single' 时,username 不能为空。 * 'appKey': String, // 当 type 为 'single' 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。 - * 'roomId': String, // 当 type 为 'chatroom' 时,roomId 不能为空。 + * 'roomId': String, // 当 type 为 'chatRoom' 时,roomId 不能为空。 * 'from': Number, // 开始的消息下标。 * 'limit': Number // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 的 10 条历史消息。 * } @@ -361,11 +361,11 @@ var JMessagePlugin = { * 根据消息 id 获取消息对象。 * * @param {object} params = { - * type: String, // 'single' / 'group' / 'chatroom' + * type: String, // 'single' / 'group' / 'chatRoom' * groupId: String, // 当 type = 'group' 时,groupId 必填。 * username: String, // 当 type = 'single' 时,username 必填。 * appKey: String, // 当 type = 'single' 时,用于指定对象所属应用的 appKey。如果未空,则默认为当前应用。 - * roomId: String, // 当 type 为 'chatroom' 时,roomId 不能为空。 + * roomId: String, // 当 type 为 'chatRoom' 时,roomId 不能为空。 * messageId: string // 消息 Id。 * } */ @@ -723,13 +723,14 @@ var JMessagePlugin = { exec(success, error, PLUGIN_NAME, 'downloadFile', [params]) }, /** - * 创建聊天会话。 + * 创建聊天会话。目前可创建单聊、群聊和聊天室会话。 * * @param {object} params = { - * 'type': String, // 'single' / 'group' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 目标群组 id。 * 'username': String, // 目标用户名。 * 'appKey': String, // 目标用户所属 AppKey。 + * 'roomId': String // 目标聊天室 id。 * } * @param {function} success = function (conversation) {} // 以参数形式返回聊天会话对象。 * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -738,13 +739,14 @@ var JMessagePlugin = { exec(success, error, PLUGIN_NAME, 'createConversation', [params]) }, /** - * 删除聊天会话,同时会删除本地聊天记录。 + * 删除聊天会话,同时将删除本地聊天记录。 * * @param {object} params = { - * 'type': String, // 'single' / 'group' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 目标群组 id。 * 'username': String, // 目标用户名。 * 'appKey': String, // 目标用户所属 AppKey。 + * 'roomId': String // 目标聊天室 id。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -754,12 +756,13 @@ var JMessagePlugin = { }, /** * 进入聊天会话。可以在进入聊天会话页面时调用该方法,这样在收到当前聊天用户的消息时,不会显示通知。 + * 对于聊天室(Chat Room)需要调用 `enterChatRoom` 方法。 * * @param {object} params = { * 'type': String, // 'single' / 'group' * 'groupId': String, // 目标群组 id。 * 'username': String, // 目标用户名。 - * 'appKey': String, // 目标用户所属 AppKey。 + * 'appKey': String // 目标用户所属 AppKey。 * } * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} @@ -769,6 +772,10 @@ var JMessagePlugin = { exec(success, error, PLUGIN_NAME, 'enterConversation', [params]) } }, + /** + * 退出聊天会话。 + * 对于聊天室(Chat Room)需要调用 `exitChatRoom` 方法。 + */ exitConversation: function () { if (device.platform === 'Android') { exec(null, null, PLUGIN_NAME, 'exitConversation', []) @@ -776,7 +783,7 @@ var JMessagePlugin = { }, /** * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'roomId' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 目标群组 id。当 type 为 'group' 时必填。 * 'username': String, // 目标用户名。当 type 为 'single' 时必填。 * 'appKey': String, // 目标用户所属 AppKey。如果不传或为空字符串,则默认为当前应用。 @@ -799,7 +806,7 @@ var JMessagePlugin = { * 重置单个会话的未读消息数。 * * @param {object} params = { - * 'type': String, // 'single' / 'group' / 'chatroom' + * 'type': String, // 'single' / 'group' / 'chatRoom' * 'groupId': String, // 目标群组 id。 * 'username': String, // 目标用户名。 * 'appKey': String, // 目标用户所属 AppKey。 @@ -813,27 +820,27 @@ var JMessagePlugin = { }, // 聊天室 API - start - Chatroom: { + ChatRoom: { /** * 获取当前应用所属聊天室的信息。 * @param {object} params = { * start: number, // 索引起始位置,从 0 开始。 * count: number // 查询个数。 * } - * @param {function} success = function (chatroomInfoList) {} + * @param {function} success = function (chatRoomInfoList) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - getChatroomInfoListOfApp: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'getChatroomInfoListOfApp', [params]) + getChatRoomInfoListOfApp: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'getChatRoomInfoListOfApp', [params]) }, /** * 获取当前登录用户加入的聊天室列表。 * - * @param {function} success = function (chatroomInfoList) {} + * @param {function} success = function (chatRoomInfoList) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - getChatroomInfoListOfUser: function (success, error) { - exec(success, error, PLUGIN_NAME, 'getChatroomInfoListOfUser', []) + getChatRoomInfoListOfUser: function (success, error) { + exec(success, error, PLUGIN_NAME, 'getChatRoomInfoListOfUser', []) }, /** * 根据聊天室 id 获取聊天室信息。 @@ -841,31 +848,33 @@ var JMessagePlugin = { * @param {object} params = { * roomIds: [String] // 聊天室 id 字符串数组。 * } - * @param {function} success = function (chatroomInfoList) {} + * @param {function} success = function (ChatRoomInfoList) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - getChatroomInfoListById: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'getChatroomInfoListById', [params]) + getChatRoomInfoListById: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'getChatRoomInfoListById', [params]) }, /** * 获取聊天室拥有者的用户信息。 * - * @param {*} params = { roomId: String } // 聊天室 id + * @param {object} params = { roomId: String } // 聊天室 id * @param {function} success = function (userInfo) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - getChatroomOwner: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'getChatroomOwner', [params]) + getChatRoomOwner: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'getChatRoomOwner', [params]) }, /** * 进入聊天室。 + * 用户只有成功调用此接口之后,才能收到聊天室消息,以及在此聊天室中发言。 + * 成功进入聊天室之后,会将聊天室中最近若干条聊天记录同步到本地并触发 `receiveChatRoomMessage` 事件。 * * @param {object} params = { roomId: String } * @param {function} success = function (conversation) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - enterChatroom: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'enterChatroom', [params]) + enterChatRoom: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'enterChatRoom', [params]) }, /** * 离开聊天室。 @@ -874,8 +883,8 @@ var JMessagePlugin = { * @param {function} success = function () {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - exitChatroom: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'exitChatroom', [params]) + exitChatRoom: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'exitChatRoom', [params]) }, /** * 获取聊天室会话信息。如果无法返回 @@ -884,8 +893,8 @@ var JMessagePlugin = { * @param {function} success = function (conversation) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - getChatroomConversation: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'getChatroomConversation', [params]) + getChatRoomConversation: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'getChatRoomConversation', [params]) }, /** * 从本地数据库中获取包含当前登录用户所有聊天室会话的列表。 @@ -893,29 +902,9 @@ var JMessagePlugin = { * @param {function} success = function (conversationList) {} * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} */ - getChatroomConversationList: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'getChatroomConversationList', [params]) + getChatRoomConversationList: function (params, success, error) { + exec(success, error, PLUGIN_NAME, 'getChatRoomConversationList', [params]) }, - /** - * 创建聊天室会话。 - * - * @param {object} params = { roomId: String } - * @param {function} success = function (conversation) {} - * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} - */ - createChatroomConversation: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'createChatroomConversation', [params]) - }, - /** - * 删除聊天室会话,同时删除掉本地相关缓存。 - * - * @param {object} params = { roomId: String } - * @param {function} success = function (conversation) {} - * @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {} - */ - deleteChatroomConversation: function (params, success, error) { - exec(success, error, PLUGIN_NAME, 'deleteChatroomConversation', [params]) - } }, // 聊天室 - end @@ -1070,13 +1059,13 @@ var JMessagePlugin = { * messageArray: Array // 消息对象数组。 * } */ - addReceiveChatroomMessageListener: function (listener) { - EventHandlers.receiveChatroomMessage.push(listener) + addReceiveChatRoomMessageListener: function (listener) { + EventHandlers.receiveChatRoomMessage.push(listener) }, - removeReceiveChatroomMessageListener: function (listener) { - var handlerIndex = EventHandlers.receiveChatroomMessage.indexOf(listener) + removeReceiveChatRoomMessageListener: function (listener) { + var handlerIndex = EventHandlers.receiveChatRoomMessage.indexOf(listener) if (handlerIndex >= 0) { - EventHandlers.receiveChatroomMessage.splice(handlerIndex, 1) + EventHandlers.receiveChatRoomMessage.splice(handlerIndex, 1) } } From 0e0ebebcf326ccec67ce67bd58a4797f7b36dffe Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Mon, 15 Jan 2018 13:18:30 +0800 Subject: [PATCH 6/8] adjust chatroom to chatRoom and merge createChatRoomConversation deleteChatRoomConversation to createConversation DeleteConversation --- src/ios/Plugins/JMessageHelper.m | 6 +-- src/ios/Plugins/JMessagePlugin.h | 2 - src/ios/Plugins/JMessagePlugin.m | 77 ++++++++++---------------------- 3 files changed, 27 insertions(+), 58 deletions(-) diff --git a/src/ios/Plugins/JMessageHelper.m b/src/ios/Plugins/JMessageHelper.m index 7f51cdb..d63c7ca 100644 --- a/src/ios/Plugins/JMessageHelper.m +++ b/src/ios/Plugins/JMessageHelper.m @@ -265,7 +265,7 @@ -(NSMutableDictionary*)conversationToDictionary{ case kJMSGConversationTypeChatRoom:{ JMSGChatRoom *chatroom = self.target; dict[@"target"] = [chatroom chatRoomToDictionary]; - dict[@"conversationType"] = @"chatroom"; + dict[@"conversationType"] = @"chatRoom"; break; } } @@ -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; } diff --git a/src/ios/Plugins/JMessagePlugin.h b/src/ios/Plugins/JMessagePlugin.h index 522939f..564c29e 100644 --- a/src/ios/Plugins/JMessagePlugin.h +++ b/src/ios/Plugins/JMessagePlugin.h @@ -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 diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index ae094e6..8624f29 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -369,7 +369,7 @@ - (JMSGConversationType)convertStringToConvsersationType:(NSString *)str { return kJMSGConversationTypeGroup; } - if ([str isEqualToString:@"chatroom"]) { + if ([str isEqualToString:@"chatRoom"]) { return kJMSGConversationTypeChatRoom; } @@ -1907,16 +1907,14 @@ - (void)deleteConversation:(CDVInvokedUrlCommand *)command { [self returnParamError:command]; return; } - - if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) { - + + if (([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) || + ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) || + ([param[@"type"] isEqual: @"chatRoom"] && param[@"roomId"] != nil)) { + } else { - if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) { - - } else { - [self returnParamError:command]; - return; - } + [self returnParamError:command]; + return; } NSString *appKey = nil; @@ -1925,13 +1923,23 @@ - (void)deleteConversation:(CDVInvokedUrlCommand *)command { } else { appKey = [JMessageHelper shareInstance].JMessageAppKey; } - - if ([param[@"type"] isEqualToString:@"single"]) { + + JMSGConversationType type = [self convertStringToConvsersationType:param[@"type"]]; + switch (type) { + case kJMSGConversationTypeSingle: { [JMSGConversation deleteSingleConversationWithUsername:param[@"username"] appKey:appKey]; - } else { + break; + } + case kJMSGConversationTypeGroup: { [JMSGConversation deleteGroupConversationWithGroupId:param[@"groupId"]]; + break; + } + case kJMSGConversationTypeChatRoom: { + [JMSGConversation deleteChatRoomConversationWithRoomId:param[@"roomId"]]; + break; + } } - + [self handleResultWithDictionary:nil command:command error:nil]; } @@ -1980,7 +1988,7 @@ - (void)resetUnreadMessageCount:(CDVInvokedUrlCommand *)command { [self handleResultWithDictionary:nil command:command error:error]; }]; } -//change + - (void)retractMessage:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; @@ -2022,6 +2030,7 @@ - (void)updateGroupAvatar:(CDVInvokedUrlCommand *)command { [self returnParamError:command]; } } + - (void)downloadThumbGroupAvatar:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; @@ -2300,44 +2309,6 @@ - (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command { }]; } -- (void)createChatroomConversation:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - - if (!param[@"roomId"]) { - [self returnParamError:command]; - return; - } - - [JMSGConversation createChatRoomConversationWithRoomId:param[@"roomId"] completionHandler:^(id resultObject, NSError *error) { - if (error) { - [self handleResultWithDictionary: nil command: command error: error]; - return; - } - - JMSGConversation *conversation = resultObject; - [self handleResultWithDictionary:[conversation conversationToDictionary] command:command error:error]; - }]; -} - -- (void)deleteChatroomConversation:(CDVInvokedUrlCommand *)command { - NSDictionary * param = [command argumentAtIndex:0]; - - if (!param[@"roomId"]) { - [self returnParamError:command]; - return; - } - JMSGConversation *chatRoomConversation = [JMSGConversation chatRoomConversationWithRoomId:param[@"roomId"]]; - NSError *error = nil; - if (!chatRoomConversation) { - error = [NSError errorWithDomain:@"cannot found chat room convsersation from this roomId" code: 1 userInfo: nil]; - [self handleResultNilWithCommand:command error:error]; - return; - } - - [JMSGConversation deleteChatRoomConversationWithRoomId:param[@"roomId"]]; - [self handleResultWithDictionary:[chatRoomConversation conversationToDictionary] command:command error:error]; -} - - (void)getChatroomOwner:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; From 6cfb507b8109dbec893760e0b71c136c80d98aaa Mon Sep 17 00:00:00 2001 From: Hevin Date: Mon, 15 Jan 2018 13:19:03 +0800 Subject: [PATCH 7/8] Update the 'currentMemberCount' to 'memberCount' --- src/android/JsonUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/JsonUtils.java b/src/android/JsonUtils.java index f1ac1e9..755392a 100644 --- a/src/android/JsonUtils.java +++ b/src/android/JsonUtils.java @@ -327,7 +327,7 @@ static JSONObject toJson(ChatRoomInfo chatRoomInfo) throws JSONException { 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; } } From 7b52adc1f22f578362cd59c44e9fa5172bed9c92 Mon Sep 17 00:00:00 2001 From: Hevin Date: Mon, 15 Jan 2018 17:23:46 +0800 Subject: [PATCH 8/8] build: v3.1.7 --- README.md | 2 +- package.json | 2 +- plugin.xml | 4 ++-- www/JMessagePlugin.js | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cd043d2..5e58a40 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/package.json b/package.json index ccc7f2f..2ca9acb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugin.xml b/plugin.xml index 42f716e..1e9c18a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.1.7"> JMessage 集成极光 IM 和推送功能 @@ -161,6 +161,6 @@ - + diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index 26506da..e9d8edd 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -878,6 +878,7 @@ var JMessagePlugin = { }, /** * 离开聊天室。 + * 成功调用此接口之后,用户将能不在此聊天室收发消息。 * * @param {object} params = { roomId: String } * @param {function} success = function () {}