Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions lib/inbox/bloc/inbox_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ class InboxBloc extends Bloc<InboxEvent, InboxState> {
),
);

int totalUnreadCount = getUnreadCount(privateMessagesResponse.privateMessages, getPersonMentionsResponse.mentions, getRepliesResponse.replies);
GetUnreadCountResponse getUnreadCountResponse = await lemmy.run(
GetUnreadCount(
auth: account.jwt!,
),
);

int totalUnreadCount = getUnreadCountResponse.privateMessages + getUnreadCountResponse.mentions + getUnreadCountResponse.replies;

return emit(
state.copyWith(
Expand Down Expand Up @@ -218,7 +224,13 @@ class InboxBloc extends Bloc<InboxEvent, InboxState> {
replies.removeWhere(matchMarkedComment);
}

int totalUnreadCount = getUnreadCount(state.privateMessages, state.mentions, replies);
GetUnreadCountResponse getUnreadCountResponse = await lemmy.run(
GetUnreadCount(
auth: account.jwt!,
),
);

int totalUnreadCount = getUnreadCountResponse.privateMessages + getUnreadCountResponse.mentions + getUnreadCountResponse.replies;

emit(state.copyWith(
status: InboxStatus.success,
Expand Down Expand Up @@ -386,24 +398,4 @@ class InboxBloc extends Bloc<InboxEvent, InboxState> {
myVote: mention.myVote,
);
}

int getUnreadCount(List<PrivateMessageView> privateMessageViews, List<PersonMentionView> personMentionViews, List<CommentReplyView> commentViews) {
// Tally up how many unread messages/mentions/replies there are so far
// This will only tally up at most 20 for each type for a total of 60 unread counts
int totalUnreadCount = 0;

for (PrivateMessageView privateMessageView in privateMessageViews) {
if (privateMessageView.privateMessage.read == false) totalUnreadCount++;
}

for (PersonMentionView personMentionView in personMentionViews) {
if (personMentionView.personMention.read == false) totalUnreadCount++;
}

for (CommentReplyView commentView in commentViews) {
if (commentView.commentReply.read == false) totalUnreadCount++;
}

return totalUnreadCount;
}
}