diff --git a/briar-android/res/drawable-hdpi/contact_connected.png b/briar-android/res/drawable-hdpi/contact_connected.png index 6c9f76c4522f49d5239cb10ade1d8e5964427f0a..9fa452b33cdc41c6771b7df4bd6d24c60458d851 100644 Binary files a/briar-android/res/drawable-hdpi/contact_connected.png and b/briar-android/res/drawable-hdpi/contact_connected.png differ diff --git a/briar-android/res/drawable-hdpi/contact_disconnected.png b/briar-android/res/drawable-hdpi/contact_disconnected.png index 4a1053fc7d3f76039fbc93c9fb1dffd1fd5e2af1..9de4968499c5c464a53beb423088bbe7c618b5b4 100644 Binary files a/briar-android/res/drawable-hdpi/contact_disconnected.png and b/briar-android/res/drawable-hdpi/contact_disconnected.png differ diff --git a/briar-android/res/drawable-hdpi/identity_anonymous.png b/briar-android/res/drawable-hdpi/identity_anonymous.png new file mode 100644 index 0000000000000000000000000000000000000000..aa539d31b7aad168d93e4d2a45a28a6c3af18c7f Binary files /dev/null and b/briar-android/res/drawable-hdpi/identity_anonymous.png differ diff --git a/briar-android/res/drawable-hdpi/identity_unknown.png b/briar-android/res/drawable-hdpi/identity_unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..b098e93aaea14e2c907662ff93b1f09f314f8bb3 Binary files /dev/null and b/briar-android/res/drawable-hdpi/identity_unknown.png differ diff --git a/briar-android/res/drawable-hdpi/identity_unverified.png b/briar-android/res/drawable-hdpi/identity_unverified.png new file mode 100644 index 0000000000000000000000000000000000000000..f9e2486261cf419e1a629e08bf671dc5034334c5 Binary files /dev/null and b/briar-android/res/drawable-hdpi/identity_unverified.png differ diff --git a/briar-android/res/drawable-hdpi/identity_verified.png b/briar-android/res/drawable-hdpi/identity_verified.png new file mode 100644 index 0000000000000000000000000000000000000000..02e819fa1023e98c5124d9cdb17b9ee85629c766 Binary files /dev/null and b/briar-android/res/drawable-hdpi/identity_verified.png differ diff --git a/briar-android/res/drawable-mdpi/contact_connected.png b/briar-android/res/drawable-mdpi/contact_connected.png index c7fb72a6d4c947ae698fee1275bd4427477986c0..22c0771bc14f2c4c8d8b31eacbc5b0f16c3126ef 100644 Binary files a/briar-android/res/drawable-mdpi/contact_connected.png and b/briar-android/res/drawable-mdpi/contact_connected.png differ diff --git a/briar-android/res/drawable-mdpi/contact_disconnected.png b/briar-android/res/drawable-mdpi/contact_disconnected.png index 790357f4e5d8e306028516269cd39a708f7bb017..bef15c40b285d783f8586d6e0af2476ec8c609d7 100644 Binary files a/briar-android/res/drawable-mdpi/contact_disconnected.png and b/briar-android/res/drawable-mdpi/contact_disconnected.png differ diff --git a/briar-android/res/drawable-mdpi/identity_anonymous.png b/briar-android/res/drawable-mdpi/identity_anonymous.png new file mode 100644 index 0000000000000000000000000000000000000000..c91a016de8d6f692e8850f77156e4b0d5af82852 Binary files /dev/null and b/briar-android/res/drawable-mdpi/identity_anonymous.png differ diff --git a/briar-android/res/drawable-mdpi/identity_unknown.png b/briar-android/res/drawable-mdpi/identity_unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..6ad29f8a0fa134f02856cdaf1de831cce8158b28 Binary files /dev/null and b/briar-android/res/drawable-mdpi/identity_unknown.png differ diff --git a/briar-android/res/drawable-mdpi/identity_unverified.png b/briar-android/res/drawable-mdpi/identity_unverified.png new file mode 100644 index 0000000000000000000000000000000000000000..9b8a13d4bfe10e6a710842ae079324dba4234c2b Binary files /dev/null and b/briar-android/res/drawable-mdpi/identity_unverified.png differ diff --git a/briar-android/res/drawable-mdpi/identity_verified.png b/briar-android/res/drawable-mdpi/identity_verified.png new file mode 100644 index 0000000000000000000000000000000000000000..79cbaedc29a153ed0df16987b656ce659a876b1b Binary files /dev/null and b/briar-android/res/drawable-mdpi/identity_verified.png differ diff --git a/briar-android/res/drawable-xhdpi/contact_connected.png b/briar-android/res/drawable-xhdpi/contact_connected.png index 53c5273b9c9c95efbf6a66eb03b12c7918498f30..4341f01a1a16797592c31e81c119d260cff7f9c9 100644 Binary files a/briar-android/res/drawable-xhdpi/contact_connected.png and b/briar-android/res/drawable-xhdpi/contact_connected.png differ diff --git a/briar-android/res/drawable-xhdpi/contact_disconnected.png b/briar-android/res/drawable-xhdpi/contact_disconnected.png index 9a398fba118a854f2bc778424cf318d316c45a55..d0499ddf1ffb6335c4b4f48d42ffed128d863a62 100644 Binary files a/briar-android/res/drawable-xhdpi/contact_disconnected.png and b/briar-android/res/drawable-xhdpi/contact_disconnected.png differ diff --git a/briar-android/res/drawable-xhdpi/identity_anonymous.png b/briar-android/res/drawable-xhdpi/identity_anonymous.png new file mode 100644 index 0000000000000000000000000000000000000000..c8f254fdac6b62ee348a82b48d5e166eeb6cfb11 Binary files /dev/null and b/briar-android/res/drawable-xhdpi/identity_anonymous.png differ diff --git a/briar-android/res/drawable-xhdpi/identity_unknown.png b/briar-android/res/drawable-xhdpi/identity_unknown.png new file mode 100644 index 0000000000000000000000000000000000000000..e3b91a85841af0985cc2635ea3ec9e516719520e Binary files /dev/null and b/briar-android/res/drawable-xhdpi/identity_unknown.png differ diff --git a/briar-android/res/drawable-xhdpi/identity_unverified.png b/briar-android/res/drawable-xhdpi/identity_unverified.png new file mode 100644 index 0000000000000000000000000000000000000000..85785c09cceadbf4357e8ac8e0f25366ab5c5f19 Binary files /dev/null and b/briar-android/res/drawable-xhdpi/identity_unverified.png differ diff --git a/briar-android/res/drawable-xhdpi/identity_verified.png b/briar-android/res/drawable-xhdpi/identity_verified.png new file mode 100644 index 0000000000000000000000000000000000000000..d93ae1df22bc1530da908a3ad53d12b92e68da8d Binary files /dev/null and b/briar-android/res/drawable-xhdpi/identity_verified.png differ diff --git a/briar-android/res/values/color.xml b/briar-android/res/values/color.xml index d9fb00b4c6b69686240b485522c1e72aaf55e8e0..c7cc015fe1b363703b9d5a35ac101718e30b519f 100644 --- a/briar-android/res/values/color.xml +++ b/briar-android/res/values/color.xml @@ -4,7 +4,6 @@ <color name="content_background">#FFFFFF</color> <color name="unread_background">#FFFFFF</color> <color name="horizontal_border">#CCCCCC</color> - <color name="anonymous_author">#AAAAAA</color> <color name="no_posts">#AAAAAA</color> <color name="no_messages">#AAAAAA</color> </resources> \ No newline at end of file diff --git a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java index d36a862bdc6a951b8efdd7e4fe45df14751df538..7fe48d2980153a6879ae3700dbe80a57b46c42e7 100644 --- a/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java +++ b/briar-android/src/org/briarproject/android/contact/ConversationAdapter.java @@ -3,10 +3,12 @@ package org.briarproject.android.contact; import static android.widget.LinearLayout.HORIZONTAL; import static java.text.DateFormat.SHORT; import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1; +import static org.briarproject.api.Author.Status.VERIFIED; import java.util.ArrayList; import org.briarproject.R; +import org.briarproject.android.util.AuthorView; import org.briarproject.android.util.LayoutUtils; import org.briarproject.api.db.MessageHeader; @@ -41,14 +43,10 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> { layout.setBackgroundColor(res.getColor(R.color.unread_background)); } - TextView name = new TextView(ctx); - // Give me all the unused width - name.setLayoutParams(WRAP_WRAP_1); - name.setTextSize(18); - name.setMaxLines(1); - name.setPadding(pad, pad, pad, pad); - name.setText(header.getAuthor().getName()); - layout.addView(name); + AuthorView authorView = new AuthorView(ctx); + authorView.setLayoutParams(WRAP_WRAP_1); + authorView.init(header.getAuthor().getName(), VERIFIED); + layout.addView(authorView); TextView date = new TextView(ctx); date.setTextSize(14); diff --git a/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java b/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java index 932e6b49cf5dcd2f800609c5c5771ad445a553a9..06c72712ac9bd69677663c678065b945bede152d 100644 --- a/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java +++ b/briar-android/src/org/briarproject/android/contact/ReadPrivateMessageActivity.java @@ -10,6 +10,7 @@ import static java.util.logging.Level.WARNING; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1; import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1; +import static org.briarproject.api.Author.Status.VERIFIED; import java.io.UnsupportedEncodingException; import java.util.concurrent.Executor; @@ -18,8 +19,9 @@ import java.util.logging.Logger; import javax.inject.Inject; import org.briarproject.R; -import org.briarproject.android.util.HorizontalBorder; +import org.briarproject.android.util.AuthorView; import org.briarproject.android.util.ElasticHorizontalSpace; +import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.LayoutUtils; import org.briarproject.api.AuthorId; import org.briarproject.api.android.DatabaseUiExecutor; @@ -116,16 +118,12 @@ implements OnClickListener { header.setOrientation(HORIZONTAL); header.setGravity(CENTER_VERTICAL); - int pad = LayoutUtils.getPadding(this); + AuthorView author = new AuthorView(this); + author.setLayoutParams(WRAP_WRAP_1); + author.init(authorName, VERIFIED); + header.addView(author); - TextView name = new TextView(this); - // Give me all the unused width - name.setLayoutParams(WRAP_WRAP_1); - name.setTextSize(18); - name.setMaxLines(1); - name.setPadding(pad, pad, pad, pad); - name.setText(authorName); - header.addView(name); + int pad = LayoutUtils.getPadding(this); TextView date = new TextView(this); date.setTextSize(14); diff --git a/briar-android/src/org/briarproject/android/groups/GroupActivity.java b/briar-android/src/org/briarproject/android/groups/GroupActivity.java index 11ff72b1e30df43116e53cf54cf40da84b3e0c8d..629a73b4396beba931c8b162494ef3e8c05eb141 100644 --- a/briar-android/src/org/briarproject/android/groups/GroupActivity.java +++ b/briar-android/src/org/briarproject/android/groups/GroupActivity.java @@ -230,6 +230,7 @@ OnClickListener, OnItemClickListener { i.putExtra("briar.AUTHOR_ID", author.getId().getBytes()); i.putExtra("briar.AUTHOR_NAME", author.getName()); } + i.putExtra("briar.AUTHOR_STATUS", item.getAuthorStatus().name()); i.putExtra("briar.CONTENT_TYPE", item.getContentType()); i.putExtra("briar.TIMESTAMP", item.getTimestamp()); startActivityForResult(i, position); diff --git a/briar-android/src/org/briarproject/android/groups/GroupAdapter.java b/briar-android/src/org/briarproject/android/groups/GroupAdapter.java index 4900e2f3e179e96caa0afe27a360419232821e72..25195e5d3aa3045878c1321a1be09c59fb201a03 100644 --- a/briar-android/src/org/briarproject/android/groups/GroupAdapter.java +++ b/briar-android/src/org/briarproject/android/groups/GroupAdapter.java @@ -7,6 +7,7 @@ import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1; import java.util.ArrayList; import org.briarproject.R; +import org.briarproject.android.util.AuthorView; import org.briarproject.android.util.LayoutUtils; import org.briarproject.api.Author; import org.briarproject.api.db.MessageHeader; @@ -32,34 +33,27 @@ class GroupAdapter extends ArrayAdapter<MessageHeader> { @Override public View getView(int position, View convertView, ViewGroup parent) { - MessageHeader item = getItem(position); + MessageHeader header = getItem(position); Context ctx = getContext(); - Resources res = ctx.getResources(); LinearLayout layout = new LinearLayout(ctx); layout.setOrientation(HORIZONTAL); - if(!item.isRead()) + if(!header.isRead()) { + Resources res = ctx.getResources(); layout.setBackgroundColor(res.getColor(R.color.unread_background)); - - TextView name = new TextView(ctx); - // Give me all the unused width - name.setLayoutParams(WRAP_WRAP_1); - name.setTextSize(18); - name.setMaxLines(1); - name.setPadding(pad, pad, pad, pad); - Author author = item.getAuthor(); - if(author == null) { - name.setTextColor(res.getColor(R.color.anonymous_author)); - name.setText(R.string.anonymous); - } else { - name.setText(author.getName()); } - layout.addView(name); + + AuthorView authorView = new AuthorView(ctx); + authorView.setLayoutParams(WRAP_WRAP_1); + Author author = header.getAuthor(); + if(author == null) authorView.init(null, header.getAuthorStatus()); + else authorView.init(author.getName(), header.getAuthorStatus()); + layout.addView(authorView); TextView date = new TextView(ctx); date.setTextSize(14); - date.setPadding(pad, pad, pad, pad); - long then = item.getTimestamp(), now = System.currentTimeMillis(); + date.setPadding(0, pad, pad, pad); + long then = header.getTimestamp(), now = System.currentTimeMillis(); date.setText(DateUtils.formatSameDayTime(then, now, SHORT, SHORT)); layout.addView(date); diff --git a/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java b/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java index 83e97520dfa1561173af8151743a6318d2f6e144..d4591a8e3758456a189fb956148d71fb944e03ad 100644 --- a/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java +++ b/briar-android/src/org/briarproject/android/groups/ReadGroupPostActivity.java @@ -18,9 +18,11 @@ import java.util.logging.Logger; import javax.inject.Inject; import org.briarproject.R; -import org.briarproject.android.util.HorizontalBorder; +import org.briarproject.android.util.AuthorView; import org.briarproject.android.util.ElasticHorizontalSpace; +import org.briarproject.android.util.HorizontalBorder; import org.briarproject.android.util.LayoutUtils; +import org.briarproject.api.Author; import org.briarproject.api.android.DatabaseUiExecutor; import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DbException; @@ -83,6 +85,9 @@ implements OnClickListener { timestamp = i.getLongExtra("briar.TIMESTAMP", -1); if(timestamp == -1) throw new IllegalStateException(); String authorName = i.getStringExtra("briar.AUTHOR_NAME"); + String s = i.getStringExtra("briar.AUTHOR_STATUS"); + if(s == null) throw new IllegalStateException(); + Author.Status authorStatus = Author.Status.valueOf(s); if(state == null) { read = false; @@ -109,21 +114,12 @@ implements OnClickListener { header.setOrientation(HORIZONTAL); header.setGravity(CENTER_VERTICAL); - int pad = LayoutUtils.getPadding(this); + AuthorView author = new AuthorView(this); + author.setLayoutParams(WRAP_WRAP_1); + author.init(authorName, authorStatus); + header.addView(author); - TextView name = new TextView(this); - // Give me all the unused width - name.setLayoutParams(WRAP_WRAP_1); - name.setTextSize(18); - name.setMaxLines(1); - name.setPadding(pad, pad, pad, pad); - if(authorName == null) { - name.setTextColor(res.getColor(R.color.anonymous_author)); - name.setText(R.string.anonymous); - } else { - name.setText(authorName); - } - header.addView(name); + int pad = LayoutUtils.getPadding(this); TextView date = new TextView(this); date.setTextSize(14); diff --git a/briar-android/src/org/briarproject/android/util/AuthorView.java b/briar-android/src/org/briarproject/android/util/AuthorView.java new file mode 100644 index 0000000000000000000000000000000000000000..fbb2d8e775554f3a9c8fa48f740aa84cf10afe62 --- /dev/null +++ b/briar-android/src/org/briarproject/android/util/AuthorView.java @@ -0,0 +1,51 @@ +package org.briarproject.android.util; + +import org.briarproject.R; +import org.briarproject.api.Author; + +import android.content.Context; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class AuthorView extends LinearLayout { + + public AuthorView(Context ctx) { + super(ctx); + } + + public void init(String name, Author.Status status) { + Context ctx = getContext(); + int pad = LayoutUtils.getPadding(ctx); + setOrientation(VERTICAL); + TextView nameView = new TextView(ctx); + // Give me all the unused width + nameView.setTextSize(18); + nameView.setMaxLines(1); + nameView.setPadding(pad, pad, pad, pad); + if(name == null) nameView.setText(R.string.anonymous); + else nameView.setText(name); + addView(nameView); + LinearLayout statusLayout = new LinearLayout(ctx); + statusLayout.setOrientation(HORIZONTAL); + ImageView statusView = new ImageView(ctx); + statusView.setPadding(pad, 0, pad, pad); + switch(status) { + case ANONYMOUS: + statusView.setImageResource(R.drawable.identity_anonymous); + break; + case UNKNOWN: + statusView.setImageResource(R.drawable.identity_unknown); + break; + case UNVERIFIED: + statusView.setImageResource(R.drawable.identity_unverified); + break; + case VERIFIED: + statusView.setImageResource(R.drawable.identity_verified); + break; + } + statusLayout.addView(statusView); + statusLayout.addView(new ElasticHorizontalSpace(ctx)); + addView(statusLayout); + } +} diff --git a/briar-api/src/org/briarproject/api/Author.java b/briar-api/src/org/briarproject/api/Author.java index 16693137b139a760ee787df79b0a5ab6b18d32b7..0ff392f9f964cccb6e0a1c857a6ffeacde2fb79b 100644 --- a/briar-api/src/org/briarproject/api/Author.java +++ b/briar-api/src/org/briarproject/api/Author.java @@ -7,6 +7,8 @@ import java.io.UnsupportedEncodingException; /** A pseudonym for a user. */ public class Author { + public enum Status { ANONYMOUS, UNKNOWN, UNVERIFIED, VERIFIED }; + private final AuthorId id; private final String name; private final byte[] publicKey; diff --git a/briar-api/src/org/briarproject/api/db/MessageHeader.java b/briar-api/src/org/briarproject/api/db/MessageHeader.java index 64831d9fe7359c73d063581ad343bcfa52f6d3f7..4a1b2054b348290dad7343714001d6fb33bcc3bc 100644 --- a/briar-api/src/org/briarproject/api/db/MessageHeader.java +++ b/briar-api/src/org/briarproject/api/db/MessageHeader.java @@ -9,16 +9,19 @@ public class MessageHeader { private final MessageId id, parent; private final GroupId groupId; private final Author author; + private final Author.Status authorStatus; private final String contentType; private final long timestamp; private final boolean read; public MessageHeader(MessageId id, MessageId parent, GroupId groupId, - Author author, String contentType, long timestamp, boolean read) { + Author author, Author.Status authorStatus, String contentType, + long timestamp, boolean read) { this.id = id; this.parent = parent; this.groupId = groupId; this.author = author; + this.authorStatus = authorStatus; this.contentType = contentType; this.timestamp = timestamp; this.read = read; @@ -51,6 +54,11 @@ public class MessageHeader { return author; } + /** Returns the status of the message's author. */ + public Author.Status getAuthorStatus() { + return authorStatus; + } + /** Returns the message's content type. */ public String getContentType() { return contentType; diff --git a/briar-core/src/org/briarproject/db/JdbcDatabase.java b/briar-core/src/org/briarproject/db/JdbcDatabase.java index ce5f74aab9097a3c24b1dd440bcd9e6d9c65d306..004c0787b144ba8ae1a8ddb03319f9d35473b8c0 100644 --- a/briar-core/src/org/briarproject/db/JdbcDatabase.java +++ b/briar-core/src/org/briarproject/db/JdbcDatabase.java @@ -4,6 +4,9 @@ import static java.sql.Types.BINARY; import static java.sql.Types.VARCHAR; import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; +import static org.briarproject.api.Author.Status.ANONYMOUS; +import static org.briarproject.api.Author.Status.UNKNOWN; +import static org.briarproject.api.Author.Status.VERIFIED; import static org.briarproject.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS; import static org.briarproject.api.messaging.MessagingConstants.RETENTION_GRANULARITY; import static org.briarproject.db.ExponentialBackoff.calculateExpiry; @@ -1525,10 +1528,12 @@ abstract class JdbcDatabase implements Database<Connection> { boolean read = rs.getBoolean(7); if(incoming) { headers.add(new MessageHeader(id, parent, groupId, - remoteAuthor, contentType, timestamp, read)); + remoteAuthor, VERIFIED, contentType, timestamp, + read)); } else { headers.add(new MessageHeader(id, parent, groupId, - localAuthor, contentType, timestamp, read)); + localAuthor, VERIFIED, contentType, timestamp, + read)); } } rs.close(); @@ -1701,9 +1706,14 @@ abstract class JdbcDatabase implements Database<Connection> { PreparedStatement ps = null; ResultSet rs = null; try { - String sql = "SELECT messageId, parentId, authorId, authorName," - + " authorKey, contentType, timestamp, read" - + " FROM messages" + String sql = "SELECT messageId, parentId, m.authorId, authorName," + + " authorKey, contentType, timestamp, read," + + " la.authorId IS NOT NULL, c.authorId IS NOT NULL" + + " FROM messages AS m" + + " LEFT OUTER JOIN localAuthors AS la" + + " ON m.authorId = la.authorId" + + " LEFT OUTER JOIN contacts AS c" + + " ON m.authorId = c.authorId" + " WHERE groupId = ?"; ps = txn.prepareStatement(sql); ps.setBytes(1, g.getBytes()); @@ -1726,8 +1736,14 @@ abstract class JdbcDatabase implements Database<Connection> { String contentType = rs.getString(6); long timestamp = rs.getLong(7); boolean read = rs.getBoolean(8); + boolean isSelf = rs.getBoolean(9); + boolean isContact = rs.getBoolean(10); + Author.Status authorStatus; + if(author == null) authorStatus = ANONYMOUS; + else if(isSelf || isContact) authorStatus = VERIFIED; + else authorStatus = UNKNOWN; headers.add(new MessageHeader(id, parent, g, author, - contentType, timestamp, read)); + authorStatus, contentType, timestamp, read)); } rs.close(); ps.close(); diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java index 1799cfb6429d88c8a4947efc6994fe84901e024b..37a4c944f2d572ffb16dde52ef5fb2a1722d6928 100644 --- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java +++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java @@ -41,7 +41,6 @@ import org.briarproject.api.messaging.MessageId; import org.briarproject.api.transport.Endpoint; import org.briarproject.api.transport.TemporarySecret; import org.briarproject.system.SystemClock; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -898,42 +897,26 @@ public class H2DatabaseTest extends BriarTestCase { // Mark one of the messages read db.setReadFlag(txn, messageId, true); - // Retrieve the message headers + // Retrieve the message headers (order is undefined) Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId); - Iterator<MessageHeader> it = headers.iterator(); - boolean messageFound = false, message1Found = false; - // First header (order is undefined) - assertTrue(it.hasNext()); - MessageHeader header = it.next(); - if(messageId.equals(header.getId())) { - assertHeadersMatch(message, header); - assertTrue(header.isRead()); - messageFound = true; - } else if(messageId1.equals(header.getId())) { - assertHeadersMatch(message1, header); - assertFalse(header.isRead()); - message1Found = true; - } else { - fail(); - } - // Second header - assertTrue(it.hasNext()); - header = it.next(); - if(messageId.equals(header.getId())) { - assertHeadersMatch(message, header); - assertTrue(header.isRead()); - messageFound = true; - } else if(messageId1.equals(header.getId())) { - assertHeadersMatch(message1, header); - assertFalse(header.isRead()); - message1Found = true; - } else { - fail(); + assertEquals(2, headers.size()); + boolean firstFound = false, secondFound = false; + for(MessageHeader header : headers) { + if(messageId.equals(header.getId())) { + assertHeadersMatch(message, header); + assertTrue(header.isRead()); + firstFound = true; + } else if(messageId1.equals(header.getId())) { + assertHeadersMatch(message1, header); + assertFalse(header.isRead()); + secondFound = true; + } else { + fail(); + } } - // No more headers - assertFalse(it.hasNext()); - assertTrue(messageFound); - assertTrue(message1Found); + // Both the headers should have been retrieved + assertTrue(firstFound); + assertTrue(secondFound); db.commitTransaction(txn); db.close(); @@ -950,6 +933,62 @@ public class H2DatabaseTest extends BriarTestCase { assertEquals(m.getTimestamp(), h.getTimestamp()); } + @Test + public void testAuthorStatus() throws Exception { + Database<Connection> db = open(false); + Connection txn = db.startTransaction(); + + // Add a contact and subscribe to a group + db.addLocalAuthor(txn, localAuthor); + assertEquals(contactId, db.addContact(txn, author, localAuthorId)); + db.addGroup(txn, group); + + // Store a message from the contact - status VERIFIED + db.addMessage(txn, message, false); + AuthorId authorId1 = new AuthorId(TestUtils.getRandomId()); + // Store a message from an unknown author - status UNKNOWN + Author author1 = new Author(authorId1, "Bob", + new byte[MAX_PUBLIC_KEY_LENGTH]); + MessageId messageId1 = new MessageId(TestUtils.getRandomId()); + Message message1 = new TestMessage(messageId1, null, group, author1, + contentType, subject, timestamp, raw); + db.addMessage(txn, message1, false); + // Store an anonymous message - status ANONYMOUS + MessageId messageId2 = new MessageId(TestUtils.getRandomId()); + Message message2 = new TestMessage(messageId2, null, group, null, + contentType, subject, timestamp, raw); + db.addMessage(txn, message2, false); + + // Retrieve the message headers (order is undefined) + Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId); + assertEquals(3, headers.size()); + boolean firstFound = false, secondFound = false, thirdFound = false; + for(MessageHeader header : headers) { + if(messageId.equals(header.getId())) { + assertHeadersMatch(message, header); + assertEquals(Author.Status.VERIFIED, header.getAuthorStatus()); + firstFound = true; + } else if(messageId1.equals(header.getId())) { + assertHeadersMatch(message1, header); + assertEquals(Author.Status.UNKNOWN, header.getAuthorStatus()); + secondFound = true; + } else if(messageId2.equals(header.getId())) { + assertHeadersMatch(message2, header); + assertEquals(Author.Status.ANONYMOUS, header.getAuthorStatus()); + thirdFound = true; + } else { + fail(); + } + } + // All of the headers should have been retrieved + assertTrue(firstFound); + assertTrue(secondFound); + assertTrue(thirdFound); + + db.commitTransaction(txn); + db.close(); + } + @Test public void testReadFlag() throws Exception { Database<Connection> db = open(false);