Skip to content
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

[WIP] base work to add unread mention count to updateUnreadMessageCount (closes #510) #2723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -6380,7 +6380,8 @@ updateUserPrivacySettingRules setting:UserPrivacySetting rules:userPrivacySettin
//@chat_list The chat list with changed number of unread messages
//@unread_count Total number of unread messages
//@unread_unmuted_count Total number of unread messages in unmuted chats
updateUnreadMessageCount chat_list:ChatList unread_count:int32 unread_unmuted_count:int32 = Update;
//@unread_mention_count Total number of unread mentions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

updateUnreadMessageCount chat_list:ChatList unread_count:int32 unread_unmuted_count:int32 unread_mention_count:int32 = Update;

//@description Number of unread chats, i.e. with unread messages or marked as unread, has changed. This update is sent only if the message database is used
//@chat_list The chat list with changed number of unread messages
Expand Down
30 changes: 26 additions & 4 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12792,6 +12792,7 @@ void MessagesManager::recalc_unread_count(DialogListId dialog_list_id, int32 old

int32 message_total_count = 0;
int32 message_muted_count = 0;
int32 mention_total_count = 0;
int32 dialog_total_count = 0;
int32 dialog_muted_count = 0;
int32 dialog_marked_count = 0;
Expand Down Expand Up @@ -12828,6 +12829,10 @@ void MessagesManager::recalc_unread_count(DialogListId dialog_list_id, int32 old
dialog_muted_marked_count++;
}
}

int unread_mention_count = d->unread_mention_count;
LOG(DEBUG) << "Have " << unread_mention_count << " unread mentions in " << dialog_id;
mention_total_count += unread_mention_count;
}
if (d->order != DEFAULT_ORDER) { // must not count sponsored dialog, which is added independently
if (dialog_id.get_type() == DialogType::SecretChat) {
Expand All @@ -12840,9 +12845,11 @@ void MessagesManager::recalc_unread_count(DialogListId dialog_list_id, int32 old
}

if (list.unread_message_total_count_ != message_total_count ||
list.unread_message_muted_count_ != message_muted_count) {
list.unread_message_muted_count_ != message_muted_count ||
list.unread_mention_total_count_ != mention_total_count) {
list.unread_message_total_count_ = message_total_count;
list.unread_message_muted_count_ = message_muted_count;
list.unread_mention_total_count_ = mention_total_count;
send_update_unread_message_count(list, DialogId(), true, "recalc_unread_count");
}

Expand Down Expand Up @@ -12912,6 +12919,7 @@ void MessagesManager::set_dialog_last_read_inbox_message_id(Dialog *d, MessageId
if (is_dialog_muted(d)) {
list.unread_message_muted_count_ += delta;
}
// TODO mention counts
send_update_unread_message_count(list, d->dialog_id, force_update, source);
}
delta = static_cast<int32>(new_unread_count != 0) - static_cast<int32>(old_unread_count != 0);
Expand Down Expand Up @@ -13744,6 +13752,7 @@ void MessagesManager::init() {
if (list != nullptr) {
list->unread_message_total_count_ = r_total_count.ok();
list->unread_message_muted_count_ = r_muted_count.ok();
// TODO mention counts
list->is_message_unread_count_inited_ = true;
send_update_unread_message_count(*list, DialogId(), true, "load unread_message_count", true);
} else {
Expand Down Expand Up @@ -30521,11 +30530,14 @@ void MessagesManager::send_update_unread_message_count(DialogList &list, DialogI

auto dialog_list_id = list.dialog_list_id;
CHECK(list.is_message_unread_count_inited_);
if (list.unread_message_muted_count_ < 0 || list.unread_message_muted_count_ > list.unread_message_total_count_) {
if (list.unread_message_muted_count_ < 0 || list.unread_message_muted_count_ > list.unread_message_total_count_ ||
list.unread_mention_total_count_ > list.unread_message_total_count_) {
if (!list.need_unread_count_recalc_) {
LOG(ERROR) << "Unread message count became invalid in " << dialog_list_id << ": "
<< list.unread_message_total_count_ << '/'
<< list.unread_message_total_count_ - list.unread_message_muted_count_ << " from " << source << " and "
<< list.unread_message_total_count_ - list.unread_message_muted_count_
<< "(" << list.unread_mention_total_count_ << ")"
<< " from " << source << " and "
<< dialog_id;
}
if (list.unread_message_muted_count_ < 0) {
Expand All @@ -30534,6 +30546,9 @@ void MessagesManager::send_update_unread_message_count(DialogList &list, DialogI
if (list.unread_message_muted_count_ > list.unread_message_total_count_) {
list.unread_message_total_count_ = list.unread_message_muted_count_;
}
if (list.unread_mention_total_count_ > list.unread_message_total_count_) {
list.unread_message_total_count_ = list.unread_mention_total_count_;
}
}

if (!from_database) {
Expand Down Expand Up @@ -33690,6 +33705,7 @@ void MessagesManager::edit_dialog_list_for_dialog_filter(unique_ptr<DialogFilter
if (is_dialog_muted(d)) {
new_list.unread_message_muted_count_ += unread_count;
}
new_list.unread_mention_total_count_ += d->unread_mention_count;
}
if (unread_count != 0 || d->is_marked_as_unread) {
new_list.unread_dialog_total_count_++;
Expand Down Expand Up @@ -33730,6 +33746,7 @@ void MessagesManager::edit_dialog_list_for_dialog_filter(unique_ptr<DialogFilter
new_list.is_message_unread_count_inited_ &&
(old_list.unread_message_total_count_ != new_list.unread_message_total_count_ ||
old_list.unread_message_muted_count_ != new_list.unread_message_muted_count_ ||
old_list.unread_mention_total_count_ != new_list.unread_mention_total_count_ ||
!old_list.is_message_unread_count_inited_);
bool need_update_unread_chat_count =
new_list.is_dialog_unread_count_inited_ &&
Expand Down Expand Up @@ -33812,6 +33829,7 @@ void MessagesManager::delete_dialog_list_for_dialog_filter(DialogFilterId dialog
if (list->is_message_unread_count_inited_) {
list->unread_message_total_count_ = 0;
list->unread_message_muted_count_ = 0;
list->unread_mention_total_count_ = 0;
send_update_unread_message_count(*list, DialogId(), true, source, true);
G()->td_db()->get_binlog_pmc()->erase(PSTRING() << "unread_message_count" << dialog_list_id.get());
}
Expand Down Expand Up @@ -37911,6 +37929,7 @@ void MessagesManager::update_dialog_lists(
need_update_unread_chat_count =
list.is_dialog_unread_count_inited_ && old_position.total_dialog_count != get_dialog_total_count(list);
auto unread_count = d->server_unread_count + d->local_unread_count;
auto mention_count = d->unread_mention_count;
const char *change_source = was_in_list ? "on_dialog_remove" : "on_dialog_add";
if (unread_count != 0 && list.is_message_unread_count_inited_) {
unread_count *= delta;
Expand All @@ -37919,6 +37938,7 @@ void MessagesManager::update_dialog_lists(
if (is_dialog_muted(d)) {
list.unread_message_muted_count_ += unread_count;
}
list.unread_mention_total_count_ += mention_count * delta;
send_update_unread_message_count(list, dialog_id, true, change_source);
}
if ((unread_count != 0 || d->is_marked_as_unread) && list.is_dialog_unread_count_inited_) {
Expand Down Expand Up @@ -40910,10 +40930,12 @@ td_api::object_ptr<td_api::updateUnreadMessageCount> MessagesManager::get_update
CHECK(list.is_message_unread_count_inited_);
int32 unread_count = list.unread_message_total_count_;
int32 unread_unmuted_count = list.unread_message_total_count_ - list.unread_message_muted_count_;
int32 unread_mention_count = list.unread_mention_total_count_;
CHECK(unread_count >= 0);
CHECK(unread_unmuted_count >= 0);
CHECK(unread_mention_count >= 0);
return td_api::make_object<td_api::updateUnreadMessageCount>(list.dialog_list_id.get_chat_list_object(), unread_count,
unread_unmuted_count);
unread_unmuted_count, unread_mention_count);
}

td_api::object_ptr<td_api::updateUnreadChatCount> MessagesManager::get_update_unread_chat_count_object(
Expand Down
1 change: 1 addition & 0 deletions td/telegram/MessagesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ class MessagesManager final : public Actor {
bool need_unread_count_recalc_ = true;
int32 unread_message_total_count_ = 0;
int32 unread_message_muted_count_ = 0;
int32 unread_mention_total_count_ = 0;
int32 unread_dialog_total_count_ = 0;
int32 unread_dialog_muted_count_ = 0;
int32 unread_dialog_marked_count_ = 0;
Expand Down