-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unread message count in query channels response #247
Conversation
Generated by 🚫 Danger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only added parsing the new messaged unread count. But please check the full channel unread count flow. You need to remove the unread count calculation by messageRead
.
@buh That's not totally possible. MessageRead doesn't include mentioned messages, and it's not sent for new & deleted messages. I think we should keep the current solution for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be sent for new and delete messages.
I think you need to check the unread count flow.
So, we have a number from the request, if we will calculate by messages probably the number will be less because of messages limits. We should use the maximum otherwise it will be useless.
Unread count calculation required a request with state and watch. Now it looks like a mess with calculation and response value. Probably we need to request the mentioned unread count from the backend and omit it on our side.
messagesUnreadCount -> unreadMessagesCount channelsUnreadCount -> unreadChannelsCount These are internal so no API changes
guard let eventCid = event.cid, let watchingChannels = watchingChannelsAtomic[eventCid] else { | ||
return | ||
} | ||
|
||
// Update watching channels for unread count and watcher count. | ||
watchingChannels.forEach { | ||
if let channel = $0.value { | ||
if let channel = $0.value, channel.cid == eventCid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no needed because watchingChannels
contains channels with the same cid:
guard let eventCid = event.cid, let watchingChannels = watchingChannelsAtomic[eventCid] else {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've added it since it was like that for notificationMessageNew
part. Will remove it.
if unreadMessageRead.unreadMessageCount > 0 { | ||
// Calculate mentioned message unread count | ||
// This is approximate since it'll be limited for the messages we've fetched | ||
for message in messages.reversed() { | ||
if message.user.isCurrent { | ||
continue | ||
} | ||
|
||
if message.user != currentUser, message.mentionedUsers.contains(currentUser) { | ||
unreadCount.mentionedMessages += 1 | ||
if message.created > unreadMessageRead.lastReadDate { | ||
if message.user != currentUser, message.mentionedUsers.contains(currentUser) { | ||
unreadCount.mentionedMessages += 1 | ||
} | ||
} else { | ||
break | ||
} | ||
} else { | ||
break | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
// Calculate mentioned message unread count
// This is approximate since it'll be limited for the messages we've fetched
for message in messages.reversed() where !message.user.isCurrent {
if message.created > unreadMessageRead.lastReadDate {
if message.mentionedUsers.contains(currentUser) {
unreadCount.mentionedMessages += 1
}
} else {
break
}
}
No description provided.