Add auto-deletion timer to private messages.

This commit is contained in:
akwizgran
2020-11-19 12:57:07 +00:00
committed by Torsten Grote
parent 629cff20a3
commit dba85debfa
18 changed files with 208 additions and 75 deletions

View File

@@ -32,7 +32,7 @@ public interface MessagingManager extends ConversationClient {
/**
* The current minor version of the messaging client.
*/
int MINOR_VERSION = 2;
int MINOR_VERSION = 3;
/**
* Stores a local private message.
@@ -70,12 +70,8 @@ public interface MessagingManager extends ConversationClient {
String getMessageText(MessageId m) throws DbException;
/**
* Returns true if the contact with the given {@link ContactId} does support
* image attachments.
* <p>
* Added: 2019-01-01
* Returns the private message format supported by the given contact.
*/
boolean contactSupportsImages(Transaction txn, ContactId c)
PrivateMessageFormat getContactMessageFormat(Transaction txn, ContactId c)
throws DbException;
}

View File

@@ -9,44 +9,65 @@ import java.util.List;
import javax.annotation.concurrent.Immutable;
import static java.util.Collections.emptyList;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES;
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES_AUTO_DELETE;
@Immutable
@NotNullByDefault
public class PrivateMessage {
private final Message message;
private final boolean legacyFormat, hasText;
private final boolean hasText;
private final List<AttachmentHeader> attachmentHeaders;
private final long autoDeleteTimer;
private final PrivateMessageFormat format;
/**
* Constructor for private messages in the legacy format, which does not
* support attachments.
* Constructor for private messages in the
* {@link PrivateMessageFormat#TEXT TEXT} format.
*/
public PrivateMessage(Message message) {
this.message = message;
legacyFormat = true;
hasText = true;
attachmentHeaders = emptyList();
autoDeleteTimer = -1;
format = TEXT;
}
/**
* Constructor for private messages in the current format, which supports
* attachments.
* Constructor for private messages in the
* {@link PrivateMessageFormat#TEXT_IMAGES TEXT_IMAGES} format.
*/
public PrivateMessage(Message message, boolean hasText,
List<AttachmentHeader> headers) {
this.message = message;
this.hasText = hasText;
this.attachmentHeaders = headers;
legacyFormat = false;
autoDeleteTimer = -1;
format = TEXT_IMAGES;
}
/**
* Constructor for private messages in the
* {@link PrivateMessageFormat#TEXT_IMAGES_AUTO_DELETE TEXT_IMAGES_AUTO_DELETE}
* format.
*/
public PrivateMessage(Message message, boolean hasText,
List<AttachmentHeader> headers, long autoDeleteTimer) {
this.message = message;
this.hasText = hasText;
this.attachmentHeaders = headers;
this.autoDeleteTimer = autoDeleteTimer;
format = TEXT_IMAGES_AUTO_DELETE;
}
public Message getMessage() {
return message;
}
public boolean isLegacyFormat() {
return legacyFormat;
public PrivateMessageFormat getFormat() {
return format;
}
public boolean hasText() {
@@ -56,4 +77,8 @@ public class PrivateMessage {
public List<AttachmentHeader> getAttachmentHeaders() {
return attachmentHeaders;
}
public long getAutoDeleteTimer() {
return autoDeleteTimer;
}
}

View File

@@ -19,4 +19,7 @@ public interface PrivateMessageFactory {
@Nullable String text, List<AttachmentHeader> headers)
throws FormatException;
PrivateMessage createPrivateMessage(GroupId groupId, long timestamp,
@Nullable String text, List<AttachmentHeader> headers,
long autoDeleteTimer) throws FormatException;
}

View File

@@ -0,0 +1,24 @@
package org.briarproject.briar.api.messaging;
public enum PrivateMessageFormat {
/**
* First version of the private message format, which doesn't support
* image attachments or auto-deletion.
*/
TEXT,
/**
* Second version of the private message format, which supports image
* attachments but not auto-deletion. Support for this format was
* added in client version 0.1.
*/
TEXT_IMAGES,
/**
* Third version of the private message format, which supports image
* attachments and auto-deletion. Support for this format was added
* in client version 0.3.
*/
TEXT_IMAGES_AUTO_DELETE
}

View File

@@ -17,13 +17,16 @@ public class PrivateMessageHeader extends ConversationMessageHeader {
private final boolean hasText;
private final List<AttachmentHeader> attachmentHeaders;
private final long autoDeleteTimer;
public PrivateMessageHeader(MessageId id, GroupId groupId, long timestamp,
boolean local, boolean read, boolean sent, boolean seen,
boolean hasText, List<AttachmentHeader> headers) {
boolean hasText, List<AttachmentHeader> headers,
long autoDeleteTimer) {
super(id, groupId, timestamp, local, read, sent, seen);
this.hasText = hasText;
this.attachmentHeaders = headers;
this.autoDeleteTimer = autoDeleteTimer;
}
public boolean hasText() {
@@ -34,9 +37,12 @@ public class PrivateMessageHeader extends ConversationMessageHeader {
return attachmentHeaders;
}
public long getAutoDeleteTimer() {
return autoDeleteTimer;
}
@Override
public <T> T accept(ConversationMessageVisitor<T> v) {
return v.visitPrivateMessageHeader(this);
}
}