fix: add check for groupchats with only 1 member

This commit is contained in:
Freek van de Ven 2024-05-24 14:17:58 +02:00
parent 82448ab9e0
commit c9a11758d8
2 changed files with 13 additions and 8 deletions

View file

@ -7,6 +7,7 @@
- Change the ChatTranslations constructor to require all translations or use the ChatTranslations.empty constructor if you don't want to specify all translations
- Remove the Divider between the users on the new chat screen
- Add option to set a custom padding around the list of chats
- Fix nullpointer when firstWhere returns null because there is only 1 person in a groupchat
## 1.4.3

View file

@ -91,11 +91,15 @@ class FirebaseChatOverviewService implements ChatOverviewService {
var chat = element.doc.data();
if (chat == null) return;
var otherUser = await _userService.getUser(
chat.users.firstWhere(
(element) => element != currentUser?.id,
),
);
var otherUser = chat.users.any(
(element) => element != currentUser?.id,
)
? await _userService.getUser(
chat.users.firstWhere(
(element) => element != currentUser?.id,
),
)
: null;
var unread =
await _addUnreadChatSubscription(chat.id!, currentUser!.id!);
@ -144,10 +148,10 @@ class FirebaseChatOverviewService implements ChatOverviewService {
imageUrl: chat.imageUrl ?? '',
unreadMessages: unread,
users: users,
lastMessage: chat.lastMessage != null
lastMessage: chat.lastMessage != null && otherUser != null
? chat.lastMessage!.imageUrl == null
? ChatTextMessageModel(
sender: otherUser!,
sender: otherUser,
text: chat.lastMessage!.text!,
timestamp: DateTime.fromMillisecondsSinceEpoch(
chat.lastMessage!.timestamp
@ -155,7 +159,7 @@ class FirebaseChatOverviewService implements ChatOverviewService {
),
)
: ChatImageMessageModel(
sender: otherUser!,
sender: otherUser,
imageUrl: chat.lastMessage!.imageUrl!,
timestamp: DateTime.fromMillisecondsSinceEpoch(
chat.lastMessage!.timestamp