diff --git a/src/app/pages/messages/messages.page.ts b/src/app/pages/messages/messages.page.ts index 90edf05..c71b32e 100644 --- a/src/app/pages/messages/messages.page.ts +++ b/src/app/pages/messages/messages.page.ts @@ -179,7 +179,7 @@ export class MessagesPage implements OnInit, OnDestroy { this.chatService.getChat({ id: chatId } as Chat).subscribe((chat) => { this.currentChat = chat; - this.title = chat.name ?? ''; + this.title = this.chatTitle(chat); this.participants = [...(chat.participants ?? [])]; const currentUser = this.auth.currentUserValue; if (currentUser) this.participants.push(currentUser); @@ -257,10 +257,18 @@ export class MessagesPage implements OnInit, OnDestroy { const { data } = await modal.onDidDismiss(); if (data) { this.currentChat = data; - this.title = data.name ?? ''; + this.title = this.chatTitle(data); this.participants = [...(data.participants ?? [])]; const currentUser = this.auth.currentUserValue; if (currentUser) this.participants.push(currentUser); } } + + private chatTitle(chat: Chat): string { + const others = chat.participants ?? []; + if (chat.type === '1to1' && others.length === 1) { + return others[0].username ?? chat.name ?? ''; + } + return chat.name ?? ''; + } }