@onyx-p/imlib-web 2.1.1 → 2.1.3
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/index.esm.js +132 -54
- package/index.umd.js +132 -54
- package/package.json +1 -1
- package/types/model/iReceivedConversation.d.ts +1 -1
- package/types/types.d.ts +2 -1
package/index.esm.js
CHANGED
@@ -19665,6 +19665,10 @@ const ConversationKey2StorageKey = {
|
|
19665
19665
|
burnAfterReadingTime: {
|
19666
19666
|
keyName: 'brt',
|
19667
19667
|
defaultVal: 0
|
19668
|
+
},
|
19669
|
+
updateTime: {
|
19670
|
+
keyName: 'ut',
|
19671
|
+
defaultVal: 0
|
19668
19672
|
}
|
19669
19673
|
};
|
19670
19674
|
class ConversationStore {
|
@@ -19771,6 +19775,12 @@ class ConversationStore {
|
|
19771
19775
|
this.localStore.remove(key);
|
19772
19776
|
}
|
19773
19777
|
}
|
19778
|
+
updateUpdateTime(conOpt, updateTime) {
|
19779
|
+
const key = this.getStoreKey(conOpt);
|
19780
|
+
const local = this.localStore.get(key) || {};
|
19781
|
+
local[ConversationKey2StorageKey.updateTime.keyName] = updateTime;
|
19782
|
+
this.localStore.set(key, local);
|
19783
|
+
}
|
19774
19784
|
set(conOpt, conversation) {
|
19775
19785
|
const key = this.getStoreKey(conOpt);
|
19776
19786
|
const local = this.localStore.get(key) || {};
|
@@ -19992,7 +20002,8 @@ class ConversationManager {
|
|
19992
20002
|
dialogTitle,
|
19993
20003
|
smallAvatarUrl,
|
19994
20004
|
burnAfterReadingFlag,
|
19995
|
-
burnAfterReadingTime
|
20005
|
+
burnAfterReadingTime,
|
20006
|
+
updateTime
|
19996
20007
|
} = conversation;
|
19997
20008
|
this.localConversationSet.add(this.getConversationKey(conversation));
|
19998
20009
|
this.addStatus({
|
@@ -20004,7 +20015,8 @@ class ConversationManager {
|
|
20004
20015
|
dialogTitle,
|
20005
20016
|
smallAvatarUrl,
|
20006
20017
|
burnAfterReadingFlag,
|
20007
|
-
burnAfterReadingTime
|
20018
|
+
burnAfterReadingTime,
|
20019
|
+
updateTime
|
20008
20020
|
}, false);
|
20009
20021
|
}
|
20010
20022
|
addStatus(statusItem, shouldNotify = false) {
|
@@ -20017,13 +20029,14 @@ class ConversationManager {
|
|
20017
20029
|
dialogTitle,
|
20018
20030
|
smallAvatarUrl,
|
20019
20031
|
burnAfterReadingFlag,
|
20020
|
-
burnAfterReadingTime
|
20032
|
+
burnAfterReadingTime,
|
20033
|
+
updateTime
|
20021
20034
|
} = statusItem;
|
20022
20035
|
const conOpt = {
|
20023
20036
|
conversationType,
|
20024
20037
|
targetId
|
20025
20038
|
};
|
20026
|
-
const updatedTime = getServerTime$1()
|
20039
|
+
const updatedTime = getServerTime$1();
|
20027
20040
|
const storageConversation = this.store.get(conOpt);
|
20028
20041
|
const updatedItems = {};
|
20029
20042
|
if (isDef(notificationLevel) && storageConversation.notificationLevel !== notificationLevel) {
|
@@ -20075,7 +20088,8 @@ class ConversationManager {
|
|
20075
20088
|
dialogTitle,
|
20076
20089
|
smallAvatarUrl,
|
20077
20090
|
burnAfterReadingFlag,
|
20078
|
-
burnAfterReadingTime
|
20091
|
+
burnAfterReadingTime,
|
20092
|
+
updateTime
|
20079
20093
|
});
|
20080
20094
|
if (Object.keys(updatedItems).length && shouldNotify) {
|
20081
20095
|
this.setUpdatedConversation({
|
@@ -20101,22 +20115,23 @@ class ConversationManager {
|
|
20101
20115
|
const oldLocalConversation = deepClone(this.get(conOpt));
|
20102
20116
|
this.store.updateUnreadCount(message);
|
20103
20117
|
this.store.updateMentionedData(message);
|
20118
|
+
this.store.updateUpdateTime(conOpt, parseInt(message.sentTime));
|
20104
20119
|
const newLocalConversation = this.get(conOpt);
|
20105
20120
|
if (oldLocalConversation.unreadMessageCount !== newLocalConversation.unreadMessageCount) {
|
20106
20121
|
updateConOptions.updatedItems.unreadMessageCount = {
|
20107
|
-
time: message.sentTime,
|
20122
|
+
time: parseInt(message.sentTime),
|
20108
20123
|
val: newLocalConversation.unreadMessageCount
|
20109
20124
|
};
|
20110
20125
|
}
|
20111
20126
|
if (oldLocalConversation.hasMentioned !== newLocalConversation.hasMentioned) {
|
20112
20127
|
updateConOptions.updatedItems.hasMentioned = {
|
20113
|
-
time: message.sentTime,
|
20128
|
+
time: parseInt(message.sentTime),
|
20114
20129
|
val: newLocalConversation.hasMentioned
|
20115
20130
|
};
|
20116
20131
|
}
|
20117
20132
|
if (oldLocalConversation.unreadMentionedCount !== newLocalConversation.unreadMentionedCount) {
|
20118
20133
|
updateConOptions.updatedItems.unreadMentionedCount = {
|
20119
|
-
time: message.sentTime,
|
20134
|
+
time: parseInt(message.sentTime),
|
20120
20135
|
val: newLocalConversation.unreadMentionedCount
|
20121
20136
|
};
|
20122
20137
|
}
|
@@ -20124,7 +20139,7 @@ class ConversationManager {
|
|
20124
20139
|
updateConOptions.conversation.updateTime = parseInt(message.sentTime);
|
20125
20140
|
updateConOptions.conversation.latestMessage = message;
|
20126
20141
|
updateConOptions.updatedItems.latestMessage = {
|
20127
|
-
time: message.sentTime,
|
20142
|
+
time: parseInt(message.sentTime),
|
20128
20143
|
val: message
|
20129
20144
|
};
|
20130
20145
|
}
|
@@ -20261,7 +20276,8 @@ class ConversationManager {
|
|
20261
20276
|
notificationStatus,
|
20262
20277
|
isTop,
|
20263
20278
|
dialogTitle,
|
20264
|
-
smallAvatarUrl
|
20279
|
+
smallAvatarUrl,
|
20280
|
+
updateTime
|
20265
20281
|
} = val;
|
20266
20282
|
return {
|
20267
20283
|
...conOpt,
|
@@ -20271,7 +20287,8 @@ class ConversationManager {
|
|
20271
20287
|
notificationStatus,
|
20272
20288
|
isTop,
|
20273
20289
|
dialogTitle,
|
20274
|
-
smallAvatarUrl
|
20290
|
+
smallAvatarUrl,
|
20291
|
+
updateTime: updateTime
|
20275
20292
|
};
|
20276
20293
|
}
|
20277
20294
|
return null;
|
@@ -20287,7 +20304,8 @@ class ConversationManager {
|
|
20287
20304
|
notificationStatus,
|
20288
20305
|
isTop,
|
20289
20306
|
dialogTitle,
|
20290
|
-
smallAvatarUrl
|
20307
|
+
smallAvatarUrl,
|
20308
|
+
updateTime
|
20291
20309
|
}) => ({
|
20292
20310
|
conversationType,
|
20293
20311
|
targetId,
|
@@ -20297,7 +20315,8 @@ class ConversationManager {
|
|
20297
20315
|
notificationStatus,
|
20298
20316
|
isTop,
|
20299
20317
|
dialogTitle,
|
20300
|
-
smallAvatarUrl
|
20318
|
+
smallAvatarUrl,
|
20319
|
+
updateTime: updateTime
|
20301
20320
|
}));
|
20302
20321
|
}
|
20303
20322
|
remove(conOpt) {
|
@@ -20313,19 +20332,27 @@ class ConversationManager {
|
|
20313
20332
|
updateConOptions.conversation.latestMessage = undefined;
|
20314
20333
|
updateConOptions.updatedItems.latestMessage = {
|
20315
20334
|
val: null,
|
20316
|
-
time: getServerTime$1()
|
20335
|
+
time: getServerTime$1()
|
20317
20336
|
};
|
20318
20337
|
this.setUpdatedConversation(updateConOptions);
|
20319
20338
|
}
|
20320
|
-
|
20339
|
+
updateLatestMessage(conOpt, message) {
|
20340
|
+
if (isDef(message)) {
|
20341
|
+
this.store.set(conOpt, {
|
20342
|
+
updateTime: parseInt(message.sentTime)
|
20343
|
+
});
|
20344
|
+
}
|
20321
20345
|
const updateConOptions = {
|
20322
20346
|
conversation: conOpt,
|
20323
20347
|
updatedItems: {}
|
20324
20348
|
};
|
20349
|
+
if (isDef(message)) {
|
20350
|
+
updateConOptions.conversation.updateTime = parseInt(message.sentTime);
|
20351
|
+
}
|
20325
20352
|
updateConOptions.conversation.latestMessage = message;
|
20326
20353
|
updateConOptions.updatedItems.latestMessage = {
|
20327
20354
|
val: message,
|
20328
|
-
time:
|
20355
|
+
time: getServerTime$1()
|
20329
20356
|
};
|
20330
20357
|
this.setUpdatedConversation(updateConOptions);
|
20331
20358
|
}
|
@@ -20336,6 +20363,7 @@ class ConversationManager {
|
|
20336
20363
|
const nullConversationManager = {
|
20337
20364
|
addStatus: function (statusItem, shouldNotify) {},
|
20338
20365
|
setConversationCacheByMessage: function (message) {},
|
20366
|
+
updateLatestMessage: function (conOpt, message) {},
|
20339
20367
|
get: function (conOpt) {
|
20340
20368
|
return null;
|
20341
20369
|
},
|
@@ -20383,8 +20411,7 @@ const nullConversationManager = {
|
|
20383
20411
|
destroyed() {},
|
20384
20412
|
syncConversationStatus: function () {},
|
20385
20413
|
remove: function (conOpt) {},
|
20386
|
-
clearHistoryMessages: function (conOpt) {}
|
20387
|
-
refreshLatestMessage: function (conOpt, message) {}
|
20414
|
+
clearHistoryMessages: function (conOpt) {}
|
20388
20415
|
};
|
20389
20416
|
let manager$1;
|
20390
20417
|
var ConversationManager$1 = {
|
@@ -21544,6 +21571,43 @@ class MessageCache {
|
|
21544
21571
|
await this.checkAndResetDatabase();
|
21545
21572
|
await this.initDatabase();
|
21546
21573
|
}
|
21574
|
+
async getLatestMessage(conversation) {
|
21575
|
+
const dialogId = getFullDialogId(conversation);
|
21576
|
+
if (!this.db) {
|
21577
|
+
return null;
|
21578
|
+
}
|
21579
|
+
return new Promise((resolve, reject) => {
|
21580
|
+
const transaction = this.db.transaction(this.STORE_NAME, 'readonly');
|
21581
|
+
const store = transaction.objectStore(this.STORE_NAME);
|
21582
|
+
const index = store.index('dialogId_sentTime');
|
21583
|
+
const range = IDBKeyRange.bound([dialogId, ''], [dialogId, '\uffff']);
|
21584
|
+
const direction = 'prev';
|
21585
|
+
const cursorRequest = index.openCursor(range, direction);
|
21586
|
+
cursorRequest.onsuccess = event => {
|
21587
|
+
const cursor = event.target.result;
|
21588
|
+
if (cursor) {
|
21589
|
+
const message = {
|
21590
|
+
...cursor.value
|
21591
|
+
};
|
21592
|
+
if (typeof message.content === 'string' && message.content) {
|
21593
|
+
try {
|
21594
|
+
message.content = this.decryptContent(message.content);
|
21595
|
+
} catch (error) {
|
21596
|
+
console.error('解密消息内容失败', error);
|
21597
|
+
message.content = null;
|
21598
|
+
}
|
21599
|
+
}
|
21600
|
+
resolve(message);
|
21601
|
+
} else {
|
21602
|
+
resolve(null);
|
21603
|
+
}
|
21604
|
+
};
|
21605
|
+
cursorRequest.onerror = event => {
|
21606
|
+
console.error('获取最新消息失败', event);
|
21607
|
+
reject(new Error('获取最新消息失败'));
|
21608
|
+
};
|
21609
|
+
});
|
21610
|
+
}
|
21547
21611
|
}
|
21548
21612
|
let cache;
|
21549
21613
|
var MessageCache$1 = {
|
@@ -29155,10 +29219,9 @@ class IMClient extends EventEmitter {
|
|
29155
29219
|
});
|
29156
29220
|
}
|
29157
29221
|
async getPreviousHistoryMessages(conversation, timestamp, count = 20) {
|
29158
|
-
debugger;
|
29159
29222
|
const cachedResult = await MessageCache$1.get().getPreviousMessages(conversation, timestamp ?? '0', count);
|
29160
29223
|
if (!timestamp && cachedResult.messages.length) {
|
29161
|
-
ConversationManager$1.get().
|
29224
|
+
ConversationManager$1.get().updateLatestMessage(conversation, cachedResult.messages[cachedResult.messages.length - 1]);
|
29162
29225
|
}
|
29163
29226
|
if (cachedResult.messages.length >= count || !cachedResult.hasMore) {
|
29164
29227
|
return {
|
@@ -29180,7 +29243,7 @@ class IMClient extends EventEmitter {
|
|
29180
29243
|
}
|
29181
29244
|
const remotesMessages = remotesResult.data.list;
|
29182
29245
|
if (!remotesTimestamp) {
|
29183
|
-
ConversationManager$1.get().
|
29246
|
+
ConversationManager$1.get().updateLatestMessage(conversation, remotesMessages[remotesMessages.length - 1]);
|
29184
29247
|
}
|
29185
29248
|
MessageCache$1.get().addMessages(remotesMessages, conversation, !remotesResult.data.hasMore);
|
29186
29249
|
return {
|
@@ -29192,10 +29255,19 @@ class IMClient extends EventEmitter {
|
|
29192
29255
|
};
|
29193
29256
|
}
|
29194
29257
|
async deleteRemoteMessage(conversation, list) {
|
29195
|
-
|
29196
|
-
|
29258
|
+
debugger;
|
29259
|
+
const result = await deleteMessages$1(getFullDialogId(conversation), list.map(e => e.messageUId)).then(result => result.code);
|
29260
|
+
if (result === ErrorCode.SUCCESS) {
|
29261
|
+
const latestMessage = await MessageCache$1.get()?.getLatestMessage(conversation);
|
29262
|
+
await MessageCache$1.get()?.removeMessagesByUId(list.map(e => e.messageUId));
|
29263
|
+
if (latestMessage && list.some(e => e.messageUId === latestMessage.messageUId)) {
|
29264
|
+
const latestMessage2 = await MessageCache$1.get()?.getLatestMessage(conversation);
|
29265
|
+
ConversationManager$1.get().updateLatestMessage(conversation, latestMessage2);
|
29266
|
+
}
|
29267
|
+
}
|
29268
|
+
return result;
|
29197
29269
|
}
|
29198
|
-
async
|
29270
|
+
async deleteHistoryMessages(conversation) {
|
29199
29271
|
MessageCache$1.get()?.clearConversationCache(conversation);
|
29200
29272
|
ConversationManager$1.get().clearHistoryMessages(conversation);
|
29201
29273
|
return clearHistoryMessage(getFullDialogId(conversation)).then(result => result.code);
|
@@ -29221,22 +29293,30 @@ class IMClient extends EventEmitter {
|
|
29221
29293
|
const contentList = [];
|
29222
29294
|
for (const dialogInfo of data.fullDialog) {
|
29223
29295
|
const conversationObj = this.formatConversation(dialogInfo);
|
29224
|
-
if (conversationObj) {
|
29225
|
-
|
29226
|
-
|
29227
|
-
|
29228
|
-
|
29229
|
-
|
29230
|
-
|
29231
|
-
|
29232
|
-
|
29233
|
-
}
|
29234
|
-
ConversationManager$1.get().addLocalConversation(conversationObj);
|
29235
|
-
const localConversation = ConversationManager$1.get().get(conOpt);
|
29236
|
-
Object.assign(conversationObj, localConversation);
|
29237
|
-
contentList.push(conversationObj);
|
29296
|
+
if (!conversationObj) {
|
29297
|
+
continue;
|
29298
|
+
}
|
29299
|
+
const conOpt = {
|
29300
|
+
conversationType: conversationObj.conversationType,
|
29301
|
+
targetId: conversationObj.targetId
|
29302
|
+
};
|
29303
|
+
if (!conversationObj.latestMessage) {
|
29304
|
+
conversationObj.latestMessage = await MessageCache$1.get()?.getLatestMessage(conOpt);
|
29238
29305
|
}
|
29306
|
+
ConversationManager$1.get().addLocalConversation(conversationObj);
|
29307
|
+
const localConversation = ConversationManager$1.get().get(conOpt);
|
29308
|
+
Object.assign(conversationObj, localConversation);
|
29309
|
+
if (isDef(conversationObj.latestMessage) && !conversationObj.updateTime) {
|
29310
|
+
conversationObj.updateTime = parseInt(conversationObj.latestMessage.sentTime);
|
29311
|
+
}
|
29312
|
+
if (!conversationObj.updateTime) {
|
29313
|
+
conversationObj.updateTime = 10000;
|
29314
|
+
}
|
29315
|
+
contentList.push(conversationObj);
|
29239
29316
|
}
|
29317
|
+
contentList.sort((a, b) => {
|
29318
|
+
return (a.updateTime ?? 0) - (b.updateTime ?? 0);
|
29319
|
+
});
|
29240
29320
|
return {
|
29241
29321
|
code: ErrorCode.SUCCESS,
|
29242
29322
|
data: contentList
|
@@ -29263,19 +29343,7 @@ class IMClient extends EventEmitter {
|
|
29263
29343
|
code: ErrorCode.CONVER_GET_ERROR
|
29264
29344
|
};
|
29265
29345
|
}
|
29266
|
-
const
|
29267
|
-
code,
|
29268
|
-
data
|
29269
|
-
} = await this.getRemoteHistoryMessages(conOpt, {
|
29270
|
-
count: 1,
|
29271
|
-
order: 0
|
29272
|
-
});
|
29273
|
-
if (code !== ErrorCode.SUCCESS) {
|
29274
|
-
return {
|
29275
|
-
code: ErrorCode.CONVER_GET_ERROR
|
29276
|
-
};
|
29277
|
-
}
|
29278
|
-
const latestMessage = data?.list[0];
|
29346
|
+
const latestMessage = await MessageCache$1.get()?.getLatestMessage(conOpt);
|
29279
29347
|
const conversation = {
|
29280
29348
|
...conOpt,
|
29281
29349
|
...localConversation,
|
@@ -29381,8 +29449,18 @@ class IMClient extends EventEmitter {
|
|
29381
29449
|
}
|
29382
29450
|
return conversationObj;
|
29383
29451
|
}
|
29384
|
-
clearBurnAfterReadingExpiredMessages(conversation) {
|
29385
|
-
|
29452
|
+
async clearBurnAfterReadingExpiredMessages(conversation) {
|
29453
|
+
const cache = MessageCache$1.get();
|
29454
|
+
if (!cache) {
|
29455
|
+
return Promise.resolve([]);
|
29456
|
+
}
|
29457
|
+
const latestMessage = await cache.getLatestMessage(conversation);
|
29458
|
+
const removedMsgUids = await cache.clearBurnAfterReadingExpiredMessages(conversation);
|
29459
|
+
if (latestMessage && removedMsgUids.includes(latestMessage.messageUId)) {
|
29460
|
+
const latestMessage2 = await cache.getLatestMessage(conversation);
|
29461
|
+
ConversationManager$1.get().updateLatestMessage(conversation, latestMessage2);
|
29462
|
+
}
|
29463
|
+
return removedMsgUids;
|
29386
29464
|
}
|
29387
29465
|
}
|
29388
29466
|
|
@@ -30602,7 +30680,7 @@ const clearHistoryMessages = async conversation => {
|
|
30602
30680
|
assert('conversation', conversation, AssertRules.CONVERSATION);
|
30603
30681
|
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
30604
30682
|
logger.debug('clear message ->' + paramsStr);
|
30605
|
-
const code = await imClient.
|
30683
|
+
const code = await imClient.deleteHistoryMessages(conversation);
|
30606
30684
|
if (code !== ErrorCode.SUCCESS) {
|
30607
30685
|
logger.warn('clear message ->' + code + ':' + ErrorDesc(code) + ',' + paramsStr);
|
30608
30686
|
return {
|
package/index.umd.js
CHANGED
@@ -19671,6 +19671,10 @@
|
|
19671
19671
|
burnAfterReadingTime: {
|
19672
19672
|
keyName: 'brt',
|
19673
19673
|
defaultVal: 0
|
19674
|
+
},
|
19675
|
+
updateTime: {
|
19676
|
+
keyName: 'ut',
|
19677
|
+
defaultVal: 0
|
19674
19678
|
}
|
19675
19679
|
};
|
19676
19680
|
class ConversationStore {
|
@@ -19777,6 +19781,12 @@
|
|
19777
19781
|
this.localStore.remove(key);
|
19778
19782
|
}
|
19779
19783
|
}
|
19784
|
+
updateUpdateTime(conOpt, updateTime) {
|
19785
|
+
const key = this.getStoreKey(conOpt);
|
19786
|
+
const local = this.localStore.get(key) || {};
|
19787
|
+
local[ConversationKey2StorageKey.updateTime.keyName] = updateTime;
|
19788
|
+
this.localStore.set(key, local);
|
19789
|
+
}
|
19780
19790
|
set(conOpt, conversation) {
|
19781
19791
|
const key = this.getStoreKey(conOpt);
|
19782
19792
|
const local = this.localStore.get(key) || {};
|
@@ -19998,7 +20008,8 @@
|
|
19998
20008
|
dialogTitle,
|
19999
20009
|
smallAvatarUrl,
|
20000
20010
|
burnAfterReadingFlag,
|
20001
|
-
burnAfterReadingTime
|
20011
|
+
burnAfterReadingTime,
|
20012
|
+
updateTime
|
20002
20013
|
} = conversation;
|
20003
20014
|
this.localConversationSet.add(this.getConversationKey(conversation));
|
20004
20015
|
this.addStatus({
|
@@ -20010,7 +20021,8 @@
|
|
20010
20021
|
dialogTitle,
|
20011
20022
|
smallAvatarUrl,
|
20012
20023
|
burnAfterReadingFlag,
|
20013
|
-
burnAfterReadingTime
|
20024
|
+
burnAfterReadingTime,
|
20025
|
+
updateTime
|
20014
20026
|
}, false);
|
20015
20027
|
}
|
20016
20028
|
addStatus(statusItem, shouldNotify = false) {
|
@@ -20023,13 +20035,14 @@
|
|
20023
20035
|
dialogTitle,
|
20024
20036
|
smallAvatarUrl,
|
20025
20037
|
burnAfterReadingFlag,
|
20026
|
-
burnAfterReadingTime
|
20038
|
+
burnAfterReadingTime,
|
20039
|
+
updateTime
|
20027
20040
|
} = statusItem;
|
20028
20041
|
const conOpt = {
|
20029
20042
|
conversationType,
|
20030
20043
|
targetId
|
20031
20044
|
};
|
20032
|
-
const updatedTime = getServerTime$1()
|
20045
|
+
const updatedTime = getServerTime$1();
|
20033
20046
|
const storageConversation = this.store.get(conOpt);
|
20034
20047
|
const updatedItems = {};
|
20035
20048
|
if (isDef(notificationLevel) && storageConversation.notificationLevel !== notificationLevel) {
|
@@ -20081,7 +20094,8 @@
|
|
20081
20094
|
dialogTitle,
|
20082
20095
|
smallAvatarUrl,
|
20083
20096
|
burnAfterReadingFlag,
|
20084
|
-
burnAfterReadingTime
|
20097
|
+
burnAfterReadingTime,
|
20098
|
+
updateTime
|
20085
20099
|
});
|
20086
20100
|
if (Object.keys(updatedItems).length && shouldNotify) {
|
20087
20101
|
this.setUpdatedConversation({
|
@@ -20107,22 +20121,23 @@
|
|
20107
20121
|
const oldLocalConversation = deepClone(this.get(conOpt));
|
20108
20122
|
this.store.updateUnreadCount(message);
|
20109
20123
|
this.store.updateMentionedData(message);
|
20124
|
+
this.store.updateUpdateTime(conOpt, parseInt(message.sentTime));
|
20110
20125
|
const newLocalConversation = this.get(conOpt);
|
20111
20126
|
if (oldLocalConversation.unreadMessageCount !== newLocalConversation.unreadMessageCount) {
|
20112
20127
|
updateConOptions.updatedItems.unreadMessageCount = {
|
20113
|
-
time: message.sentTime,
|
20128
|
+
time: parseInt(message.sentTime),
|
20114
20129
|
val: newLocalConversation.unreadMessageCount
|
20115
20130
|
};
|
20116
20131
|
}
|
20117
20132
|
if (oldLocalConversation.hasMentioned !== newLocalConversation.hasMentioned) {
|
20118
20133
|
updateConOptions.updatedItems.hasMentioned = {
|
20119
|
-
time: message.sentTime,
|
20134
|
+
time: parseInt(message.sentTime),
|
20120
20135
|
val: newLocalConversation.hasMentioned
|
20121
20136
|
};
|
20122
20137
|
}
|
20123
20138
|
if (oldLocalConversation.unreadMentionedCount !== newLocalConversation.unreadMentionedCount) {
|
20124
20139
|
updateConOptions.updatedItems.unreadMentionedCount = {
|
20125
|
-
time: message.sentTime,
|
20140
|
+
time: parseInt(message.sentTime),
|
20126
20141
|
val: newLocalConversation.unreadMentionedCount
|
20127
20142
|
};
|
20128
20143
|
}
|
@@ -20130,7 +20145,7 @@
|
|
20130
20145
|
updateConOptions.conversation.updateTime = parseInt(message.sentTime);
|
20131
20146
|
updateConOptions.conversation.latestMessage = message;
|
20132
20147
|
updateConOptions.updatedItems.latestMessage = {
|
20133
|
-
time: message.sentTime,
|
20148
|
+
time: parseInt(message.sentTime),
|
20134
20149
|
val: message
|
20135
20150
|
};
|
20136
20151
|
}
|
@@ -20267,7 +20282,8 @@
|
|
20267
20282
|
notificationStatus,
|
20268
20283
|
isTop,
|
20269
20284
|
dialogTitle,
|
20270
|
-
smallAvatarUrl
|
20285
|
+
smallAvatarUrl,
|
20286
|
+
updateTime
|
20271
20287
|
} = val;
|
20272
20288
|
return {
|
20273
20289
|
...conOpt,
|
@@ -20277,7 +20293,8 @@
|
|
20277
20293
|
notificationStatus,
|
20278
20294
|
isTop,
|
20279
20295
|
dialogTitle,
|
20280
|
-
smallAvatarUrl
|
20296
|
+
smallAvatarUrl,
|
20297
|
+
updateTime: updateTime
|
20281
20298
|
};
|
20282
20299
|
}
|
20283
20300
|
return null;
|
@@ -20293,7 +20310,8 @@
|
|
20293
20310
|
notificationStatus,
|
20294
20311
|
isTop,
|
20295
20312
|
dialogTitle,
|
20296
|
-
smallAvatarUrl
|
20313
|
+
smallAvatarUrl,
|
20314
|
+
updateTime
|
20297
20315
|
}) => ({
|
20298
20316
|
conversationType,
|
20299
20317
|
targetId,
|
@@ -20303,7 +20321,8 @@
|
|
20303
20321
|
notificationStatus,
|
20304
20322
|
isTop,
|
20305
20323
|
dialogTitle,
|
20306
|
-
smallAvatarUrl
|
20324
|
+
smallAvatarUrl,
|
20325
|
+
updateTime: updateTime
|
20307
20326
|
}));
|
20308
20327
|
}
|
20309
20328
|
remove(conOpt) {
|
@@ -20319,19 +20338,27 @@
|
|
20319
20338
|
updateConOptions.conversation.latestMessage = undefined;
|
20320
20339
|
updateConOptions.updatedItems.latestMessage = {
|
20321
20340
|
val: null,
|
20322
|
-
time: getServerTime$1()
|
20341
|
+
time: getServerTime$1()
|
20323
20342
|
};
|
20324
20343
|
this.setUpdatedConversation(updateConOptions);
|
20325
20344
|
}
|
20326
|
-
|
20345
|
+
updateLatestMessage(conOpt, message) {
|
20346
|
+
if (isDef(message)) {
|
20347
|
+
this.store.set(conOpt, {
|
20348
|
+
updateTime: parseInt(message.sentTime)
|
20349
|
+
});
|
20350
|
+
}
|
20327
20351
|
const updateConOptions = {
|
20328
20352
|
conversation: conOpt,
|
20329
20353
|
updatedItems: {}
|
20330
20354
|
};
|
20355
|
+
if (isDef(message)) {
|
20356
|
+
updateConOptions.conversation.updateTime = parseInt(message.sentTime);
|
20357
|
+
}
|
20331
20358
|
updateConOptions.conversation.latestMessage = message;
|
20332
20359
|
updateConOptions.updatedItems.latestMessage = {
|
20333
20360
|
val: message,
|
20334
|
-
time:
|
20361
|
+
time: getServerTime$1()
|
20335
20362
|
};
|
20336
20363
|
this.setUpdatedConversation(updateConOptions);
|
20337
20364
|
}
|
@@ -20342,6 +20369,7 @@
|
|
20342
20369
|
const nullConversationManager = {
|
20343
20370
|
addStatus: function (statusItem, shouldNotify) {},
|
20344
20371
|
setConversationCacheByMessage: function (message) {},
|
20372
|
+
updateLatestMessage: function (conOpt, message) {},
|
20345
20373
|
get: function (conOpt) {
|
20346
20374
|
return null;
|
20347
20375
|
},
|
@@ -20389,8 +20417,7 @@
|
|
20389
20417
|
destroyed() {},
|
20390
20418
|
syncConversationStatus: function () {},
|
20391
20419
|
remove: function (conOpt) {},
|
20392
|
-
clearHistoryMessages: function (conOpt) {}
|
20393
|
-
refreshLatestMessage: function (conOpt, message) {}
|
20420
|
+
clearHistoryMessages: function (conOpt) {}
|
20394
20421
|
};
|
20395
20422
|
let manager$1;
|
20396
20423
|
var ConversationManager$1 = {
|
@@ -21550,6 +21577,43 @@
|
|
21550
21577
|
await this.checkAndResetDatabase();
|
21551
21578
|
await this.initDatabase();
|
21552
21579
|
}
|
21580
|
+
async getLatestMessage(conversation) {
|
21581
|
+
const dialogId = getFullDialogId(conversation);
|
21582
|
+
if (!this.db) {
|
21583
|
+
return null;
|
21584
|
+
}
|
21585
|
+
return new Promise((resolve, reject) => {
|
21586
|
+
const transaction = this.db.transaction(this.STORE_NAME, 'readonly');
|
21587
|
+
const store = transaction.objectStore(this.STORE_NAME);
|
21588
|
+
const index = store.index('dialogId_sentTime');
|
21589
|
+
const range = IDBKeyRange.bound([dialogId, ''], [dialogId, '\uffff']);
|
21590
|
+
const direction = 'prev';
|
21591
|
+
const cursorRequest = index.openCursor(range, direction);
|
21592
|
+
cursorRequest.onsuccess = event => {
|
21593
|
+
const cursor = event.target.result;
|
21594
|
+
if (cursor) {
|
21595
|
+
const message = {
|
21596
|
+
...cursor.value
|
21597
|
+
};
|
21598
|
+
if (typeof message.content === 'string' && message.content) {
|
21599
|
+
try {
|
21600
|
+
message.content = this.decryptContent(message.content);
|
21601
|
+
} catch (error) {
|
21602
|
+
console.error('解密消息内容失败', error);
|
21603
|
+
message.content = null;
|
21604
|
+
}
|
21605
|
+
}
|
21606
|
+
resolve(message);
|
21607
|
+
} else {
|
21608
|
+
resolve(null);
|
21609
|
+
}
|
21610
|
+
};
|
21611
|
+
cursorRequest.onerror = event => {
|
21612
|
+
console.error('获取最新消息失败', event);
|
21613
|
+
reject(new Error('获取最新消息失败'));
|
21614
|
+
};
|
21615
|
+
});
|
21616
|
+
}
|
21553
21617
|
}
|
21554
21618
|
let cache;
|
21555
21619
|
var MessageCache$1 = {
|
@@ -29161,10 +29225,9 @@
|
|
29161
29225
|
});
|
29162
29226
|
}
|
29163
29227
|
async getPreviousHistoryMessages(conversation, timestamp, count = 20) {
|
29164
|
-
debugger;
|
29165
29228
|
const cachedResult = await MessageCache$1.get().getPreviousMessages(conversation, timestamp ?? '0', count);
|
29166
29229
|
if (!timestamp && cachedResult.messages.length) {
|
29167
|
-
ConversationManager$1.get().
|
29230
|
+
ConversationManager$1.get().updateLatestMessage(conversation, cachedResult.messages[cachedResult.messages.length - 1]);
|
29168
29231
|
}
|
29169
29232
|
if (cachedResult.messages.length >= count || !cachedResult.hasMore) {
|
29170
29233
|
return {
|
@@ -29186,7 +29249,7 @@
|
|
29186
29249
|
}
|
29187
29250
|
const remotesMessages = remotesResult.data.list;
|
29188
29251
|
if (!remotesTimestamp) {
|
29189
|
-
ConversationManager$1.get().
|
29252
|
+
ConversationManager$1.get().updateLatestMessage(conversation, remotesMessages[remotesMessages.length - 1]);
|
29190
29253
|
}
|
29191
29254
|
MessageCache$1.get().addMessages(remotesMessages, conversation, !remotesResult.data.hasMore);
|
29192
29255
|
return {
|
@@ -29198,10 +29261,19 @@
|
|
29198
29261
|
};
|
29199
29262
|
}
|
29200
29263
|
async deleteRemoteMessage(conversation, list) {
|
29201
|
-
|
29202
|
-
|
29264
|
+
debugger;
|
29265
|
+
const result = await deleteMessages$1(getFullDialogId(conversation), list.map(e => e.messageUId)).then(result => result.code);
|
29266
|
+
if (result === exports.ErrorCode.SUCCESS) {
|
29267
|
+
const latestMessage = await MessageCache$1.get()?.getLatestMessage(conversation);
|
29268
|
+
await MessageCache$1.get()?.removeMessagesByUId(list.map(e => e.messageUId));
|
29269
|
+
if (latestMessage && list.some(e => e.messageUId === latestMessage.messageUId)) {
|
29270
|
+
const latestMessage2 = await MessageCache$1.get()?.getLatestMessage(conversation);
|
29271
|
+
ConversationManager$1.get().updateLatestMessage(conversation, latestMessage2);
|
29272
|
+
}
|
29273
|
+
}
|
29274
|
+
return result;
|
29203
29275
|
}
|
29204
|
-
async
|
29276
|
+
async deleteHistoryMessages(conversation) {
|
29205
29277
|
MessageCache$1.get()?.clearConversationCache(conversation);
|
29206
29278
|
ConversationManager$1.get().clearHistoryMessages(conversation);
|
29207
29279
|
return clearHistoryMessage(getFullDialogId(conversation)).then(result => result.code);
|
@@ -29227,22 +29299,30 @@
|
|
29227
29299
|
const contentList = [];
|
29228
29300
|
for (const dialogInfo of data.fullDialog) {
|
29229
29301
|
const conversationObj = this.formatConversation(dialogInfo);
|
29230
|
-
if (conversationObj) {
|
29231
|
-
|
29232
|
-
|
29233
|
-
|
29234
|
-
|
29235
|
-
|
29236
|
-
|
29237
|
-
|
29238
|
-
|
29239
|
-
}
|
29240
|
-
ConversationManager$1.get().addLocalConversation(conversationObj);
|
29241
|
-
const localConversation = ConversationManager$1.get().get(conOpt);
|
29242
|
-
Object.assign(conversationObj, localConversation);
|
29243
|
-
contentList.push(conversationObj);
|
29302
|
+
if (!conversationObj) {
|
29303
|
+
continue;
|
29304
|
+
}
|
29305
|
+
const conOpt = {
|
29306
|
+
conversationType: conversationObj.conversationType,
|
29307
|
+
targetId: conversationObj.targetId
|
29308
|
+
};
|
29309
|
+
if (!conversationObj.latestMessage) {
|
29310
|
+
conversationObj.latestMessage = await MessageCache$1.get()?.getLatestMessage(conOpt);
|
29244
29311
|
}
|
29312
|
+
ConversationManager$1.get().addLocalConversation(conversationObj);
|
29313
|
+
const localConversation = ConversationManager$1.get().get(conOpt);
|
29314
|
+
Object.assign(conversationObj, localConversation);
|
29315
|
+
if (isDef(conversationObj.latestMessage) && !conversationObj.updateTime) {
|
29316
|
+
conversationObj.updateTime = parseInt(conversationObj.latestMessage.sentTime);
|
29317
|
+
}
|
29318
|
+
if (!conversationObj.updateTime) {
|
29319
|
+
conversationObj.updateTime = 10000;
|
29320
|
+
}
|
29321
|
+
contentList.push(conversationObj);
|
29245
29322
|
}
|
29323
|
+
contentList.sort((a, b) => {
|
29324
|
+
return (a.updateTime ?? 0) - (b.updateTime ?? 0);
|
29325
|
+
});
|
29246
29326
|
return {
|
29247
29327
|
code: exports.ErrorCode.SUCCESS,
|
29248
29328
|
data: contentList
|
@@ -29269,19 +29349,7 @@
|
|
29269
29349
|
code: exports.ErrorCode.CONVER_GET_ERROR
|
29270
29350
|
};
|
29271
29351
|
}
|
29272
|
-
const
|
29273
|
-
code,
|
29274
|
-
data
|
29275
|
-
} = await this.getRemoteHistoryMessages(conOpt, {
|
29276
|
-
count: 1,
|
29277
|
-
order: 0
|
29278
|
-
});
|
29279
|
-
if (code !== exports.ErrorCode.SUCCESS) {
|
29280
|
-
return {
|
29281
|
-
code: exports.ErrorCode.CONVER_GET_ERROR
|
29282
|
-
};
|
29283
|
-
}
|
29284
|
-
const latestMessage = data?.list[0];
|
29352
|
+
const latestMessage = await MessageCache$1.get()?.getLatestMessage(conOpt);
|
29285
29353
|
const conversation = {
|
29286
29354
|
...conOpt,
|
29287
29355
|
...localConversation,
|
@@ -29387,8 +29455,18 @@
|
|
29387
29455
|
}
|
29388
29456
|
return conversationObj;
|
29389
29457
|
}
|
29390
|
-
clearBurnAfterReadingExpiredMessages(conversation) {
|
29391
|
-
|
29458
|
+
async clearBurnAfterReadingExpiredMessages(conversation) {
|
29459
|
+
const cache = MessageCache$1.get();
|
29460
|
+
if (!cache) {
|
29461
|
+
return Promise.resolve([]);
|
29462
|
+
}
|
29463
|
+
const latestMessage = await cache.getLatestMessage(conversation);
|
29464
|
+
const removedMsgUids = await cache.clearBurnAfterReadingExpiredMessages(conversation);
|
29465
|
+
if (latestMessage && removedMsgUids.includes(latestMessage.messageUId)) {
|
29466
|
+
const latestMessage2 = await cache.getLatestMessage(conversation);
|
29467
|
+
ConversationManager$1.get().updateLatestMessage(conversation, latestMessage2);
|
29468
|
+
}
|
29469
|
+
return removedMsgUids;
|
29392
29470
|
}
|
29393
29471
|
}
|
29394
29472
|
|
@@ -30608,7 +30686,7 @@
|
|
30608
30686
|
assert('conversation', conversation, AssertRules.CONVERSATION);
|
30609
30687
|
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
30610
30688
|
logger.debug('clear message ->' + paramsStr);
|
30611
|
-
const code = await imClient.
|
30689
|
+
const code = await imClient.deleteHistoryMessages(conversation);
|
30612
30690
|
if (code !== exports.ErrorCode.SUCCESS) {
|
30613
30691
|
logger.warn('clear message ->' + code + ':' + ErrorDesc(code) + ',' + paramsStr);
|
30614
30692
|
return {
|
package/package.json
CHANGED
package/types/types.d.ts
CHANGED
@@ -89,6 +89,7 @@ export interface IConversationState extends IBaseConversationInfo {
|
|
89
89
|
isTop: boolean;
|
90
90
|
dialogTitle: string | null | undefined;
|
91
91
|
smallAvatarUrl: string | null | undefined;
|
92
|
+
updateTime: number | null | undefined;
|
92
93
|
}
|
93
94
|
/**
|
94
95
|
* 会话信息
|
@@ -96,7 +97,7 @@ export interface IConversationState extends IBaseConversationInfo {
|
|
96
97
|
export type IConversationOption = IBaseConversationInfo;
|
97
98
|
export type IUpdatedConversationItemKeys = Extract<keyof IReceivedConversation, 'isTop' | 'notificationStatus' | 'notificationLevel' | 'unreadMessageCount' | 'hasMentioned' | 'unreadMentionedCount' | 'dialogTitle' | 'smallAvatarUrl' | 'latestMessage' | 'burnAfterReadingFlag' | 'burnAfterReadingTime'>;
|
98
99
|
export type IUpdatedConversationItem = Partial<Record<IUpdatedConversationItemKeys, {
|
99
|
-
time:
|
100
|
+
time: number;
|
100
101
|
val: any;
|
101
102
|
}>>;
|
102
103
|
/**
|