Skip to content

Commit 6da34b7

Browse files
authored
Merge pull request #19025 from nextcloud/fix/13777/temp-messages-timestamp
fix: use real timestamp for temp messages
2 parents 276da12 + a47f2af commit 6da34b7

18 files changed

Lines changed: 74 additions & 38 deletions

File tree

src/components/Dashboard/TalkDashboard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { EventBus } from '../../services/EventBus.ts'
3636
import { useActorStore } from '../../stores/actor.ts'
3737
import { useDashboardStore } from '../../stores/dashboard.ts'
3838
import { hasUnreadMentions } from '../../utils/conversation.ts'
39+
import { convertToUnix } from '../../utils/formattedTime.ts'
3940
import { copyConversationLinkToClipboard } from '../../utils/handleUrl.ts'
4041
4142
const supportsUpcomingReminders = hasTalkFeature('local', 'upcoming-reminders')
@@ -154,7 +155,7 @@ async function startMeeting() {
154155
roomName: conversationName.value || t('spreed', 'Meeting'),
155156
roomType: CONVERSATION.TYPE.PUBLIC,
156157
objectType: CONVERSATION.OBJECT_TYPE.INSTANT_MEETING,
157-
objectId: Math.floor(Date.now() / 1000).toString(),
158+
objectId: convertToUnix(new Date()).toString(),
158159
})
159160
await copyConversationLinkToClipboard(conversation.token)
160161
await router.push({

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ATTENDEE, CONVERSATION, MESSAGE, PARTICIPANT } from '../../../constants
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(),
@@ -237,8 +238,8 @@ describe('ConversationItem.vue', () => {
237238
it.each(TEST_CASES)(
238239
'should render correct timestamp for %s',
239240
(message, activity, output) => {
240-
item.lastMessage.timestamp = message && new Date(message).valueOf() / 1000
241-
item.lastActivity = activity && new Date(activity).valueOf() / 1000
241+
item.lastMessage.timestamp = message && convertToUnix(new Date(message))
242+
item.lastActivity = activity && convertToUnix(new Date(activity))
242243

243244
const wrapper = mountConversation(false)
244245

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
@@ -32,6 +32,7 @@ import { EventBus } from '../../../../services/EventBus.ts'
3232
import storeConfig from '../../../../store/storeConfig.js'
3333
import { useActorStore } from '../../../../stores/actor.ts'
3434
import { useTokenStore } from '../../../../stores/token.ts'
35+
import { convertToUnix } from '../../../../utils/formattedTime.ts'
3536

3637
let store
3738

@@ -94,7 +95,7 @@ describe('MessageItem.vue', () => {
9495
messageParameters: {},
9596
id: 123,
9697
isReplyable: true,
97-
timestamp: new Date('2020-05-07 09:23:00').getTime() / 1000,
98+
timestamp: convertToUnix(new Date('2020-05-07 09:23:00')),
9899
token: TOKEN,
99100
systemMessage: '',
100101
messageType: MESSAGE.TYPE.COMMENT,
@@ -533,7 +534,7 @@ describe('MessageItem.vue', () => {
533534
})
534535

535536
test('does not render actions for temporary messages', async () => {
536-
messageProps.message.timestamp = 0
537+
messageProps.message.id = 'temp-123'
537538

538539
const wrapper = mountMessage(messageProps)
539540

@@ -644,7 +645,7 @@ describe('MessageItem.vue', () => {
644645
})
645646

646647
test('displays the message already with a spinner while sending it', () => {
647-
messageProps.message.timestamp = 0
648+
messageProps.message.id = 'temp-123'
648649
const wrapper = mountMessage(messageProps)
649650
const message = wrapper.findComponent(NcRichText)
650651
expect(message.text()).toBe('test message')

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ import { hasTalkFeature } from '../../../../services/CapabilitiesManager.ts'
113113
import { EventBus } from '../../../../services/EventBus.ts'
114114
import { useActorStore } from '../../../../stores/actor.ts'
115115
import { useChatExtrasStore } from '../../../../stores/chatExtras.ts'
116-
import { isFilePreviewParameter } from '../../../../utils/message.ts'
116+
import { isFilePreviewParameter, isTemporaryId } from '../../../../utils/message.ts'
117117
118118
const LocationCard = defineAsyncComponent(() => import('./MessagePart/LocationCard.vue'))
119119
@@ -187,7 +187,7 @@ export default {
187187
},
188188
189189
isTemporary() {
190-
return !this.isScheduledMessage && this.message.timestamp === 0
190+
return !this.isScheduledMessage && isTemporaryId(this.message.id)
191191
},
192192
193193
isDeletedMessage() {
@@ -319,7 +319,7 @@ export default {
319319
}
320320
321321
return this.message.id === this.message.threadId
322-
|| this.message.id.toString().startsWith('temp-')
322+
|| isTemporaryId(this.message.id)
323323
|| (this.isScheduledMessage && this.message.threadId === -1)
324324
},
325325

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ import { useChatExtrasStore } from '../../../../../stores/chatExtras.ts'
222222
import { usePollsStore } from '../../../../../stores/polls.ts'
223223
import { useUploadStore } from '../../../../../stores/upload.ts'
224224
import { formatDateTime } from '../../../../../utils/formattedTime.ts'
225-
import { getFileKeys, getFilePreviewKeys, isFilePreviewParameter } from '../../../../../utils/message.ts'
225+
import {
226+
getFileKeys,
227+
getFilePreviewKeys,
228+
isFilePreviewParameter,
229+
isTemporaryId,
230+
} from '../../../../../utils/message.ts'
226231
import { parseMentions, parseSpecialSymbols } from '../../../../../utils/textParse.ts'
227232
228233
// Regular expression to check for Unicode emojis in message text
@@ -433,7 +438,7 @@ export default {
433438
},
434439
435440
isTemporary() {
436-
return !this.isScheduledMessage && this.message.timestamp === 0
441+
return !this.isScheduledMessage && isTemporaryId(this.message.id)
437442
},
438443
439444
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
@@ -476,7 +476,7 @@ export default {
476476
if (!this.messagesShouldBeGrouped(message, lastMessage)) {
477477
groupId = message.id
478478
if (message.timestamp === 0) {
479-
// This is a temporary message, the timestamp is today
479+
// This is a scheduled message that failed to send, the timestamp is today
480480
dateTimestamp = this.currentDay
481481
} else {
482482
dateTimestamp = convertToUnix(new Date(message.timestamp * 1000).setHours(0, 0, 0, 0))
@@ -635,9 +635,6 @@ export default {
635635
* @return {object} Date object
636636
*/
637637
getDateOfMessage(message) {
638-
if (message.id.toString().startsWith('temp-')) {
639-
return new Date()
640-
}
641638
return new Date(message.timestamp * 1000)
642639
},
643640

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
@@ -40,6 +40,7 @@ import { setConversationUnread, updateLastReadMessage } from '../services/messag
4040
import { useActorStore } from '../stores/actor.ts'
4141
import { useTalkHashStore } from '../stores/talkHash.js'
4242
import { generateOCSErrorResponse, generateOCSResponse } from '../test-helpers.js'
43+
import { convertToUnix } from '../utils/formattedTime.ts'
4344
import storeConfig from './storeConfig.js'
4445

4546
vi.mock('../services/conversationsService', () => ({
@@ -1022,7 +1023,7 @@ describe('conversationsStore', () => {
10221023
vi.useRealTimers()
10231024

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

0 commit comments

Comments
 (0)