Skip to content

Commit 4c67b98

Browse files
committed
(demo) add room created as default last message
1 parent 98a3338 commit 4c67b98

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

demo/src/ChatContainer.vue

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,14 @@ export default {
251251
...room,
252252
roomId: key,
253253
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+
}
255262
})
256263
})
257264
@@ -298,12 +305,6 @@ export default {
298305
formatLastMessage(message) {
299306
if (!message.timestamp) return
300307
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-
307308
let content = message.content
308309
if (message.file)
309310
content = `${message.file.name}.${message.file.extension ||
@@ -313,7 +314,10 @@ export default {
313314
...message,
314315
...{
315316
content,
316-
timestamp,
317+
timestamp: this.formatTimestamp(
318+
new Date(message.timestamp.seconds * 1000),
319+
message.timestamp
320+
),
317321
distributed: true,
318322
seen: message.sender_id === this.currentUserId ? message.seen : null,
319323
new:
@@ -323,6 +327,12 @@ export default {
323327
}
324328
},
325329
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+
326336
fetchMessages({ room, options = {} }) {
327337
this.$emit('show-demo-options', false)
328338
@@ -666,21 +676,11 @@ export default {
666676
.on('value', snapshot => {
667677
if (!snapshot || !snapshot.val()) return
668678
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(
677680
new Date(snapshot.val().last_changed),
678-
timestampFormat
681+
new Date(snapshot.val().last_changed)
679682
)
680683
681-
const last_changed =
682-
timestampFormat === 'HH:mm' ? `today, ${timestamp}` : timestamp
683-
684684
user.status = { ...snapshot.val(), last_changed }
685685
686686
const roomIndex = this.rooms.findIndex(

0 commit comments

Comments
 (0)