mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Add dummy implementation of AutoDeleteManager.
This commit is contained in:
@@ -10,6 +10,7 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.db.TransactionManager;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
@@ -32,6 +33,7 @@ import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
||||
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
@@ -63,7 +65,6 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
||||
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES;
|
||||
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONLY;
|
||||
|
||||
@@ -88,6 +89,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
private final PrivateMessageFactory privateMessageFactory;
|
||||
private final AttachmentRetriever attachmentRetriever;
|
||||
private final AttachmentCreator attachmentCreator;
|
||||
private final AutoDeleteManager autoDeleteManager;
|
||||
|
||||
@Nullable
|
||||
private ContactId contactId = null;
|
||||
@@ -122,7 +124,8 @@ public class ConversationViewModel extends DbViewModel
|
||||
SettingsManager settingsManager,
|
||||
PrivateMessageFactory privateMessageFactory,
|
||||
AttachmentRetriever attachmentRetriever,
|
||||
AttachmentCreator attachmentCreator) {
|
||||
AttachmentCreator attachmentCreator,
|
||||
AutoDeleteManager autoDeleteManager) {
|
||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
@@ -133,6 +136,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
this.privateMessageFactory = privateMessageFactory;
|
||||
this.attachmentRetriever = attachmentRetriever;
|
||||
this.attachmentCreator = attachmentCreator;
|
||||
this.autoDeleteManager = autoDeleteManager;
|
||||
messagingGroupId = map(contactItem, c ->
|
||||
messagingManager.getContactGroup(c.getContact()).getId());
|
||||
contactDeleted.setValue(false);
|
||||
@@ -246,7 +250,8 @@ public class ConversationViewModel extends DbViewModel
|
||||
observeForeverOnce(messagingGroupId, groupId -> {
|
||||
requireNonNull(groupId);
|
||||
observeForeverOnce(privateMessageFormat, format ->
|
||||
createMessage(groupId, text, headers, timestamp, format));
|
||||
storeMessage(requireNonNull(contactId), groupId, text,
|
||||
headers, timestamp, format));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -306,45 +311,50 @@ public class ConversationViewModel extends DbViewModel
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void createMessage(GroupId groupId, @Nullable String text,
|
||||
private PrivateMessage createMessage(Transaction txn, ContactId c,
|
||||
GroupId groupId, @Nullable String text,
|
||||
List<AttachmentHeader> headers, long timestamp,
|
||||
PrivateMessageFormat format) {
|
||||
PrivateMessageFormat format) throws DbException {
|
||||
try {
|
||||
PrivateMessage pm;
|
||||
if (format == TEXT_ONLY) {
|
||||
pm = privateMessageFactory.createLegacyPrivateMessage(
|
||||
return privateMessageFactory.createLegacyPrivateMessage(
|
||||
groupId, timestamp, requireNonNull(text));
|
||||
} else if (format == TEXT_IMAGES) {
|
||||
pm = privateMessageFactory.createPrivateMessage(groupId,
|
||||
return privateMessageFactory.createPrivateMessage(groupId,
|
||||
timestamp, text, headers);
|
||||
} else {
|
||||
// TODO: Look up auto-delete timer
|
||||
pm = privateMessageFactory.createPrivateMessage(groupId,
|
||||
timestamp, text, headers, NO_AUTO_DELETE_TIMER);
|
||||
long timer = autoDeleteManager.getAutoDeleteTimer(txn, c);
|
||||
return privateMessageFactory.createPrivateMessage(groupId,
|
||||
timestamp, text, headers, timer);
|
||||
}
|
||||
storeMessage(pm);
|
||||
} catch (FormatException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void storeMessage(PrivateMessage m) {
|
||||
attachmentCreator.onAttachmentsSent(m.getMessage().getId());
|
||||
private void storeMessage(ContactId c, GroupId groupId,
|
||||
@Nullable String text, List<AttachmentHeader> headers,
|
||||
long timestamp, PrivateMessageFormat format) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
messagingManager.addLocalMessage(m);
|
||||
logDuration(LOG, "Storing message", start);
|
||||
Message message = m.getMessage();
|
||||
PrivateMessageHeader h = new PrivateMessageHeader(
|
||||
message.getId(), message.getGroupId(),
|
||||
message.getTimestamp(), true, true, false, false,
|
||||
m.hasText(), m.getAttachmentHeaders(),
|
||||
m.getAutoDeleteTimer());
|
||||
// TODO add text to cache when available here
|
||||
addedHeader.postEvent(h);
|
||||
db.transaction(false, txn -> {
|
||||
long start = now();
|
||||
PrivateMessage m = createMessage(txn, c, groupId, text,
|
||||
headers, timestamp, format);
|
||||
messagingManager.addLocalMessage(txn, m);
|
||||
logDuration(LOG, "Storing message", start);
|
||||
Message message = m.getMessage();
|
||||
PrivateMessageHeader h = new PrivateMessageHeader(
|
||||
message.getId(), message.getGroupId(),
|
||||
message.getTimestamp(), true, true, false, false,
|
||||
m.hasText(), m.getAttachmentHeaders(),
|
||||
m.getAutoDeleteTimer());
|
||||
// TODO add text to cache when available here
|
||||
MessageId id = message.getId();
|
||||
txn.attach(() -> attachmentCreator.onAttachmentsSent(id));
|
||||
addedHeader.postEvent(h);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user