@@ -251,7 +251,14 @@ export default {
251
251
... room,
252
252
roomId: key,
253
253
avatar: roomAvatar,
254
- index: room .lastUpdated .seconds
254
+ index: room .lastUpdated .seconds ,
255
+ lastMessage: {
256
+ content: ' Room created' ,
257
+ timestamp: this .formatTimestamp (
258
+ new Date (room .lastUpdated .seconds ),
259
+ room .lastUpdated
260
+ )
261
+ }
255
262
})
256
263
})
257
264
@@ -298,12 +305,6 @@ export default {
298
305
formatLastMessage (message ) {
299
306
if (! message .timestamp ) return
300
307
301
- const date = new Date (message .timestamp .seconds * 1000 )
302
- const timestampFormat = isSameDay (date, new Date ()) ? ' HH:mm' : ' DD/MM/YY'
303
-
304
- let timestamp = parseTimestamp (message .timestamp , timestampFormat)
305
- if (timestampFormat === ' HH:mm' ) timestamp = ` Today, ${ timestamp} `
306
-
307
308
let content = message .content
308
309
if (message .file )
309
310
content = ` ${ message .file .name } .${ message .file .extension ||
@@ -313,7 +314,10 @@ export default {
313
314
... message,
314
315
... {
315
316
content,
316
- timestamp,
317
+ timestamp: this .formatTimestamp (
318
+ new Date (message .timestamp .seconds * 1000 ),
319
+ message .timestamp
320
+ ),
317
321
distributed: true ,
318
322
seen: message .sender_id === this .currentUserId ? message .seen : null ,
319
323
new:
@@ -323,6 +327,12 @@ export default {
323
327
}
324
328
},
325
329
330
+ formatTimestamp (date , timestamp ) {
331
+ const timestampFormat = isSameDay (date, new Date ()) ? ' HH:mm' : ' DD/MM/YY'
332
+ const result = parseTimestamp (timestamp, timestampFormat)
333
+ return timestampFormat === ' HH:mm' ? ` Today, ${ result} ` : result
334
+ },
335
+
326
336
fetchMessages ({ room, options = {} }) {
327
337
this .$emit (' show-demo-options' , false )
328
338
@@ -666,21 +676,11 @@ export default {
666
676
.on (' value' , snapshot => {
667
677
if (! snapshot || ! snapshot .val ()) return
668
678
669
- const timestampFormat = isSameDay (
670
- new Date (snapshot .val ().last_changed ),
671
- new Date ()
672
- )
673
- ? ' HH:mm'
674
- : ' DD MMMM, HH:mm'
675
-
676
- const timestamp = parseTimestamp (
679
+ const last_changed = this .formatTimestamp (
677
680
new Date (snapshot .val ().last_changed ),
678
- timestampFormat
681
+ new Date ( snapshot . val (). last_changed )
679
682
)
680
683
681
- const last_changed =
682
- timestampFormat === ' HH:mm' ? ` today, ${ timestamp} ` : timestamp
683
-
684
684
user .status = { ... snapshot .val (), last_changed }
685
685
686
686
const roomIndex = this .rooms .findIndex (
0 commit comments