Skip to content

Commit

Permalink
Update notification on profile name fetch or change.
Browse files Browse the repository at this point in the history
  • Loading branch information
clark-signal authored and greyson-signal committed Apr 12, 2023
1 parent 71e2b82 commit 27e3c88
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.thoughtcrime.securesms.jobmanager.JobManager;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.notifications.v2.ConversationId;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
Expand Down Expand Up @@ -462,19 +463,26 @@ private boolean setProfileName(Recipient recipient, String profileName) {
String remoteDisplayName = remoteProfileName.toString();
String localDisplayName = localProfileName.toString();

if (!recipient.isBlocked() &&
!recipient.isGroup() &&
!recipient.isSelf() &&
!localDisplayName.isEmpty() &&
!remoteDisplayName.equals(localDisplayName))
{
boolean writeChangeEvent = !recipient.isBlocked() &&
!recipient.isGroup() &&
!recipient.isSelf() &&
!localDisplayName.isEmpty() &&
!remoteDisplayName.equals(localDisplayName);
if (writeChangeEvent) {
Log.i(TAG, "Writing a profile name change event for " + recipient.getId());
SignalDatabase.messages().insertProfileNameChangeMessages(recipient, remoteDisplayName, localDisplayName);
} else {
Log.i(TAG, String.format(Locale.US, "Name changed, but wasn't relevant to write an event. blocked: %s, group: %s, self: %s, firstSet: %s, displayChange: %s",
recipient.isBlocked(), recipient.isGroup(), recipient.isSelf(), localDisplayName.isEmpty(), !remoteDisplayName.equals(localDisplayName)));
}

if (writeChangeEvent || localDisplayName.isEmpty()) {
Long threadId = SignalDatabase.threads().getThreadIdFor(recipient.getId());
if (threadId != null) {
ApplicationDependencies.getMessageNotifier().updateNotification(context, ConversationId.forConversation(threadId));
}
}

return true;
}
} catch (InvalidCiphertextException e) {
Expand Down

0 comments on commit 27e3c88

Please sign in to comment.