Store message count, unread count and timestamp of latest message

in group metadata to be able to speed up group listings.

Closes #584, #586, #585
This commit is contained in:
Torsten Grote
2016-10-04 13:37:29 -03:00
parent 3fa84ec7a8
commit a727a0817e
25 changed files with 421 additions and 141 deletions

View File

@@ -0,0 +1,44 @@
package org.briarproject.api.clients;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
public interface MessageTracker {
/**
* Gets the number of visible and unread messages in the group
* as well as the timestamp of the latest message
**/
GroupCount getGroupCount(GroupId g) throws DbException;
/**
* Marks a message as read or unread and updates the group counts in g.
**/
void setReadFlag(GroupId g, MessageId m, boolean read) throws DbException;
class GroupCount {
private final long msgCount, unreadCount, latestMsgTime;
public GroupCount(long msgCount, long unreadCount, long latestMsgTime) {
this.msgCount = msgCount;
this.unreadCount = unreadCount;
this.latestMsgTime = latestMsgTime;
}
public long getMsgCount() {
return msgCount;
}
public long getUnreadCount() {
return unreadCount;
}
public long getLatestMsgTime() {
return latestMsgTime;
}
}
}

View File

@@ -28,6 +28,5 @@ public interface ForumConstants {
String KEY_PUBLIC_NAME = "publicKey";
String KEY_AUTHOR = "author";
String KEY_LOCAL = "local";
String KEY_READ = "read";
}

View File

@@ -1,5 +1,6 @@
package org.briarproject.api.forum;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.sync.ClientId;
@@ -8,7 +9,7 @@ import org.briarproject.api.sync.MessageId;
import java.util.Collection;
public interface ForumManager {
public interface ForumManager extends MessageTracker {
/** Returns the unique ID of the forum client. */
ClientId getClientId();
@@ -37,9 +38,6 @@ public interface ForumManager {
/** Returns the headers of all posts in the given forum. */
Collection<ForumPostHeader> getPostHeaders(GroupId g) throws DbException;
/** Marks a forum post as read or unread. */
void setReadFlag(MessageId m, boolean read) throws DbException;
/** Registers a hook to be called whenever a forum is removed. */
void registerRemoveForumHook(RemoveForumHook hook);

View File

@@ -45,7 +45,6 @@ public interface IntroductionConstants {
String CONTACT_ID_2 = "contactId2";
String RESPONSE_1 = "response1";
String RESPONSE_2 = "response2";
String READ = "read";
/* Introduction Request Action */
String PUBLIC_KEY1 = "publicKey1";

View File

@@ -1,6 +1,7 @@
package org.briarproject.api.introduction;
import org.briarproject.api.FormatException;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.clients.SessionId;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
@@ -9,7 +10,7 @@ import org.briarproject.api.sync.ClientId;
import java.util.Collection;
public interface IntroductionManager {
public interface IntroductionManager extends MessageTracker {
/** Returns the unique ID of the introduction client. */
ClientId getClientId();

View File

@@ -1,5 +1,6 @@
package org.briarproject.api.messaging;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.sync.ClientId;
@@ -8,7 +9,7 @@ import org.briarproject.api.sync.MessageId;
import java.util.Collection;
public interface MessagingManager {
public interface MessagingManager extends MessageTracker {
/** Returns the unique ID of the messaging client. */
ClientId getClientId();
@@ -31,6 +32,4 @@ public interface MessagingManager {
/** Returns the body of the private message with the given ID. */
byte[] getMessageBody(MessageId m) throws DbException;
/** Marks a private message as read or unread. */
void setReadFlag(MessageId m, boolean read) throws DbException;
}

View File

@@ -1,5 +1,6 @@
package org.briarproject.api.privategroup;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.sync.ClientId;
@@ -9,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public interface PrivateGroupManager {
public interface PrivateGroupManager extends MessageTracker {
/** Returns the unique ID of the private group client. */
@NotNull
@@ -40,7 +41,4 @@ public interface PrivateGroupManager {
@NotNull
Collection<GroupMessageHeader> getHeaders(GroupId g) throws DbException;
/** Marks a group message as read or unread. */
void setReadFlag(MessageId m, boolean read) throws DbException;
}

View File

@@ -16,7 +16,6 @@ public interface SharingConstants {
String STATE = "state";
String LOCAL = "local";
String TIME = "time";
String READ = "read";
String IS_SHARER = "isSharer";
String SHAREABLE_ID = "shareableId";
String INVITATION_MSG = "invitationMsg";

View File

@@ -1,5 +1,6 @@
package org.briarproject.api.sharing;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
@@ -8,7 +9,7 @@ import org.briarproject.api.sync.GroupId;
import java.util.Collection;
public interface SharingManager<S extends Shareable> {
public interface SharingManager<S extends Shareable> extends MessageTracker {
/** Returns the unique ID of the group sharing client. */
ClientId getClientId();