mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Separate the sync layer from its clients. #112
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface MessagingConstants {
|
||||
|
||||
/** The maximum length of a private message's content type in bytes. */
|
||||
int MAX_CONTENT_TYPE_LENGTH = 50;
|
||||
|
||||
/** The maximum length of a private message's body in bytes. */
|
||||
int MAX_PRIVATE_MESSAGE_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
}
|
||||
@@ -1,37 +1,35 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface MessagingManager {
|
||||
|
||||
/** Returns the unique ID of the messaging client. */
|
||||
ClientId getClientId();
|
||||
|
||||
/**
|
||||
* Informs the messaging manager that a new contact has been added.
|
||||
* Creates a private conversation with the contact.
|
||||
*/
|
||||
void addContact(ContactId c, SecretKey master) throws DbException;
|
||||
void addContact(ContactId c) throws DbException;
|
||||
|
||||
/** Stores a local private message. */
|
||||
void addLocalMessage(Message m) throws DbException;
|
||||
void addLocalMessage(PrivateMessage m) throws DbException;
|
||||
|
||||
/** Returns the private conversation with the given ID. */
|
||||
PrivateConversation getConversation(GroupId g) 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, or
|
||||
* null if no private conversation ID has been set.
|
||||
*/
|
||||
/** Returns the ID of the private conversation with the given contact. */
|
||||
GroupId getConversationId(ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the headers of all messages in the private conversation with the
|
||||
* given contact, or null if no private conversation ID has been set.
|
||||
* Returns the headers of all messages in the given private conversation.
|
||||
*/
|
||||
Collection<PrivateMessageHeader> getMessageHeaders(ContactId c)
|
||||
throws DbException;
|
||||
@@ -39,13 +37,6 @@ public interface MessagingManager {
|
||||
/** Returns the body of the private message with the given ID. */
|
||||
byte[] getMessageBody(MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Makes a private conversation visible to the given contact, adds it to
|
||||
* the contact's subscriptions, and sets it as the private conversation for
|
||||
* the contact.
|
||||
*/
|
||||
void setConversation(ContactId c, PrivateConversation p) throws DbException;
|
||||
|
||||
/** Marks a private message as read or unread. */
|
||||
void setReadFlag(MessageId m, boolean read) throws DbException;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,33 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
|
||||
public interface PrivateConversation {
|
||||
// TODO: Remove if no longer needed
|
||||
public class PrivateConversation {
|
||||
|
||||
GroupId getId();
|
||||
private final Group group;
|
||||
|
||||
public PrivateConversation(Group group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public GroupId getId() {
|
||||
return group.getId();
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return group.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PrivateConversation
|
||||
&& group.equals(((PrivateConversation) o).group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class PrivateMessage {
|
||||
|
||||
private final Message message;
|
||||
private final MessageId parent;
|
||||
private final String contentType;
|
||||
|
||||
public PrivateMessage(Message message, MessageId parent,
|
||||
String contentType) {
|
||||
this.message = message;
|
||||
this.parent = parent;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public MessageId getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -8,8 +8,7 @@ import java.security.GeneralSecurityException;
|
||||
|
||||
public interface PrivateMessageFactory {
|
||||
|
||||
Message createPrivateMessage(MessageId parent,
|
||||
PrivateConversation conversation, String contentType,
|
||||
long timestamp, byte[] body) throws IOException,
|
||||
GeneralSecurityException;
|
||||
PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
|
||||
MessageId parent, String contentType, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,51 @@
|
||||
package org.briarproject.api.messaging;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public interface PrivateMessageHeader {
|
||||
public class PrivateMessageHeader {
|
||||
|
||||
enum Status { STORED, SENT, DELIVERED }
|
||||
private final MessageId id;
|
||||
private final long timestamp;
|
||||
private final String contentType;
|
||||
private final boolean local, read, sent, seen;
|
||||
|
||||
MessageId getId();
|
||||
public PrivateMessageHeader(MessageId id, long timestamp,
|
||||
String contentType, boolean local, boolean read, boolean sent,
|
||||
boolean seen) {
|
||||
this.id = id;
|
||||
this.timestamp = timestamp;
|
||||
this.contentType = contentType;
|
||||
this.local = local;
|
||||
this.read = read;
|
||||
this.sent = sent;
|
||||
this.seen = seen;
|
||||
}
|
||||
|
||||
Author getAuthor();
|
||||
public MessageId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
String getContentType();
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
long getTimestamp();
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
boolean isLocal();
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
boolean isRead();
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
Status getStatus();
|
||||
public boolean isSent() {
|
||||
return sent;
|
||||
}
|
||||
|
||||
public boolean isSeen() {
|
||||
return seen;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user