Skip to content

Commit

Permalink
Update number of contacts after adding/removing contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
vkryl committed Oct 26, 2023
1 parent 69a9f6a commit a56681d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,27 +441,32 @@ void onUpdateMyUserId (long userId) {

@TdlibThread
void onUpdateUser (TdApi.UpdateUser update) {
boolean statusChanged;
boolean isMe;
boolean hadUser;
final boolean statusChanged;
final boolean hadUser;
final boolean isContactChanged;
final boolean isContact;
TdApi.User newUser = update.user;
synchronized (dataLock) {
TdApi.User oldUser = users.get(newUser.id);
if (hadUser = oldUser != null) {
hadUser = oldUser != null;
isContact = newUser.isContact;
if (hadUser) {
statusChanged = !Td.equalsTo(oldUser.status, newUser.status);
isContactChanged = oldUser.isContact != newUser.isContact;
Td.copyTo(newUser, oldUser);
synchronized (onlineMutex) {
oldUser.status = newUser.status;
}
newUser = oldUser;
} else {
statusChanged = false;
statusChanged = isContactChanged = false;
users.put(newUser.id, newUser);
}
}

notifyUserListeners(newUser);
if (isMe = (newUser.id == myUserId)) {
boolean isMe = (newUser.id == myUserId);
if (isMe) {
notifyMyUserListeners(myUserListeners.iterator(), newUser);
tdlib.downloadMyUser(newUser);
tdlib.context().onUpdateAccountProfile(tdlib.id(), newUser, true);
Expand All @@ -481,6 +486,10 @@ void onUpdateUser (TdApi.UpdateUser update) {
TdlibNotificationChannelGroup.updateGroup(newUser);
}
tdlib.context().onUpdateAccountProfile(tdlib.id(), newUser, !hadUser);
} else {
if (isContactChanged) {
tdlib.contacts().notifyContactStatusChanged(newUser.id, isContact);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ private void checkRegisteredCount () {
tdlib.searchContacts(null, 5, newHandler());
}

@TdlibThread
void notifyContactStatusChanged (long userId, boolean isContact) {
checkRegisteredCount();
}

private Client.ResultHandler newHandler () {
return object -> {
switch (object.getConstructor()) {
Expand Down

0 comments on commit a56681d

Please sign in to comment.