dateLabel added to chat web

This commit is contained in:
Eudes Inácio
2023-09-11 21:14:00 +01:00
parent 42c2fc92ff
commit f1717f71cc
7 changed files with 82 additions and 32 deletions
+1
View File
@@ -66,6 +66,7 @@ export class MessageService {
messageModelInstance: MessageModel
attachmentsModelData: any
dateLabel = false;
constructor(
+30 -1
View File
@@ -707,8 +707,18 @@ export class RoomService {
return JSON.parse(str);
}
formatDateToDDMMYYYY(dateStamp) {
const date = new Date(dateStamp);
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Month is zero-based
const year = date.getFullYear();
return `${day}-${month}-${year}`;
}
restoreOnce = false
dateLabel: any = [];
async restoreMessageFromDB() {
if(environment.chatOffline && this.restoreOnce == false) {
this.restoreOnce = true
@@ -716,10 +726,24 @@ export class RoomService {
const messages = await MessageModel.filter({rid:this.id}).execute()
console.log('MessageModel', messages)
console.log('MessageModel', messages)
for (let ChatMessage of messages) {
const wewMessage = await this.simplePrepareMessage(ChatMessage)
console.log('MessageModel 22', wewMessage)
const currentMessageDate = this.formatDateToDDMMYYYY(ChatMessage._updatedAt)
if(!this.dateLabel.includes(currentMessageDate) ) {
this.dateLabel.push(currentMessageDate);
wewMessage.msg = currentMessageDate
wewMessage.dateLabel = true;
this.messages.push(wewMessage)
}
wewMessage.from = 'Offline'
wewMessage.loadHistory = this.hasLoadHistory
wewMessage.messageModelInstance = ChatMessage
@@ -727,6 +751,9 @@ export class RoomService {
if(wewMessage.offline == false) {
const message = await this.prepareCreate({message:ChatMessage})
console.log('MessageModel 33', messages)
message.from = 'Offline'
message.loadHistory = this.hasLoadHistory
wewMessage.messageModelInstance = ChatMessage
@@ -736,6 +763,8 @@ export class RoomService {
const offlineMessage = await this.prepareCreate({message:ChatMessage})
console.log('MessageModel 44', offlineMessage)
offlineMessage.from = 'Offline'
offlineMessage.loadHistory = this.hasLoadHistory
wewMessage.messageModelInstance = ChatMessage