mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-18 18:33:49 +02:00
feat: allow chatTitleResolver to return null to fallback to default chatTitles
This commit is contained in:
parent
c38a608716
commit
63575ac8fe
3 changed files with 20 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
|||
- Changed the ChatDetailScreen to use the chatId instead of the ChatModel, the screen will now fetch the chat from the ChatService
|
||||
- Changed baseScreenBuilder to include a chatTitle that can be used to show provide the title logic to apps that use the baseScreenBuilder
|
||||
- Added loadNewMessagesAfter, loadOldMessagesBefore and removed pagination from getMessages in the ChatRepositoryInterface to change pagination behavior to rely on the stream and two methods indicating that more messages should be added to the stream
|
||||
- Added chatTitleResolver that can be used to resolve the chat title from the chat model or return null to allow for default behavior
|
||||
|
||||
## 4.0.0
|
||||
- Move to the new user story architecture
|
||||
|
|
|
@ -84,7 +84,7 @@ class ChatOptions {
|
|||
|
||||
/// Typedef for the chatTitleResolver function that is used to get a title for
|
||||
/// a chat.
|
||||
typedef ChatTitleResolver = String Function(ChatModel chat);
|
||||
typedef ChatTitleResolver = String? Function(ChatModel chat);
|
||||
|
||||
/// Typedef for the messageThemeResolver function that is used to get a
|
||||
/// [MessageTheme] for a message. This can return null so you can fall back to
|
||||
|
|
|
@ -129,21 +129,30 @@ class ChatDetailScreen extends HookWidget {
|
|||
required ChatModel chat,
|
||||
required List<UserModel> allUsers,
|
||||
}) {
|
||||
var options = chatScope.options;
|
||||
var translations = options.translations;
|
||||
var title = options.chatTitleResolver?.call(chat);
|
||||
if (title != null) {
|
||||
return title;
|
||||
}
|
||||
|
||||
if (chat.isGroupChat) {
|
||||
return chatScope.options.translations.groupNameEmpty;
|
||||
if (chat.chatName?.isNotEmpty ?? false) {
|
||||
return chat.chatName;
|
||||
}
|
||||
return translations.groupNameEmpty;
|
||||
}
|
||||
|
||||
// For one-to-one, pick the 'other' user from the list
|
||||
var otherUser = allUsers.firstWhere(
|
||||
(u) => u.id != chatScope.userId,
|
||||
orElse: () => const UserModel(
|
||||
id: "",
|
||||
),
|
||||
);
|
||||
var otherUser = allUsers
|
||||
.where(
|
||||
(u) => u.id != chatScope.userId,
|
||||
)
|
||||
.firstOrNull;
|
||||
|
||||
return otherUser.fullname?.isNotEmpty ?? false
|
||||
return otherUser != null && otherUser.fullname != null
|
||||
? otherUser.fullname
|
||||
: chatScope.options.translations.anonymousUser;
|
||||
: translations.anonymousUser;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue