mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
list position save and restore now implemented for threaded lists
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.briar.client;
|
||||
|
||||
public interface MessageTrackerConstants {
|
||||
|
||||
String GROUP_KEY_STORED_MESSAGE_ID = "storedMessageId";
|
||||
String GROUP_KEY_MSG_COUNT = "messageCount";
|
||||
String GROUP_KEY_UNREAD_COUNT = "unreadCount";
|
||||
String GROUP_KEY_LATEST_MSG = "latestMessageTime";
|
||||
|
||||
@@ -13,11 +13,13 @@ import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.client.MessageTracker;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
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.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||
|
||||
@@ -57,6 +59,30 @@ class MessageTrackerImpl implements MessageTracker {
|
||||
latestMsgTime));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MessageId loadStoredMessageId(GroupId g) throws DbException {
|
||||
try {
|
||||
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(g);
|
||||
byte[] msgBytes = d.getOptionalRaw(GROUP_KEY_STORED_MESSAGE_ID);
|
||||
return msgBytes != null? new MessageId(msgBytes) : null;
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeMessageId(GroupId g, MessageId m) throws DbException {
|
||||
BdfDictionary d = BdfDictionary.of(
|
||||
new BdfEntry(GROUP_KEY_STORED_MESSAGE_ID, m)
|
||||
);
|
||||
try {
|
||||
clientHelper.mergeGroupMetadata(g, d);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCount getGroupCount(GroupId g) throws DbException {
|
||||
GroupCount count;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.briarproject.briar.forum;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.briar.api.forum.Forum;
|
||||
import org.briarproject.briar.api.forum.ForumManager;
|
||||
import org.briarproject.briar.api.forum.ForumPost;
|
||||
@@ -10,6 +13,7 @@ import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||
import org.briarproject.briar.test.BriarIntegrationTest;
|
||||
import org.briarproject.briar.test.BriarIntegrationTestComponent;
|
||||
import org.briarproject.briar.test.DaggerBriarIntegrationTestComponent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -223,4 +227,18 @@ public class ForumManagerTest
|
||||
assertEquals(1, forumManager1.getPostHeaders(g1).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageStoreAndLoad() {
|
||||
MessageId msgId = new MessageId(TestUtils.getRandomId());
|
||||
MessageId loadedId = null;
|
||||
try {
|
||||
messageTracker0.storeMessageId(groupId0, msgId);
|
||||
loadedId = messageTracker0.loadStoredMessageId(groupId0);
|
||||
} catch (DbException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(loadedId);
|
||||
Assert.assertTrue(msgId.equals(loadedId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user