Commit 3fe7aae9 authored by Torsten Grote's avatar Torsten Grote

Contact aliases: address review comments

parent ecf417c9
......@@ -96,6 +96,12 @@ public interface ContactManager {
void setContactActive(Transaction txn, ContactId c, boolean active)
throws DbException;
/**
* Sets an alias name for the contact or unsets it if alias is null.
*/
void setContactAlias(Transaction txn, ContactId c, @Nullable String alias)
throws DbException;
/**
* Sets an alias name for the contact or unsets it if alias is null.
*/
......
......@@ -163,14 +163,20 @@ class ContactManagerImpl implements ContactManager {
}
@Override
public void setContactAlias(ContactId c, @Nullable String alias)
throws DbException {
public void setContactAlias(Transaction txn, ContactId c,
@Nullable String alias) throws DbException {
if (alias != null) {
int aliasLength = toUtf8(alias).length;
if (aliasLength == 0 || aliasLength > MAX_AUTHOR_NAME_LENGTH)
throw new IllegalArgumentException();
}
db.transaction(false, txn -> db.setContactAlias(txn, c, alias));
db.setContactAlias(txn, c, alias);
}
@Override
public void setContactAlias(ContactId c, @Nullable String alias)
throws DbException {
db.transaction(false, txn -> setContactAlias(txn, c, alias));
}
@Override
......
......@@ -204,7 +204,8 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test(expected = IllegalArgumentException.class)
public void testSetContactAliasTooLong() throws Exception {
contactManager.setContactAlias(contactId,
Transaction txn = new Transaction(null, false);
contactManager.setContactAlias(txn, contactId,
getRandomString(MAX_AUTHOR_NAME_LENGTH + 1));
}
......
......@@ -10,7 +10,6 @@ import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder;
import org.briarproject.briar.android.threaded.ThreadItemAdapter.ThreadItemListener;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
@UiThread
@NotNullByDefault
......@@ -37,8 +36,7 @@ class JoinMessageItemViewHolder
if (item.isInitial()) {
textView.setText(R.string.groups_member_created_you);
} else {
String name = getContactDisplayName(item.getAuthor(),
item.getAuthorInfo().getAlias());
String name = item.getAuthorName();
textView.setText(getContext()
.getString(R.string.groups_member_joined, name));
}
......@@ -46,8 +44,7 @@ class JoinMessageItemViewHolder
private void bind(JoinMessageItem item) {
Context ctx = getContext();
String name = getContactDisplayName(item.getAuthor(),
item.getAuthorInfo().getAlias());
String name = item.getAuthorName();
if (item.isInitial()) {
textView.setText(
......
......@@ -10,6 +10,7 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import static org.briarproject.briar.android.threaded.ThreadItemAdapter.UNDEFINED;
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
@NotThreadSafe
@NotNullByDefault
......@@ -70,6 +71,13 @@ public abstract class ThreadItem implements MessageNode {
return authorInfo;
}
/**
* Returns the author's name, with an alias if one exists.
*/
public String getAuthorName() {
return getContactDisplayName(author, authorInfo.getAlias());
}
@Override
public void setLevel(int level) {
this.level = level;
......
......@@ -141,7 +141,7 @@ public class UiUtils {
}
public static Spanned getSpanned(@Nullable String s) {
// TODO move to HtmlCompat
// TODO move to HtmlCompat #1435
// https://commonsware.com/blog/2018/05/29/at-last-htmlcompat.html
return Html.fromHtml(s);
}
......
......@@ -421,19 +421,14 @@ class IntroductionManagerImpl extends ConversationClientImpl
if (ss == null) throw new AssertionError();
MessageType type = meta.getMessageType();
if (type == REQUEST) {
messages.add(
parseInvitationRequest(txn, contactGroupId, m,
meta, status, ss.bdfSession, authorInfos));
messages.add(parseInvitationRequest(txn, contactGroupId, m,
meta, status, ss.bdfSession, authorInfos));
} else if (type == ACCEPT) {
messages.add(
parseInvitationResponse(txn, contactGroupId, m,
meta, status, ss.bdfSession, authorInfos,
true));
messages.add(parseInvitationResponse(txn, contactGroupId, m,
meta, status, ss.bdfSession, authorInfos, true));
} else if (type == DECLINE) {
messages.add(
parseInvitationResponse(txn, contactGroupId, m,
meta, status, ss.bdfSession, authorInfos,
false));
messages.add(parseInvitationResponse(txn, contactGroupId, m,
meta, status, ss.bdfSession, authorInfos, false));
}
}
return messages;
......
......@@ -174,6 +174,10 @@ public class TestDataCreatorImpl implements TestDataCreator {
ContactId contactId = contactManager
.addContact(txn, author, localAuthorId, secretKey,
timestamp, true, verified, true);
if (random.nextBoolean()) {
contactManager
.setContactAlias(txn, contactId, getRandomAuthorName());
}
transportPropertyManager.addRemoteProperties(txn, contactId, props);
contact = db.getContact(txn, contactId);
db.commitTransaction(txn);
......@@ -202,10 +206,13 @@ public class TestDataCreatorImpl implements TestDataCreator {
return authorFactory.createLocalAuthor(name, publicKey, privateKey);
}
private LocalAuthor getRandomAuthor() {
private String getRandomAuthorName() {
int i = random.nextInt(AUTHOR_NAMES.length);
String authorName = AUTHOR_NAMES[i];
return getAuthor(authorName);
return AUTHOR_NAMES[i];
}
private LocalAuthor getRandomAuthor() {
return getAuthor(getRandomAuthorName());
}
private SecretKey getSecretKey() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment