mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Broadcast ContactAliasChangedEvent to update contact list
This commit is contained in:
@@ -48,6 +48,10 @@ public class ContactListAdapter extends
|
||||
if (c1.isConnected() != c2.isConnected()) {
|
||||
return false;
|
||||
}
|
||||
if (!NullSafety.equals(c1.getContact().getAlias(),
|
||||
c2.getContact().getAlias())) {
|
||||
return false;
|
||||
}
|
||||
return NullSafety.equals(c1.getAuthorInfo().getAvatarHeader(),
|
||||
c2.getAuthorInfo().getAvatarHeader());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||
import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@@ -45,12 +46,24 @@ public class ContactListItem extends ContactItem
|
||||
Math.max(h.getTimestamp(), item.timestamp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new copy of the given item with a new alias set.
|
||||
*/
|
||||
ContactListItem(ContactListItem item, @Nullable String alias) {
|
||||
this(update(item.getContact(), alias), item.getAuthorInfo(),
|
||||
item.isConnected(), item.empty, item.unread, item.timestamp);
|
||||
}
|
||||
|
||||
private static Contact update(Contact c, @Nullable String alias) {
|
||||
return new Contact(c.getId(), c.getAuthor(), c.getLocalAuthorId(),
|
||||
alias, c.getHandshakePublicKey(), c.isVerified());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new copy of the given item with a new avatar
|
||||
* referenced by the given attachment header.
|
||||
*/
|
||||
ContactListItem(ContactListItem item,
|
||||
AttachmentHeader attachmentHeader) {
|
||||
ContactListItem(ContactListItem item, AttachmentHeader attachmentHeader) {
|
||||
this(item.getContact(), new AuthorInfo(item.getAuthorInfo().getStatus(),
|
||||
item.getAuthorInfo().getAlias(), attachmentHeader),
|
||||
item.isConnected(), item.empty, item.unread, item.timestamp);
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.ContactAliasChangedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
@@ -141,6 +142,10 @@ public class ContactsViewModel extends DbViewModel implements EventListener {
|
||||
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
||||
updateItem(a.getContactId(), item -> new ContactListItem(item,
|
||||
a.getAttachmentHeader()), false);
|
||||
} else if (e instanceof ContactAliasChangedEvent) {
|
||||
ContactAliasChangedEvent c = (ContactAliasChangedEvent) e;
|
||||
updateItem(c.getContactId(),
|
||||
item -> new ContactListItem(item, c.getAlias()), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user