Wrap messages, introductions and forum invites in a ConversationManager

This commit is contained in:
str4d
2016-06-02 03:51:08 +00:00
parent 67aa7c3269
commit c333052396
41 changed files with 1041 additions and 814 deletions

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.conversation;
import org.briarproject.api.forum.ForumInvitationMessage;
public interface ConversationForumInvitationItem extends ConversationItem {
ForumInvitationMessage getForumInvitationMessage();
}

View File

@@ -0,0 +1,12 @@
package org.briarproject.api.conversation;
import org.briarproject.api.introduction.IntroductionRequest;
public interface ConversationIntroductionRequestItem extends ConversationItem {
IntroductionRequest getIntroductionRequest();
boolean wasAnswered();
void setAnswered(boolean answered);
}

View File

@@ -0,0 +1,8 @@
package org.briarproject.api.conversation;
import org.briarproject.api.introduction.IntroductionResponse;
public interface ConversationIntroductionResponseItem extends ConversationItem {
IntroductionResponse getIntroductionResponse();
}

View File

@@ -0,0 +1,40 @@
package org.briarproject.api.conversation;
import org.briarproject.api.sync.MessageId;
public interface ConversationItem {
MessageId getId();
long getTime();
interface ContentListener {
void contentReady();
}
interface Partial extends ConversationItem {
void setContent(byte[] content);
void setContentListener(ContentListener listener);
}
interface IncomingItem extends ConversationItem {
boolean isRead();
void setRead(boolean read);
}
interface OutgoingItem extends ConversationItem {
boolean isSent();
void setSent(boolean sent);
boolean isSeen();
void setSeen(boolean seen);
}
}

View File

@@ -0,0 +1,61 @@
package org.briarproject.api.conversation;
import org.briarproject.api.FormatException;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.PrivateMessage;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import java.util.List;
public interface ConversationManager {
/**
* Returns the unique ID of the conversation client.
*/
ClientId getClientId();
/**
* Stores a local private message, and returns the corresponding item.
*/
ConversationItem addLocalMessage(PrivateMessage m, byte[] body) throws DbException;
/**
* Returns the ID of the contact with the given private conversation.
*/
ContactId getContactId(GroupId g) throws DbException;
/**
* Returns the ID of the private conversation with the given contact.
*/
GroupId getConversationId(ContactId c) throws DbException;
/**
* Returns all messages in the given private conversation.
*/
List<ConversationItem> getMessages(ContactId c) throws DbException;
/**
* Returns all messages in the given private conversation.
*/
List<ConversationItem> getMessages(ContactId c, boolean content)
throws DbException;
/**
* Starts a background task to load the content of the given message.
*/
void loadMessageContent(ConversationItem.Partial m);
/**
* Respond to a conversation item with accept/decline.
*/
void respondToItem(ContactId c, ConversationItem item, boolean accept,
long timestamp) throws DbException, FormatException;
/**
* Marks a conversation item as read or unread.
*/
void setReadFlag(ConversationItem item, boolean read) throws DbException;
}

View File

@@ -0,0 +1,11 @@
package org.briarproject.api.conversation;
import org.briarproject.api.conversation.ConversationItem.Partial;
import org.briarproject.api.messaging.PrivateMessageHeader;
public interface ConversationMessageItem extends Partial {
PrivateMessageHeader getHeader();
byte[] getBody();
}

View File

@@ -6,6 +6,7 @@ import org.briarproject.api.db.DbException;
import org.briarproject.api.sharing.SharingManager;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import java.util.Collection;
@@ -46,4 +47,7 @@ public interface ForumSharingManager extends SharingManager<Forum, ForumInvitati
/** Returns true if the forum not already shared and no invitation is open */
boolean canBeShared(GroupId g, Contact c) throws DbException;
/** Marks a forum sharing message as read or unread. */
void setReadFlag(MessageId m, boolean read) throws DbException;
}

View File

@@ -6,6 +6,7 @@ import org.briarproject.api.contact.Contact;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.MessageId;
import java.util.Collection;
@@ -41,4 +42,7 @@ public interface IntroductionManager {
Collection<IntroductionMessage> getIntroductionMessages(ContactId contactId)
throws DbException;
/** Marks an introduction message as read or unread. */
void setReadFlag(MessageId m, boolean read) throws DbException;
}

View File

@@ -5,6 +5,7 @@ import org.briarproject.api.contact.ContactId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import java.util.Collection;
@@ -45,4 +46,7 @@ public interface SharingManager<S extends Shareable, IM extends InvitationMessag
/** Returns true if the group not already shared and no invitation is open */
boolean canBeShared(GroupId g, Contact c) throws DbException;
/** Marks a sharing message as read or unread. */
void setReadFlag(MessageId m, boolean read) throws DbException;
}