mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch '1944-update-contact-list-when-changing-aliases' into 'master'
Broadcast ContactAliasChangedEvent to update contact list Closes #1944 See merge request briar/briar!1425
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.briarproject.bramble.api.contact.event;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when the alias for a contact changed.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class ContactAliasChangedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
@Nullable
|
||||
private final String alias;
|
||||
|
||||
public ContactAliasChangedEvent(ContactId contactId,
|
||||
@Nullable String alias) {
|
||||
this.contactId = contactId;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.contact.PendingContact;
|
||||
import org.briarproject.bramble.api.contact.PendingContactId;
|
||||
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.contact.event.ContactVerifiedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent;
|
||||
@@ -1013,6 +1014,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsContact(txn, c))
|
||||
throw new NoSuchContactException();
|
||||
transaction.attach(new ContactAliasChangedEvent(c, alias));
|
||||
db.setContactAlias(txn, c, alias);
|
||||
}
|
||||
|
||||
|
||||
@@ -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