juggleim-rnsdk 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/juggleim-rnsdk.podspec +1 -1
- package/package.json +1 -1
- package/src/index.js +55 -10
- package/src/types.d.ts +16 -0
package/juggleim-rnsdk.podspec
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -152,9 +152,10 @@ class JuggleIM {
|
|
|
152
152
|
if (listener.onMessageReceive) {
|
|
153
153
|
const subscription = juggleIMEmitter.addListener(
|
|
154
154
|
"MessageReceived",
|
|
155
|
-
(event) => {
|
|
155
|
+
async (event) => {
|
|
156
|
+
const message = await this.buildMessageInfo(event.message);
|
|
156
157
|
if (Platform.OS === "android" && event.key !== key) return;
|
|
157
|
-
listener.onMessageReceive(
|
|
158
|
+
listener.onMessageReceive(message);
|
|
158
159
|
}
|
|
159
160
|
);
|
|
160
161
|
subscriptions.push(subscription);
|
|
@@ -356,8 +357,10 @@ class JuggleIM {
|
|
|
356
357
|
const subscription = juggleIMEmitter.addListener(
|
|
357
358
|
"ConversationInfoAdded",
|
|
358
359
|
(event) => {
|
|
360
|
+
const convsList = this.buildConversationInfoList(event.conversations);
|
|
361
|
+
console.log("ConversationInfoAdded", convsList);
|
|
359
362
|
if (Platform.OS === "android" && event.key !== key) return;
|
|
360
|
-
listener.onConversationInfoAdd(
|
|
363
|
+
listener.onConversationInfoAdd(convsList);
|
|
361
364
|
}
|
|
362
365
|
);
|
|
363
366
|
subscriptions.push(subscription);
|
|
@@ -368,8 +371,10 @@ class JuggleIM {
|
|
|
368
371
|
const subscription = juggleIMEmitter.addListener(
|
|
369
372
|
"ConversationInfoUpdated",
|
|
370
373
|
(event) => {
|
|
374
|
+
const convsList = this.buildConversationInfoList(event.conversations);
|
|
375
|
+
console.log("ConversationInfoUpdated", convsList);
|
|
371
376
|
if (Platform.OS === "android" && event.key !== key) return;
|
|
372
|
-
listener.onConversationInfoUpdate(
|
|
377
|
+
listener.onConversationInfoUpdate(convsList);
|
|
373
378
|
}
|
|
374
379
|
);
|
|
375
380
|
subscriptions.push(subscription);
|
|
@@ -380,8 +385,10 @@ class JuggleIM {
|
|
|
380
385
|
const subscription = juggleIMEmitter.addListener(
|
|
381
386
|
"ConversationInfoDeleted",
|
|
382
387
|
(event) => {
|
|
388
|
+
const convsList = this.buildConversationInfoList(event.conversations);
|
|
389
|
+
console.log("ConversationInfoDeleted", convsList);
|
|
383
390
|
if (Platform.OS === "android" && event.key !== key) return;
|
|
384
|
-
listener.onConversationInfoDelete(
|
|
391
|
+
listener.onConversationInfoDelete(convsList);
|
|
385
392
|
}
|
|
386
393
|
);
|
|
387
394
|
subscriptions.push(subscription);
|
|
@@ -444,6 +451,37 @@ class JuggleIM {
|
|
|
444
451
|
});
|
|
445
452
|
}
|
|
446
453
|
|
|
454
|
+
static buildConversationInfoList(convs) {
|
|
455
|
+
convs?.forEach(async (conv) => {
|
|
456
|
+
if (conv.conversation?.conversationType === 1) {
|
|
457
|
+
const userInfo = await JMI.getUserInfo(conv.conversation?.conversationId);
|
|
458
|
+
conv.name = userInfo?.nickname;
|
|
459
|
+
conv.avatar = userInfo?.avatar;
|
|
460
|
+
conv.extra = userInfo?.extra;
|
|
461
|
+
} else if (conv.conversation?.conversationType === 2) {
|
|
462
|
+
const groupInfo = await JMI.getGroupInfo(conv.conversation?.conversationId);
|
|
463
|
+
conv.name = groupInfo?.groupName;
|
|
464
|
+
conv.avatar = groupInfo?.portrait;
|
|
465
|
+
conv.extra = groupInfo?.extra;
|
|
466
|
+
}
|
|
467
|
+
if (conv.lastMessage) {
|
|
468
|
+
const userInfo = await JMI.getUserInfo(conv.lastMessage.senderUserId);
|
|
469
|
+
conv.lastMessage.senderUserName = userInfo?.nickname;
|
|
470
|
+
conv.lastMessage.senderUserAvatar = userInfo?.avatar;
|
|
471
|
+
conv.lastMessage.senderUserExtra = userInfo?.extra;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
return convs;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
static async buildMessageInfo(message) {
|
|
478
|
+
const userInfo = await JMI.getUserInfo(message.senderUserId);
|
|
479
|
+
message.senderUserName = userInfo?.nickname;
|
|
480
|
+
message.senderUserAvatar = userInfo?.avatar;
|
|
481
|
+
message.senderUserExtra = userInfo?.extra;
|
|
482
|
+
return message;
|
|
483
|
+
}
|
|
484
|
+
|
|
447
485
|
/**
|
|
448
486
|
* 获取单个会话信息
|
|
449
487
|
* @param {object} conversation - 会话对象
|
|
@@ -571,11 +609,18 @@ class JuggleIM {
|
|
|
571
609
|
* @returns {Promise<boolean>} 清除结果
|
|
572
610
|
*/
|
|
573
611
|
static clearUnreadCount(conversation) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
612
|
+
// 参数检查
|
|
613
|
+
return new Promise((resolve, reject) => {
|
|
614
|
+
if (!conversation || !conversation.conversationId || !conversation.conversationType) {
|
|
615
|
+
reject('error', '会话参数错误');
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (Platform.OS === "android") {
|
|
619
|
+
JMI.clearUnreadCount(conversation).then(resolve).catch(reject);
|
|
620
|
+
} else if (Platform.OS === "ios") {
|
|
621
|
+
JMI.clearUnreadCount(conversation).then(resolve).catch(reject);
|
|
622
|
+
}
|
|
623
|
+
});
|
|
579
624
|
}
|
|
580
625
|
|
|
581
626
|
/**
|
package/src/types.d.ts
CHANGED
|
@@ -448,6 +448,22 @@ export interface SendMessageObject {
|
|
|
448
448
|
}
|
|
449
449
|
/**
|
|
450
450
|
* 连接状态监听器回调函数
|
|
451
|
+
* @param {ConnectionStatus} status - 连接状态
|
|
452
|
+
* @param {number} code - 状态码
|
|
453
|
+
* 0: CONNECT_SUCCESS 链接成功
|
|
454
|
+
* 11000: CONNECT_ERROR 默认错误
|
|
455
|
+
* 11001: CONNECT_APPKEY_IS_REQUIRE 未传 Appkey
|
|
456
|
+
* 11002: CONNECT_TOKEN_NOT_EXISTS 未传 Token
|
|
457
|
+
* 11003: CONNECT_APPKEY_NOT_EXISTS Appkey 不存在
|
|
458
|
+
* 11004: CONNECT_TOKEN_ILLEGAL Token 不合法
|
|
459
|
+
* 11005: CONNECT_TOKEN_UNAUTHORIZED Token 未授权
|
|
460
|
+
* 11006: CONNECT_TOKEN_EXPIRE Token 已过期
|
|
461
|
+
* 11008: CONNECT_UNSUPPORT_PLATFORM 不支持的平台类型
|
|
462
|
+
* 11009: CONNECT_APP_BLOCKED App已封禁
|
|
463
|
+
* 11010: CONNECT_USER_BLOCKED 用户已封禁
|
|
464
|
+
* 11011: CONNECT_USER_KICKED 被踢下线
|
|
465
|
+
* 11012: CONNECT_USER_LOGOUT 注销下线
|
|
466
|
+
* @param {string} extra - 扩展信息
|
|
451
467
|
*/
|
|
452
468
|
export type ConnectionStatusListener = (
|
|
453
469
|
status: ConnectionStatus,
|