Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Empty chat appeared #580
Browse files Browse the repository at this point in the history
  • Loading branch information
florianhaar authored and Boehrsi committed Jun 4, 2020
1 parent a01176c commit d2619a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/src/chat/chat_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
color: color,
freshMessageCount: 0,
isSelfTalk: false,
isDeviceTalk: false,
isGroupChat: false,
preview: null,
timestamp: null,
Expand All @@ -162,6 +163,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
final colorValue = await chat.getColor();
final freshMessageCount = await context.getFreshMessageCount(_chatId);
final isSelfTalk = await chat.isSelfTalk();
final isDeviceTalk = await chat.isDeviceTalk();
final isVerified = await chat.isVerified();
final color = colorFromArgb(colorValue);
final chatSummary = chat.get(ChatExtension.chatSummary);
Expand All @@ -180,10 +182,9 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
Contact contact = _contactRepository.get(chatContactId);
phoneNumbers = contact?.get(ContactExtension.contactPhoneNumber);
avatarPath = contact?.get(ContactExtension.contactAvatar);
final isSelfTalk = await chat.isSelfTalk();
if (isSelfTalk) {
subTitle = L10n.get(L.chatMessagesSelf);
} else {
} else if(!isDeviceTalk) {
final Contact contact = _contactRepository.get(chatContactId);
subTitle = await contact.getAddress();
}
Expand All @@ -194,6 +195,7 @@ class ChatBloc extends Bloc<ChatEvent, ChatState> {
color: color,
freshMessageCount: freshMessageCount,
isSelfTalk: isSelfTalk,
isDeviceTalk: isDeviceTalk,
isGroupChat: _isGroupChat,
preview: chatSummaryState != ChatMsg.messageStateDraft && chatSummaryState != ChatMsg.messageNone ? chatSummary?.preview : L10n.get(L.chatNoMessages),
timestamp: chatSummary?.timestamp,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/chat/chat_event_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ChatStateSuccess extends ChatState {
final Color color;
final int freshMessageCount;
final bool isSelfTalk;
final bool isDeviceTalk;
final bool isGroupChat;
final String preview;
final int timestamp;
Expand All @@ -85,6 +86,7 @@ class ChatStateSuccess extends ChatState {
@required this.color,
@required this.freshMessageCount,
@required this.isSelfTalk,
@required this.isDeviceTalk,
@required this.isGroupChat,
@required this.preview,
@required this.timestamp,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/chatlist/chat_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class _ChatListItemState extends State<ChatListItem> {
String imagePath = "";
bool hasError = false;
bool isGroupChat = false;
bool isDeviceTalk = false;

if (state is ChatStateSuccess) {
name = state.name;
Expand All @@ -105,12 +106,13 @@ class _ChatListItemState extends State<ChatListItem> {
preview = state.preview;
imagePath = state.avatarPath;
isGroupChat = state.isGroupChat;
isDeviceTalk = state.isDeviceTalk;
} else if (state is ChatStateFailure) {
hasError = true;
}

return Visibility(
visible: !hasError,
visible: !hasError && !isDeviceTalk,
child: InkWell(
child: AvatarListItem(
title: name,
Expand Down
19 changes: 11 additions & 8 deletions lib/src/notifications/local_notification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,18 @@ class LocalNotificationManager {
notificationHistory.update(chatId.toString(), (value) => messageId, ifAbsent: () => messageId);
_chatRepository.putIfAbsent(id: chatId);
final chat = _chatRepository.get(chatId);
String title = await chat.getName();
final count = (await _context.getFreshMessageCount(chatId)) - 1;
if (count > 1) {
title = "$title (+ ${L10n.getFormatted(L.moreMessagesX, [count])})";
final isDeviceTalk = await chat.isDeviceTalk();
if(!isDeviceTalk) {
String title = await chat.getName();
final count = (await _context.getFreshMessageCount(chatId)) - 1;
if (count > 1) {
title = "$title (+ ${L10n.getFormatted(L.moreMessagesX, [count])})";
}
final teaser = await message.getSummaryText(200);
final payload = chatId?.toString();
_logger.info("Creating chat notification for chat id $chatId with message id $messageId");
_notificationManager.showNotificationFromLocal(chatId, title, teaser, payload: payload);
}
final teaser = await message.getSummaryText(200);
final payload = chatId?.toString();
_logger.info("Creating chat notification for chat id $chatId with message id $messageId");
_notificationManager.showNotificationFromLocal(chatId, title, teaser, payload: payload);
}
});

Expand Down

0 comments on commit d2619a7

Please sign in to comment.