Add AttachmentHeader to AuthorInfo

This way the UI can retrieve the author's avatar (if it exists).
This commit is contained in:
Torsten Grote
2020-11-24 11:15:34 -03:00
parent d0d2e0ed82
commit c3cea37641
14 changed files with 196 additions and 102 deletions

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.api.avatar;
import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.ClientId;
import org.briarproject.briar.api.media.Attachment;
@@ -42,13 +43,14 @@ public interface AvatarManager {
* or null if none is known.
*/
@Nullable
AttachmentHeader getAvatarHeader(Contact c) throws DbException;
AttachmentHeader getAvatarHeader(Transaction txn, Contact c)
throws DbException;
/**
* Returns our current profile image header or null if none has been added.
*/
@Nullable
AttachmentHeader getMyAvatarHeader() throws DbException;
AttachmentHeader getMyAvatarHeader(Transaction txn) throws DbException;
/**
* Returns the profile image attachment for the given header.

View File

@@ -1,6 +1,7 @@
package org.briarproject.briar.api.identity;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.media.AttachmentHeader;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@@ -20,14 +21,18 @@ public class AuthorInfo {
private final Status status;
@Nullable
private final String alias;
@Nullable
private final AttachmentHeader avatarHeader;
public AuthorInfo(Status status, @Nullable String alias) {
public AuthorInfo(Status status, @Nullable String alias,
@Nullable AttachmentHeader avatarHeader) {
this.status = status;
this.alias = alias;
this.avatarHeader = avatarHeader;
}
public AuthorInfo(Status status) {
this(status, null);
this(status, null, null);
}
public Status getStatus() {
@@ -39,6 +44,11 @@ public class AuthorInfo {
return alias;
}
@Nullable
public AttachmentHeader getAvatarHeader() {
return avatarHeader;
}
@Override
public int hashCode() {
int hashCode = status.ordinal();
@@ -52,6 +62,11 @@ public class AuthorInfo {
AuthorInfo info = (AuthorInfo) o;
//noinspection EqualsReplaceableByObjectsCall
return status == info.status &&
(alias == null ? info.alias == null : alias.equals(info.alias));
// aliases are equal
(alias == null ? info.alias == null :
alias.equals(info.alias)) &&
// avatars are equal
(avatarHeader == null ? info.avatarHeader == null :
avatarHeader.equals(info.avatarHeader));
}
}

View File

@@ -3,6 +3,7 @@ package org.briarproject.briar.api.identity;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault
@@ -18,4 +19,8 @@ public interface AuthorManager {
*/
AuthorInfo getAuthorInfo(Transaction txn, AuthorId a) throws DbException;
/**
* Returns the {@link AuthorInfo} for the {@link LocalAuthor}.
*/
AuthorInfo getMyAuthorInfo(Transaction txn) throws DbException;
}