fix delete message on ui layer

This commit is contained in:
Peter Maquiran
2024-09-03 16:26:54 +01:00
parent 878008b4ba
commit 842133fcc6
18 changed files with 268 additions and 136 deletions
+36 -25
View File
@@ -1,14 +1,14 @@
import { SafeResourceUrl } from "@angular/platform-browser";
import { IMessageType, MessageEntity, MessageEntitySchema } from "src/app/core/chat/entity/message";
import { MessageEntity, MessageEntitySchema, IMessageType, IMessage } from "src/app/core/chat/entity/message";
import { SessionStore } from "src/app/store/session.service";
export class MessageViewModal {
$id?: number
id?: string
roomId?: string
receiverId?: number
message?: string
messageType: number = 0
canEdit: boolean = false
oneShot: boolean = false
sentAt?: string
@@ -17,18 +17,30 @@ export class MessageViewModal {
sender!: typeof MessageEntitySchema._type.sender
sending: boolean = false
sendAttemp = 0
messageType = IMessageType.normal
attachments: typeof MessageEntitySchema._type.attachments = []
reactions: typeof MessageEntitySchema._type.reactions = []
requestId!: string
requestId: string
isDeleted: typeof MessageEntitySchema._type.isDeleted = false
status!: 'allViewed' | 'allReceived'| 'enviado'| 'enviar'
messageUiType!: 'info-meeting'| 'my-message'| 'other-message'
constructor(model: MessageEntity) {
Object.assign(this, model)
showReaction = false
showMessage = false
ballo = false
constructor(model?: IMessage) {
if(model) {
Object.assign(this, model)
}
this.setMessageUIType()
if(this.isDeleted != true && this.messageType != IMessageType.information) {
this.showReaction = true
}
if(this.isDeleted == false && this.messageType == IMessageType.normal) {
this.showMessage = true
}
}
setMessageUIType() {
@@ -41,28 +53,27 @@ export class MessageViewModal {
}
}
messageStatus(totalMembers: number) {
if(this.allViewed(totalMembers)) {
this.status = 'allViewed'
} else if(this.allReceived(totalMembers)) {
this.status = 'allReceived'
} else if (this.id) {
this.status = 'enviado'
} else {
this.status = 'enviar'
delete() {
this.showMessage = false
this.isDeleted = true
}
get messageStatus() {
if(this.id) {
return 'send'
}
}
allReceived(totalMembers: number) {
return this.info.filter(e => typeof e.deliverAt == 'string').length == totalMembers
}
allViewed(totalMembers: number) {
return this.info.filter(e => typeof e.readAt == 'string').length == totalMembers
}
get hasAttachment() {
return this.attachments.length >= 1
}
haveSeen(info: typeof MessageEntitySchema._type.info) {
return info.filter(e => typeof e.readAt == 'string' && e.memberId == SessionStore.user.UserId).length == 1
}
meSender() {
return this.sender.wxUserId == SessionStore.user.UserId
}
}
+10 -11
View File
@@ -2,7 +2,6 @@ import { IRoom, RoomEntitySchema } from "src/app/core/chat/entity/group";
export class RoomViewModel implements IRoom {
id: typeof RoomEntitySchema._input.id
roomName: typeof RoomEntitySchema._input.roomName
createdBy: typeof RoomEntitySchema._input.createdBy
@@ -27,35 +26,35 @@ export class RoomViewModel implements IRoom {
const hoje = new Date(agora.getFullYear(), agora.getMonth(), agora.getDate());
const ontem = new Date(hoje);
ontem.setDate(hoje.getDate() - 1);
const diasDaSemana = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
// Verifica se a mensagem foi enviada hoje
if (dataMensagem >= hoje) {
this.displayDate = dataMensagem.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false });
return
return
}
// Verifica se a mensagem foi enviada ontem
if (dataMensagem >= ontem && dataMensagem < hoje) {
this.displayDate = "Ontem";
return
}
// Verifica se a mensagem foi enviada nesta semana
const inicioDaSemana = new Date(hoje);
inicioDaSemana.setDate(hoje.getDate() - hoje.getDay());
if (dataMensagem >= inicioDaSemana) {
this.displayDate = diasDaSemana[dataMensagem.getDay()];
return
}
// Se a mensagem foi enviada antes desta semana
this.displayDate = dataMensagem.toLocaleDateString("pt-BR"); // Formato: DD/MM/AAAA
return
}
}
}
}