mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
show last messae and date
This commit is contained in:
@@ -68,16 +68,19 @@
|
||||
</span>
|
||||
</ion-label>
|
||||
</div>
|
||||
<!-- <div class="item-date font-13-em" [class.item-date-active]="room.id == idSelected">{{room.duration}}</div> -->
|
||||
<div class="item-date font-13-em" [class.item-date-active]="room.id == idSelected">
|
||||
{{ room.displayDate }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="item-date font-13-em" [class.item-date-active]="room.id == idSelected">
|
||||
<!-- {{ expirationDate[room.id] !== null ? expirationDate[room.id] + ' seconds left' : 'No expiration' }} -->
|
||||
{{ expirationDate[room.id] !== null ? expirationDate[room.id] + ' seconds left' : '' }}
|
||||
</div>
|
||||
<!-- <div *ngIf="room.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="room.id ==idSelected">
|
||||
<div class="item-message font-13-em add-ellipsis white-space-nowrap" *ngIf="room.otherUserType == false"> {{room.lastMessage.msg}} </div>
|
||||
<div class="font-13-em" *ngIf="room.otherUserType == true">está escrever ...</div>
|
||||
</div> -->
|
||||
<div *ngIf="room?.messages?.[0]?.message" class="item-description d-flex align-items-center" [class.item-description-active]="room.id ==idSelected">
|
||||
<div class="item-message font-13-em add-ellipsis white-space-nowrap"> {{room.messages[0].message}} </div>
|
||||
<!-- <div class="item-message font-13-em add-ellipsis white-space-nowrap" *ngIf="room.otherUserType == false"> {{room.messages[0].message}} </div> -->
|
||||
<!-- <div class="font-13-em" *ngIf="room.otherUserType == true">está escrever ...</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ion-item-sliding>
|
||||
@@ -106,16 +109,20 @@
|
||||
</span>
|
||||
</ion-label>
|
||||
</div>
|
||||
<div class="item-date font-13-em" [class.item-date-active]="room.id == idSelected">
|
||||
{{ room.displayDate }}
|
||||
</div>
|
||||
<!-- <div class="item-date font-13-em" [class.item-date-active]="room.id == idSelected">{{room.duration}}</div> -->
|
||||
</div>
|
||||
<div class="item-date font-13-em" [class.item-date-active]="room.id == idSelected">
|
||||
<!-- {{ expirationDate[room.id] !== null ? expirationDate[room.id] + ' seconds left' : 'No expiration' }} -->
|
||||
{{ expirationDate[room.id] !== null ? expirationDate[room.id] + ' seconds left' : '' }}
|
||||
</div>
|
||||
<!-- <div *ngIf="room.lastMessage" class="item-description d-flex align-items-center" [class.item-description-active]="room.id ==idSelected">
|
||||
<div class="item-message font-13-em add-ellipsis white-space-nowrap" *ngIf="room.otherUserType == false"> {{room.lastMessage.msg}} </div>
|
||||
<div class="font-13-em" *ngIf="room.otherUserType == true">está escrever ...</div>
|
||||
</div> -->
|
||||
<div *ngIf="room?.messages?.[0]?.message" class="item-description d-flex align-items-center" [class.item-description-active]="room.id ==idSelected">
|
||||
<div class="item-message font-13-em add-ellipsis white-space-nowrap"> {{room?.messages?.[0]?.message}} </div>
|
||||
<!-- <div class="item-message font-13-em add-ellipsis white-space-nowrap" *ngIf="room.otherUserType == false"> {{room?.messages?.[0]?.message}} </div> -->
|
||||
<!-- <div class="font-13-em" *ngIf="room.otherUserType == true">está escrever ...</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ion-item-sliding>
|
||||
|
||||
@@ -22,9 +22,10 @@ import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room/ro
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { interval, Subscription } from 'rxjs';
|
||||
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { RoomEntity, RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { BoldLocalRepository } from 'src/app/module/chat/data/repository/bold/bold-local-repository'
|
||||
import { BoldTable } from 'src/app/infra/database/dexie/instance/chat/schema/bold';
|
||||
import { RoomViewModel } from './store/model/room';
|
||||
@Component({
|
||||
selector: 'app-chat',
|
||||
templateUrl: './chat.page.html',
|
||||
@@ -104,12 +105,13 @@ export class ChatPage implements OnInit {
|
||||
ngOnInit() {
|
||||
|
||||
this.items$ = this.roomLocalDataSourceService.getItemsLive().pipe(
|
||||
map(rooms => rooms.map(room => ({
|
||||
...room,
|
||||
minutesLeft: this.getSecondsLeft(room.expirationDate)
|
||||
}))),
|
||||
map((roomList) => roomList.map((room)=> new RoomViewModel(room))),
|
||||
tap((roomList) => {
|
||||
this.rooms = roomList
|
||||
this.rooms = roomList.sort((a, b) =>
|
||||
|
||||
new Date(b.messages?.[0]?.sentAt as unknown as string) as unknown as number -
|
||||
(new Date(a.messages?.[0]?.sentAt as unknown as string) as any) as unknown as number
|
||||
)
|
||||
})
|
||||
);
|
||||
|
||||
@@ -125,7 +127,7 @@ export class ChatPage implements OnInit {
|
||||
// Subscribe to the interval observable
|
||||
this.intervalSubscription = interval$.subscribe();
|
||||
|
||||
this.ChatServiceService.getRoomList()
|
||||
// this.ChatServiceService.getRoomList()
|
||||
|
||||
this.hideRefreshButton();
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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
|
||||
createdAt: typeof RoomEntitySchema._input.createdAt
|
||||
expirationDate: typeof RoomEntitySchema._input.expirationDate
|
||||
roomType: typeof RoomEntitySchema._input.roomType
|
||||
members: typeof RoomEntitySchema._input.members
|
||||
messages: typeof RoomEntitySchema._input.messages
|
||||
displayDate = ''
|
||||
|
||||
constructor(model: IRoom) {
|
||||
Object.assign(this, model)
|
||||
this.formatarData()
|
||||
}
|
||||
|
||||
formatarData() {
|
||||
if(this.messages?.[0]?.sentAt) {
|
||||
|
||||
const dataMensagem = new Date(this.messages[0].sentAt);
|
||||
const agora = new Date();
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user