Skip to content

Commit af46bd1

Browse files
authored
Merge pull request #19032 from nextcloud/backport/19025/stable34
[stable34] fix: use real timestamp for temp messages
2 parents 6d19214 + b7dcdc4 commit af46bd1

17 files changed

Lines changed: 65 additions & 32 deletions

File tree

src/components/Dashboard/TalkDashboard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { EventBus } from '../../services/EventBus.ts'
3535
import { useActorStore } from '../../stores/actor.ts'
3636
import { useDashboardStore } from '../../stores/dashboard.ts'
3737
import { hasUnreadMentions } from '../../utils/conversation.ts'
38+
import { convertToUnix } from '../../utils/formattedTime.ts'
3839
import { copyConversationLinkToClipboard } from '../../utils/handleUrl.ts'
3940
4041
const supportsUpcomingReminders = hasTalkFeature('local', 'upcoming-reminders')
@@ -141,7 +142,7 @@ async function startMeeting() {
141142
roomName: conversationName.value || t('spreed', 'Meeting'),
142143
roomType: CONVERSATION.TYPE.PUBLIC,
143144
objectType: CONVERSATION.OBJECT_TYPE.INSTANT_MEETING,
144-
objectId: Math.floor(Date.now() / 1000).toString(),
145+
objectId: convertToUnix(new Date()).toString(),
145146
})
146147
await copyConversationLinkToClipboard(conversation.token)
147148
await router.push({

src/components/LeftSidebar/ConversationsList/Conversation.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ATTENDEE, CONVERSATION, PARTICIPANT } from '../../../constants.ts'
1717
import { leaveConversation } from '../../../services/participantsService.js'
1818
import storeConfig from '../../../store/storeConfig.js'
1919
import { findNcActionButton } from '../../../test-helpers.js'
20+
import { convertToUnix } from '../../../utils/formattedTime.ts'
2021

2122
vi.mock('../../../services/participantsService', () => ({
2223
leaveConversation: vi.fn(),

src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useActorStore } from '../../../../../stores/actor.ts'
1818
import { useIntegrationsStore } from '../../../../../stores/integrations.js'
1919
import { useTokenStore } from '../../../../../stores/token.ts'
2020
import { findNcActionButton, findNcButton } from '../../../../../test-helpers.js'
21+
import { convertToUnix } from '../../../../../utils/formattedTime.ts'
2122

2223
describe('MessageButtonsBar.vue', () => {
2324
const TOKEN = 'XXTOKENXX'
@@ -65,7 +66,7 @@ describe('MessageButtonsBar.vue', () => {
6566
messageParameters: {},
6667
id: 123,
6768
isReplyable: true,
68-
timestamp: new Date('2020-05-07 09:23:00').getTime() / 1000,
69+
timestamp: convertToUnix(new Date('2020-05-07 09:23:00')),
6970
token: TOKEN,
7071
systemMessage: '',
7172
messageType: MESSAGE.TYPE.COMMENT,

src/components/MessagesList/MessagesGroup/Message/MessageItem.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { EventBus } from '../../../../services/EventBus.ts'
3030
import storeConfig from '../../../../store/storeConfig.js'
3131
import { useActorStore } from '../../../../stores/actor.ts'
3232
import { useTokenStore } from '../../../../stores/token.ts'
33+
import { convertToUnix } from '../../../../utils/formattedTime.ts'
3334

3435
let store
3536

@@ -92,7 +93,7 @@ describe('MessageItem.vue', () => {
9293
messageParameters: {},
9394
id: 123,
9495
isReplyable: true,
95-
timestamp: new Date('2020-05-07 09:23:00').getTime() / 1000,
96+
timestamp: convertToUnix(new Date('2020-05-07 09:23:00')),
9697
token: TOKEN,
9798
systemMessage: '',
9899
messageType: MESSAGE.TYPE.COMMENT,
@@ -483,7 +484,7 @@ describe('MessageItem.vue', () => {
483484
})
484485

485486
test('does not render actions for temporary messages', async () => {
486-
messageProps.message.timestamp = 0
487+
messageProps.message.id = 'temp-123'
487488

488489
const wrapper = mountMessage(messageProps)
489490

@@ -594,7 +595,7 @@ describe('MessageItem.vue', () => {
594595
})
595596

596597
test('displays the message already with a spinner while sending it', () => {
597-
messageProps.message.timestamp = 0
598+
messageProps.message.id = 'temp-123'
598599
const wrapper = mountMessage(messageProps)
599600
const message = wrapper.findComponent(NcRichText)
600601
expect(message.text()).toBe('test message')

src/components/MessagesList/MessagesGroup/Message/MessageItem.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import { EventBus } from '../../../../services/EventBus.ts'
115115
import { useActorStore } from '../../../../stores/actor.ts'
116116
import { useChatExtrasStore } from '../../../../stores/chatExtras.ts'
117117
import { getItemTypeFromMessage } from '../../../../utils/getItemTypeFromMessage.ts'
118+
import { isTemporaryId } from '../../../../utils/message.ts'
118119
119120
const LocationCard = defineAsyncComponent(() => import('./MessagePart/LocationCard.vue'))
120121
@@ -187,7 +188,7 @@ export default {
187188
},
188189
189190
isTemporary() {
190-
return !this.isScheduledMessage && this.message.timestamp === 0
191+
return !this.isScheduledMessage && isTemporaryId(this.message.id)
191192
},
192193
193194
isDeletedMessage() {
@@ -332,7 +333,7 @@ export default {
332333
}
333334
334335
return this.message.id === this.message.threadId
335-
|| this.message.id.toString().startsWith('temp-')
336+
|| isTemporaryId(this.message.id)
336337
|| (this.isScheduledMessage && this.message.threadId === -1)
337338
},
338339

src/components/MessagesList/MessagesGroup/Message/MessagePart/MessageBody.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ import { useChatExtrasStore } from '../../../../../stores/chatExtras.ts'
213213
import { usePollsStore } from '../../../../../stores/polls.ts'
214214
import { useUploadStore } from '../../../../../stores/upload.ts'
215215
import { formatDateTime } from '../../../../../utils/formattedTime.ts'
216+
import { isTemporaryId } from '../../../../../utils/message.ts'
216217
import { parseMentions, parseSpecialSymbols } from '../../../../../utils/textParse.ts'
217218
218219
// Regular expression to check for Unicode emojis in message text
@@ -410,7 +411,7 @@ export default {
410411
},
411412
412413
isTemporary() {
413-
return !this.isScheduledMessage && this.message.timestamp === 0
414+
return !this.isScheduledMessage && isTemporaryId(this.message.id)
414415
},
415416
416417
isScheduledSendingFailure() {

src/components/MessagesList/MessagesList.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import router from '../../__mocks__/router.js'
1818
import { ATTENDEE, MESSAGE } from '../../constants.ts'
1919
import storeConfig from '../../store/storeConfig.js'
2020
import { useChatStore } from '../../stores/chat.ts'
21+
import { convertToUnix } from '../../utils/formattedTime.ts'
2122

2223
vi.mock('vuex', async () => {
2324
const vuex = await vi.importActual('vuex')
@@ -48,7 +49,7 @@ vi.mock('../../composables/useGetMessages.ts', async () => ({
4849
})),
4950
}))
5051

51-
const fakeTimestamp = (value) => new Date(value).getTime() / 1000
52+
const fakeTimestamp = (value) => convertToUnix(new Date(value))
5253

5354
describe('MessagesList.vue', () => {
5455
const TOKEN = 'XXTOKENXX'

src/components/MessagesList/MessagesList.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export default {
462462
if (!this.messagesShouldBeGrouped(message, lastMessage)) {
463463
groupId = message.id
464464
if (message.timestamp === 0) {
465-
// This is a temporary message, the timestamp is today
465+
// This is a scheduled message that failed to send, the timestamp is today
466466
dateTimestamp = this.currentDay
467467
} else {
468468
dateTimestamp = convertToUnix(new Date(message.timestamp * 1000).setHours(0, 0, 0, 0))
@@ -625,9 +625,6 @@ export default {
625625
* @return {object} Date object
626626
*/
627627
getDateOfMessage(message) {
628-
if (message.id.toString().startsWith('temp-')) {
629-
return new Date()
630-
}
631628
return new Date(message.timestamp * 1000)
632629
},
633630

src/composables/__tests__/useMessageInfo.spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useStore } from 'vuex'
1010
import { ATTENDEE, CONVERSATION, MESSAGE } from '../../constants.ts'
1111
import { useActorStore } from '../../stores/actor.ts'
1212
import { useGuestNameStore } from '../../stores/guestName.ts'
13+
import { convertToUnix } from '../../utils/formattedTime.ts'
1314
import { useConversationInfo } from '../useConversationInfo.ts'
1415
import { useMessageInfo } from '../useMessageInfo.ts'
1516

@@ -49,7 +50,7 @@ describe('message actions', () => {
4950
messageParameters: {},
5051
id: 123,
5152
isReplyable: true,
52-
timestamp: new Date('2024-05-01 16:15:00').getTime() / 1000,
53+
timestamp: convertToUnix(new Date('2024-05-01 16:15:00')),
5354
token: TOKEN,
5455
systemMessage: '',
5556
messageType: MESSAGE.TYPE.COMMENT,
@@ -78,7 +79,7 @@ describe('message actions', () => {
7879

7980
test('message is not deleteable when it is older than 6 hours and unlimited capability is disabled', () => {
8081
// Arrange
81-
message.value.timestamp = new Date('2024-05-01 7:20:00').getTime() / 1000
82+
message.value.timestamp = convertToUnix(new Date('2024-05-01 7:20:00'))
8283
// Act
8384
const result = useMessageInfo(message)
8485
// Assert
@@ -173,7 +174,7 @@ describe('message actions', () => {
173174

174175
test('can edit own message in note to self', () => {
175176
// Arrange
176-
message.value.timestamp = new Date('2024-04-28 7:20:00').getTime() / 1000
177+
message.value.timestamp = convertToUnix(new Date('2024-04-28 7:20:00'))
177178
conversationProps.type = CONVERSATION.TYPE.NOTE_TO_SELF
178179
// Act
179180
const result = useMessageInfo(message)
@@ -368,11 +369,11 @@ describe('message actions', () => {
368369
messageParameters: {},
369370
id: 123,
370371
isReplyable: true,
371-
lastEditTimestamp: new Date('2024-05-01 16:30:00').getTime() / 1000,
372+
lastEditTimestamp: convertToUnix(new Date('2024-05-01 16:30:00')),
372373
lastEditActorId: 'user-id-1',
373374
lastEditActorType: ATTENDEE.ACTOR_TYPE.USERS,
374375
lastEditActorDisplayName: 'user-display-name-1',
375-
timestamp: new Date('2024-05-01 16:15:00').getTime() / 1000,
376+
timestamp: convertToUnix(new Date('2024-05-01 16:15:00')),
376377
token: TOKEN,
377378
systemMessage: '',
378379
messageType: MESSAGE.TYPE.COMMENT,

src/store/conversationsStore.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { setConversationUnread, updateLastReadMessage } from '../services/messag
3939
import { useActorStore } from '../stores/actor.ts'
4040
import { useTalkHashStore } from '../stores/talkHash.js'
4141
import { generateOCSErrorResponse, generateOCSResponse } from '../test-helpers.js'
42+
import { convertToUnix } from '../utils/formattedTime.ts'
4243
import storeConfig from './storeConfig.js'
4344

4445
vi.mock('../services/conversationsService', () => ({
@@ -1021,7 +1022,7 @@ describe('conversationsStore', () => {
10211022
vi.useRealTimers()
10221023

10231024
const changedConversation = store.getters.conversation(testToken)
1024-
expect(changedConversation.lastActivity).toBe(mockDate.getTime() / 1000)
1025+
expect(changedConversation.lastActivity).toBe(convertToUnix(mockDate))
10251026
})
10261027
})
10271028

0 commit comments

Comments
 (0)