@onyx-p/imlib-web 1.8.7 → 1.8.9

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 CHANGED
@@ -28414,6 +28414,72 @@ class MessageCache {
28414
28414
  }
28415
28415
  });
28416
28416
  }
28417
+ updateMessageReceiptStatus(event, type) {
28418
+ if (!event || !event.messageUIdList || event.messageUIdList.length === 0) {
28419
+ return;
28420
+ }
28421
+ const {
28422
+ conversation
28423
+ } = event;
28424
+ const dialogId = getFullDialogId(conversation);
28425
+ const cachedMessages = this.messageCache.get(dialogId);
28426
+ if (!cachedMessages || cachedMessages.length === 0) {
28427
+ return;
28428
+ }
28429
+ const messageUIdSet = new Set(event.messageUIdList);
28430
+ let updated = false;
28431
+ for (let i = 0; i < cachedMessages.length; i++) {
28432
+ const message = cachedMessages[i];
28433
+ if (messageUIdSet.has(message.messageUId)) {
28434
+ if (type === 0) {
28435
+ if (message.receivedStatus < ReceivedStatus.RECEIVED) {
28436
+ message.receivedStatus = ReceivedStatus.RECEIVED;
28437
+ updated = true;
28438
+ }
28439
+ } else {
28440
+ if (message.receivedStatus < ReceivedStatus.READ) {
28441
+ message.receivedStatus = ReceivedStatus.READ;
28442
+ updated = true;
28443
+ }
28444
+ }
28445
+ }
28446
+ }
28447
+ if (updated) {
28448
+ this.messageCache.set(dialogId, cachedMessages);
28449
+ }
28450
+ }
28451
+ clearBurnAfterReadingExpiredMessages(conversation) {
28452
+ const dialogId = getFullDialogId(conversation);
28453
+ const cachedMessages = this.messageCache.get(dialogId);
28454
+ if (!cachedMessages || cachedMessages.length === 0) {
28455
+ return [];
28456
+ }
28457
+ const currentTime = Date.now();
28458
+ const expiredMessageUIds = [];
28459
+ const remainingMessages = cachedMessages.filter(message => {
28460
+ if (!message.burnAfterReadingFlag) {
28461
+ return true;
28462
+ }
28463
+ const burnTime = message.burnAfterReadingTime || 0;
28464
+ if (burnTime === 0) {
28465
+ expiredMessageUIds.push(message.messageUId);
28466
+ return false;
28467
+ }
28468
+ const sentTimeLong = Long.fromString(message.sentTime);
28469
+ const currentTimeLong = Long.fromNumber(currentTime);
28470
+ const burnTimeLong = Long.fromNumber(burnTime);
28471
+ const expirationTime = sentTimeLong.add(burnTimeLong);
28472
+ if (currentTimeLong.greaterThan(expirationTime)) {
28473
+ expiredMessageUIds.push(message.messageUId);
28474
+ return false;
28475
+ }
28476
+ return true;
28477
+ });
28478
+ if (remainingMessages.length < cachedMessages.length) {
28479
+ this.messageCache.set(dialogId, remainingMessages);
28480
+ }
28481
+ return expiredMessageUIds;
28482
+ }
28417
28483
  }
28418
28484
 
28419
28485
  class IMClient extends EventEmitter {
@@ -28489,6 +28555,7 @@ class IMClient extends EventEmitter {
28489
28555
  });
28490
28556
  },
28491
28557
  onReceiptReceived: (event, type) => {
28558
+ MessageCache.get().updateMessageReceiptStatus(event, type);
28492
28559
  if (type === 0) {
28493
28560
  this.emit(Events.ARRIVAL_RECEIPT_RECEIVED, event);
28494
28561
  } else {
@@ -28561,8 +28628,8 @@ class IMClient extends EventEmitter {
28561
28628
  });
28562
28629
  }
28563
28630
  async getPreviousHistoryMessages(conversation, timestamp, count = 20) {
28564
- const cachedMessages = MessageCache.get().getPreviousMessages(conversation, timestamp, count);
28565
- if (!timestamp) {
28631
+ const cachedMessages = MessageCache.get().getPreviousMessages(conversation, timestamp ?? "0", count);
28632
+ if (!timestamp && cachedMessages.length) {
28566
28633
  ConversationManager$1.get().refreshLatestMessage(conversation, cachedMessages[cachedMessages.length - 1]);
28567
28634
  }
28568
28635
  if (cachedMessages.length >= count) {
@@ -28780,6 +28847,9 @@ class IMClient extends EventEmitter {
28780
28847
  }
28781
28848
  return conversationObj;
28782
28849
  }
28850
+ clearBurnAfterReadingExpiredMessages(conversation) {
28851
+ return MessageCache.get().clearBurnAfterReadingExpiredMessages(conversation);
28852
+ }
28783
28853
  }
28784
28854
 
28785
28855
  /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
@@ -29973,7 +30043,6 @@ const getHistoryMessages = async (conversation, options) => {
29973
30043
  return response;
29974
30044
  };
29975
30045
  const getRemoteHistoryMessages = async (conversation, options) => {
29976
- assert('options.timestamp', options.timestamp ?? 0, AssertRules.NUMBER);
29977
30046
  assert('options.count', options.count ?? 0, AssertRules.NUMBER);
29978
30047
  assert('options.order', options.order ?? 0, value => {
29979
30048
  return value === 0 || value === 1;
@@ -29981,8 +30050,11 @@ const getRemoteHistoryMessages = async (conversation, options) => {
29981
30050
  assert('conversation', conversation, AssertRules.CONVERSATION, true);
29982
30051
  const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
29983
30052
  logger.debug('get remote history message ->' + paramsStr);
30053
+ if (isDef(options.timestamp)) {
30054
+ options.timestamp = options.timestamp.toString();
30055
+ }
29984
30056
  let response;
29985
- if (options.order === 0) {
30057
+ if (!options.order) {
29986
30058
  response = await imClient.getPreviousHistoryMessages(conversation, options.timestamp, options.count);
29987
30059
  } else {
29988
30060
  response = await imClient.getRemoteHistoryMessages(conversation, options);
@@ -30063,5 +30135,18 @@ const _logSendError = (conversation, errorCode) => {
30063
30135
  logger.warn('send message fail ->' + errorCode + ':' + ErrorDesc(errorCode) + ',' + paramsStr);
30064
30136
  }
30065
30137
  };
30138
+ const clearBurnAfterReadingExpiredMessages = conversation => {
30139
+ assert('conversation', conversation, AssertRules.CONVERSATION, true);
30140
+ const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
30141
+ logger.debug('clear burn after reading expired messages ->' + paramsStr);
30142
+ const expiredMessageUIds = imClient.clearBurnAfterReadingExpiredMessages(conversation);
30143
+ if (expiredMessageUIds.length > 0) {
30144
+ logger.debug(`已清除会话 ${paramsStr} 中的 ${expiredMessageUIds.length} 条阅后即焚过期消息`);
30145
+ }
30146
+ return Promise.resolve({
30147
+ code: ErrorCode.SUCCESS,
30148
+ data: expiredMessageUIds
30149
+ });
30150
+ };
30066
30151
 
30067
- export { ChatRecordMessage, ConnectionStatus, ContactMessage, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, GroupCloseBurnAfterReadingMessage, GroupOpenBurnAfterReadingMessage, VoiceMessage as HQVoiceMessage, ImageMessage, InvitationMessage, LocationMessage, LogLevel, MentionedType, MessageDirection, MessageTypes, NotiMessageTypes, NotificationLevel, NotificationStatus, PrivateCloseBurnAfterReadingMessage, PrivateOpenBurnAfterReadingMessage, RecallCommandMessage, ReceivedStatus, RedEnvelopeMessage, SentStatus, TextMessage, TransferMessage, VideoMessage, addEventListener, clearAllMessagesUnreadStatus, clearHistoryMessages, clearMessagesUnreadStatus, clearTextMessageDraft, connect, deleteMessages, disconnect, getAllConversationState, getAllUnreadMentionedCount, getBlockedConversationList, getConnectionStatus, getConversation, getConversationList, getConversationNotificationLevel, getConversationNotificationStatus, getConversationState, getHistoryMessages, getRemoteHistoryMessages, getServerTime, getTextMessageDraft, getTopConversationList, getTotalUnreadCount, getUnreadCount, getUnreadMentionedCount, init, logOut, mockLogin, onceEventListener, parseChatRecordMsgDetails, recallMessage, registerMessageType, removeConversation, removeEventListener, request, saveTextMessageDraft, sendFileMessage, sendGIFMessage, sendHQVoiceMessage, sendImageMessage, sendMessage, sendReadReceipts, sendSightMessage, sendTextMessage, setConversationNotificationStatus, setConversationToTop, setUserLogged };
30152
+ export { ChatRecordMessage, ConnectionStatus, ContactMessage, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, GroupCloseBurnAfterReadingMessage, GroupOpenBurnAfterReadingMessage, VoiceMessage as HQVoiceMessage, ImageMessage, InvitationMessage, LocationMessage, LogLevel, MentionedType, MessageDirection, MessageTypes, NotiMessageTypes, NotificationLevel, NotificationStatus, PrivateCloseBurnAfterReadingMessage, PrivateOpenBurnAfterReadingMessage, RecallCommandMessage, ReceivedStatus, RedEnvelopeMessage, SentStatus, TextMessage, TransferMessage, VideoMessage, addEventListener, clearAllMessagesUnreadStatus, clearBurnAfterReadingExpiredMessages, clearHistoryMessages, clearMessagesUnreadStatus, clearTextMessageDraft, connect, deleteMessages, disconnect, getAllConversationState, getAllUnreadMentionedCount, getBlockedConversationList, getConnectionStatus, getConversation, getConversationList, getConversationNotificationLevel, getConversationNotificationStatus, getConversationState, getHistoryMessages, getRemoteHistoryMessages, getServerTime, getTextMessageDraft, getTopConversationList, getTotalUnreadCount, getUnreadCount, getUnreadMentionedCount, init, logOut, mockLogin, onceEventListener, parseChatRecordMsgDetails, recallMessage, registerMessageType, removeConversation, removeEventListener, request, saveTextMessageDraft, sendFileMessage, sendGIFMessage, sendHQVoiceMessage, sendImageMessage, sendMessage, sendReadReceipts, sendSightMessage, sendTextMessage, setConversationNotificationStatus, setConversationToTop, setUserLogged };
package/index.umd.js CHANGED
@@ -28420,6 +28420,72 @@
28420
28420
  }
28421
28421
  });
28422
28422
  }
28423
+ updateMessageReceiptStatus(event, type) {
28424
+ if (!event || !event.messageUIdList || event.messageUIdList.length === 0) {
28425
+ return;
28426
+ }
28427
+ const {
28428
+ conversation
28429
+ } = event;
28430
+ const dialogId = getFullDialogId(conversation);
28431
+ const cachedMessages = this.messageCache.get(dialogId);
28432
+ if (!cachedMessages || cachedMessages.length === 0) {
28433
+ return;
28434
+ }
28435
+ const messageUIdSet = new Set(event.messageUIdList);
28436
+ let updated = false;
28437
+ for (let i = 0; i < cachedMessages.length; i++) {
28438
+ const message = cachedMessages[i];
28439
+ if (messageUIdSet.has(message.messageUId)) {
28440
+ if (type === 0) {
28441
+ if (message.receivedStatus < exports.ReceivedStatus.RECEIVED) {
28442
+ message.receivedStatus = exports.ReceivedStatus.RECEIVED;
28443
+ updated = true;
28444
+ }
28445
+ } else {
28446
+ if (message.receivedStatus < exports.ReceivedStatus.READ) {
28447
+ message.receivedStatus = exports.ReceivedStatus.READ;
28448
+ updated = true;
28449
+ }
28450
+ }
28451
+ }
28452
+ }
28453
+ if (updated) {
28454
+ this.messageCache.set(dialogId, cachedMessages);
28455
+ }
28456
+ }
28457
+ clearBurnAfterReadingExpiredMessages(conversation) {
28458
+ const dialogId = getFullDialogId(conversation);
28459
+ const cachedMessages = this.messageCache.get(dialogId);
28460
+ if (!cachedMessages || cachedMessages.length === 0) {
28461
+ return [];
28462
+ }
28463
+ const currentTime = Date.now();
28464
+ const expiredMessageUIds = [];
28465
+ const remainingMessages = cachedMessages.filter(message => {
28466
+ if (!message.burnAfterReadingFlag) {
28467
+ return true;
28468
+ }
28469
+ const burnTime = message.burnAfterReadingTime || 0;
28470
+ if (burnTime === 0) {
28471
+ expiredMessageUIds.push(message.messageUId);
28472
+ return false;
28473
+ }
28474
+ const sentTimeLong = Long.fromString(message.sentTime);
28475
+ const currentTimeLong = Long.fromNumber(currentTime);
28476
+ const burnTimeLong = Long.fromNumber(burnTime);
28477
+ const expirationTime = sentTimeLong.add(burnTimeLong);
28478
+ if (currentTimeLong.greaterThan(expirationTime)) {
28479
+ expiredMessageUIds.push(message.messageUId);
28480
+ return false;
28481
+ }
28482
+ return true;
28483
+ });
28484
+ if (remainingMessages.length < cachedMessages.length) {
28485
+ this.messageCache.set(dialogId, remainingMessages);
28486
+ }
28487
+ return expiredMessageUIds;
28488
+ }
28423
28489
  }
28424
28490
 
28425
28491
  class IMClient extends EventEmitter {
@@ -28495,6 +28561,7 @@
28495
28561
  });
28496
28562
  },
28497
28563
  onReceiptReceived: (event, type) => {
28564
+ MessageCache.get().updateMessageReceiptStatus(event, type);
28498
28565
  if (type === 0) {
28499
28566
  this.emit(exports.Events.ARRIVAL_RECEIPT_RECEIVED, event);
28500
28567
  } else {
@@ -28567,8 +28634,8 @@
28567
28634
  });
28568
28635
  }
28569
28636
  async getPreviousHistoryMessages(conversation, timestamp, count = 20) {
28570
- const cachedMessages = MessageCache.get().getPreviousMessages(conversation, timestamp, count);
28571
- if (!timestamp) {
28637
+ const cachedMessages = MessageCache.get().getPreviousMessages(conversation, timestamp ?? "0", count);
28638
+ if (!timestamp && cachedMessages.length) {
28572
28639
  ConversationManager$1.get().refreshLatestMessage(conversation, cachedMessages[cachedMessages.length - 1]);
28573
28640
  }
28574
28641
  if (cachedMessages.length >= count) {
@@ -28786,6 +28853,9 @@
28786
28853
  }
28787
28854
  return conversationObj;
28788
28855
  }
28856
+ clearBurnAfterReadingExpiredMessages(conversation) {
28857
+ return MessageCache.get().clearBurnAfterReadingExpiredMessages(conversation);
28858
+ }
28789
28859
  }
28790
28860
 
28791
28861
  /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
@@ -29979,7 +30049,6 @@
29979
30049
  return response;
29980
30050
  };
29981
30051
  const getRemoteHistoryMessages = async (conversation, options) => {
29982
- assert('options.timestamp', options.timestamp ?? 0, AssertRules.NUMBER);
29983
30052
  assert('options.count', options.count ?? 0, AssertRules.NUMBER);
29984
30053
  assert('options.order', options.order ?? 0, value => {
29985
30054
  return value === 0 || value === 1;
@@ -29987,8 +30056,11 @@
29987
30056
  assert('conversation', conversation, AssertRules.CONVERSATION, true);
29988
30057
  const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
29989
30058
  logger.debug('get remote history message ->' + paramsStr);
30059
+ if (isDef(options.timestamp)) {
30060
+ options.timestamp = options.timestamp.toString();
30061
+ }
29990
30062
  let response;
29991
- if (options.order === 0) {
30063
+ if (!options.order) {
29992
30064
  response = await imClient.getPreviousHistoryMessages(conversation, options.timestamp, options.count);
29993
30065
  } else {
29994
30066
  response = await imClient.getRemoteHistoryMessages(conversation, options);
@@ -30069,6 +30141,19 @@
30069
30141
  logger.warn('send message fail ->' + errorCode + ':' + ErrorDesc(errorCode) + ',' + paramsStr);
30070
30142
  }
30071
30143
  };
30144
+ const clearBurnAfterReadingExpiredMessages = conversation => {
30145
+ assert('conversation', conversation, AssertRules.CONVERSATION, true);
30146
+ const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
30147
+ logger.debug('clear burn after reading expired messages ->' + paramsStr);
30148
+ const expiredMessageUIds = imClient.clearBurnAfterReadingExpiredMessages(conversation);
30149
+ if (expiredMessageUIds.length > 0) {
30150
+ logger.debug(`已清除会话 ${paramsStr} 中的 ${expiredMessageUIds.length} 条阅后即焚过期消息`);
30151
+ }
30152
+ return Promise.resolve({
30153
+ code: exports.ErrorCode.SUCCESS,
30154
+ data: expiredMessageUIds
30155
+ });
30156
+ };
30072
30157
 
30073
30158
  exports.ChatRecordMessage = ChatRecordMessage;
30074
30159
  exports.ContactMessage = ContactMessage;
@@ -30092,6 +30177,7 @@
30092
30177
  exports.VideoMessage = VideoMessage;
30093
30178
  exports.addEventListener = addEventListener;
30094
30179
  exports.clearAllMessagesUnreadStatus = clearAllMessagesUnreadStatus;
30180
+ exports.clearBurnAfterReadingExpiredMessages = clearBurnAfterReadingExpiredMessages;
30095
30181
  exports.clearHistoryMessages = clearHistoryMessages;
30096
30182
  exports.clearMessagesUnreadStatus = clearMessagesUnreadStatus;
30097
30183
  exports.clearTextMessageDraft = clearTextMessageDraft;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "1.8.7",
3
+ "version": "1.8.9",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -239,3 +239,9 @@ export declare const mockLogin: (config: {
239
239
  phone: string;
240
240
  password: string;
241
241
  }) => CommonReqResult<import("./net/pbs/rpc.login").AuthSignIn2Resp>;
242
+ /**
243
+ * 清除指定会话中阅后即焚过期的消息
244
+ * @param conversation 会话信息
245
+ * @returns 被清除的消息ID列表
246
+ */
247
+ export declare const clearBurnAfterReadingExpiredMessages: (conversation: IConversationOption) => IPromiseResult<string[]>;