diff options
| author | HJ <30-hj@users.noreply.git.pleroma.social> | 2020-11-02 08:35:22 +0000 |
|---|---|---|
| committer | HJ <30-hj@users.noreply.git.pleroma.social> | 2020-11-02 08:35:22 +0000 |
| commit | bcb6ee328f339366f2a661dc205013d12e2f39c3 (patch) | |
| tree | af9f4ac8ec78226a3c624f1c34b6aef0b9589f16 | |
| parent | 5254fdba75fc8d645c2235902a39b79c45f9aa6f (diff) | |
| parent | 757706425a1c865a0e64e9c530b3aa1e7d9e2494 (diff) | |
Merge branch 'fix/use-ids-for-chat-last-seen' into 'develop'
Fix: Use ids for chat last seen instead of timestamp
See merge request pleroma/pleroma-fe!1270
| -rw-r--r-- | src/services/chat_service/chat_service.js | 8 | ||||
| -rw-r--r-- | test/unit/specs/services/chat_service/chat_service.spec.js | 6 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/services/chat_service/chat_service.js b/src/services/chat_service/chat_service.js index b0905dc1..1fc4e390 100644 --- a/src/services/chat_service/chat_service.js +++ b/src/services/chat_service/chat_service.js @@ -6,7 +6,7 @@ const empty = (chatId) => { idempotencyKeyIndex: {}, messages: [], newMessageCount: 0, - lastSeenTimestamp: 0, + lastSeenMessageId: '0', chatId: chatId, minId: undefined, maxId: undefined @@ -27,7 +27,7 @@ const clear = (storage) => { storage.messages = storage.messages.filter(m => failedMessageIds.includes(m.id)) storage.newMessageCount = 0 - storage.lastSeenTimestamp = 0 + storage.lastSeenMessageId = '0' storage.minId = undefined storage.maxId = undefined } @@ -104,7 +104,7 @@ const add = (storage, { messages: newMessages, updateMaxId = true }) => { } if (!storage.idIndex[message.id] && !isConfirmation(storage, message)) { - if (storage.lastSeenTimestamp < message.created_at) { + if (storage.lastSeenMessageId < message.id) { storage.newMessageCount++ } storage.idIndex[message.id] = message @@ -122,7 +122,7 @@ const isConfirmation = (storage, message) => { const resetNewMessageCount = (storage) => { if (!storage) { return } storage.newMessageCount = 0 - storage.lastSeenTimestamp = new Date() + storage.lastSeenMessageId = storage.maxId } // Inserts date separators and marks the head and tail if it's the chain of messages made by the same user diff --git a/test/unit/specs/services/chat_service/chat_service.spec.js b/test/unit/specs/services/chat_service/chat_service.spec.js index 15e64bb5..0251cae7 100644 --- a/test/unit/specs/services/chat_service/chat_service.spec.js +++ b/test/unit/specs/services/chat_service/chat_service.spec.js @@ -47,10 +47,10 @@ describe('chatService', () => { chatService.resetNewMessageCount(chat) expect(chat.newMessageCount).to.eql(0) + expect(chat.lastSeenMessageId).to.eql(message2.id) - const createdAt = new Date() - createdAt.setSeconds(createdAt.getSeconds() + 10) - chatService.add(chat, { messages: [ { message3, created_at: createdAt } ] }) + // Add message with higher id + chatService.add(chat, { messages: [ message3 ] }) expect(chat.newMessageCount).to.eql(1) }) }) |
