mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch '1501-new-contacts-at-top' into 'master'
Display new contacts at the top of the contact list Closes #1501 See merge request briar/briar!1063
This commit is contained in:
@@ -12,6 +12,12 @@ import javax.annotation.Nullable;
|
||||
@NotNullByDefault
|
||||
public interface MessageTracker {
|
||||
|
||||
/**
|
||||
* Initializes the group count with zero messages,
|
||||
* but uses the current time as latest message time for sorting.
|
||||
*/
|
||||
void initializeGroupCount(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Gets the number of visible and unread messages in the group
|
||||
* as well as the timestamp of the latest message
|
||||
|
||||
@@ -31,6 +31,15 @@ public abstract class ConversationClientImpl extends BdfIncomingMessageHook
|
||||
this.messageTracker = messageTracker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the group count with zero messages,
|
||||
* but uses the current time as latest message time for sorting.
|
||||
*/
|
||||
protected void initializeGroupCount(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
messageTracker.initializeGroupCount(txn, g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCount getGroupCount(Transaction txn, ContactId contactId)
|
||||
throws DbException {
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -29,11 +30,22 @@ class MessageTrackerImpl implements MessageTracker {
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final ClientHelper clientHelper;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
MessageTrackerImpl(DatabaseComponent db, ClientHelper clientHelper) {
|
||||
MessageTrackerImpl(DatabaseComponent db, ClientHelper clientHelper,
|
||||
Clock clock) {
|
||||
this.db = db;
|
||||
this.clientHelper = clientHelper;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeGroupCount(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
long now = clock.currentTimeMillis();
|
||||
GroupCount groupCount = new GroupCount(0, 0, now);
|
||||
storeGroupCount(txn, g, groupCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -93,6 +93,8 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
// Initialize the group count with current time
|
||||
initializeGroupCount(txn, g.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,16 +4,22 @@ import org.briarproject.bramble.api.client.ClientHelper;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.GROUP_KEY_LATEST_MSG;
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.GROUP_KEY_MSG_COUNT;
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.GROUP_KEY_STORED_MESSAGE_ID;
|
||||
import static org.briarproject.briar.client.MessageTrackerConstants.GROUP_KEY_UNREAD_COUNT;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class MessageTrackerTest extends BrambleMockTestCase {
|
||||
|
||||
@@ -21,13 +27,31 @@ public class MessageTrackerTest extends BrambleMockTestCase {
|
||||
protected final ClientHelper clientHelper =
|
||||
context.mock(ClientHelper.class);
|
||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
private final MessageId messageId = new MessageId(TestUtils.getRandomId());
|
||||
private final MessageTracker messageTracker =
|
||||
new MessageTrackerImpl(db, clientHelper);
|
||||
new MessageTrackerImpl(db, clientHelper, clock);
|
||||
private final BdfDictionary dictionary = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_STORED_MESSAGE_ID, messageId)
|
||||
);
|
||||
|
||||
@Test
|
||||
public void testInitializeGroupCount() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
long now = 42L;
|
||||
BdfDictionary dictionary = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_MSG_COUNT, 0),
|
||||
new BdfEntry(GROUP_KEY_UNREAD_COUNT, 0),
|
||||
new BdfEntry(GROUP_KEY_LATEST_MSG, now)
|
||||
);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(clientHelper).mergeGroupMetadata(txn, groupId, dictionary);
|
||||
}});
|
||||
messageTracker.initializeGroupCount(txn, groupId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageStore() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
@@ -43,8 +67,8 @@ public class MessageTrackerTest extends BrambleMockTestCase {
|
||||
will(returnValue(dictionary));
|
||||
}});
|
||||
MessageId loadedId = messageTracker.loadStoredMessageId(groupId);
|
||||
Assert.assertNotNull(loadedId);
|
||||
Assert.assertTrue(messageId.equals(loadedId));
|
||||
assertNotNull(loadedId);
|
||||
assertEquals(messageId, loadedId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user