mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Move lookup of latest conversation timestamp to core.
This commit is contained in:
@@ -736,18 +736,10 @@ public class ConversationActivity extends BriarActivity
|
||||
List<AttachmentHeader> attachmentHeaders) {
|
||||
if (isNullOrEmpty(text) && attachmentHeaders.isEmpty())
|
||||
throw new AssertionError();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||
viewModel.sendMessage(text, attachmentHeaders, timestamp);
|
||||
viewModel.sendMessage(text, attachmentHeaders);
|
||||
textInputView.clearText();
|
||||
}
|
||||
|
||||
private long getMinTimestampForNewMessage() {
|
||||
// Don't use an earlier timestamp than the newest message
|
||||
ConversationItem item = adapter.getLastItem();
|
||||
return item == null ? 0 : item.getTime() + 1;
|
||||
}
|
||||
|
||||
private void onAddedPrivateMessage(@Nullable PrivateMessageHeader h) {
|
||||
if (h == null) return;
|
||||
addConversationItem(h.accept(visitor));
|
||||
@@ -955,13 +947,11 @@ public class ConversationActivity extends BriarActivity
|
||||
adapter.notifyItemChanged(position, item);
|
||||
}
|
||||
runOnDbThread(() -> {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||
try {
|
||||
switch (item.getRequestType()) {
|
||||
case INTRODUCTION:
|
||||
respondToIntroductionRequest(item.getSessionId(),
|
||||
accept, timestamp);
|
||||
accept);
|
||||
break;
|
||||
case FORUM:
|
||||
respondToForumRequest(item.getSessionId(), accept);
|
||||
@@ -1037,9 +1027,8 @@ public class ConversationActivity extends BriarActivity
|
||||
|
||||
@DatabaseExecutor
|
||||
private void respondToIntroductionRequest(SessionId sessionId,
|
||||
boolean accept, long time) throws DbException {
|
||||
introductionManager.respondToIntroduction(contactId, sessionId, time,
|
||||
accept);
|
||||
boolean accept) throws DbException {
|
||||
introductionManager.respondToIntroduction(contactId, sessionId, accept);
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
|
||||
@@ -35,6 +35,7 @@ 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.conversation.ConversationManager;
|
||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||
import org.briarproject.briar.api.identity.AuthorManager;
|
||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||
@@ -90,6 +91,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
private final AttachmentRetriever attachmentRetriever;
|
||||
private final AttachmentCreator attachmentCreator;
|
||||
private final AutoDeleteManager autoDeleteManager;
|
||||
private final ConversationManager conversationManager;
|
||||
|
||||
@Nullable
|
||||
private ContactId contactId = null;
|
||||
@@ -125,7 +127,8 @@ public class ConversationViewModel extends DbViewModel
|
||||
PrivateMessageFactory privateMessageFactory,
|
||||
AttachmentRetriever attachmentRetriever,
|
||||
AttachmentCreator attachmentCreator,
|
||||
AutoDeleteManager autoDeleteManager) {
|
||||
AutoDeleteManager autoDeleteManager,
|
||||
ConversationManager conversationManager) {
|
||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||
this.db = db;
|
||||
this.eventBus = eventBus;
|
||||
@@ -137,6 +140,7 @@ public class ConversationViewModel extends DbViewModel
|
||||
this.attachmentRetriever = attachmentRetriever;
|
||||
this.attachmentCreator = attachmentCreator;
|
||||
this.autoDeleteManager = autoDeleteManager;
|
||||
this.conversationManager = conversationManager;
|
||||
messagingGroupId = map(contactItem, c ->
|
||||
messagingManager.getContactGroup(c.getContact()).getId());
|
||||
contactDeleted.setValue(false);
|
||||
@@ -244,14 +248,13 @@ public class ConversationViewModel extends DbViewModel
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void sendMessage(@Nullable String text,
|
||||
List<AttachmentHeader> headers, long timestamp) {
|
||||
void sendMessage(@Nullable String text, List<AttachmentHeader> headers) {
|
||||
// messagingGroupId is loaded with the contact
|
||||
observeForeverOnce(messagingGroupId, groupId -> {
|
||||
requireNonNull(groupId);
|
||||
observeForeverOnce(privateMessageFormat, format ->
|
||||
storeMessage(requireNonNull(contactId), groupId, text,
|
||||
headers, timestamp, format));
|
||||
headers, format));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -313,8 +316,10 @@ public class ConversationViewModel extends DbViewModel
|
||||
|
||||
private PrivateMessage createMessage(Transaction txn, ContactId c,
|
||||
GroupId groupId, @Nullable String text,
|
||||
List<AttachmentHeader> headers, long timestamp,
|
||||
PrivateMessageFormat format) throws DbException {
|
||||
List<AttachmentHeader> headers, PrivateMessageFormat format)
|
||||
throws DbException {
|
||||
long timestamp =
|
||||
conversationManager.getTimestampForOutgoingMessage(txn, c);
|
||||
try {
|
||||
if (format == TEXT_ONLY) {
|
||||
return privateMessageFactory.createLegacyPrivateMessage(
|
||||
@@ -335,13 +340,13 @@ public class ConversationViewModel extends DbViewModel
|
||||
@UiThread
|
||||
private void storeMessage(ContactId c, GroupId groupId,
|
||||
@Nullable String text, List<AttachmentHeader> headers,
|
||||
long timestamp, PrivateMessageFormat format) {
|
||||
PrivateMessageFormat format) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
db.transaction(false, txn -> {
|
||||
long start = now();
|
||||
PrivateMessage m = createMessage(txn, c, groupId, text,
|
||||
headers, timestamp, format);
|
||||
headers, format);
|
||||
messagingManager.addLocalMessage(txn, m);
|
||||
logDuration(LOG, "Storing message", start);
|
||||
Message message = m.getMessage();
|
||||
|
||||
@@ -219,8 +219,7 @@ public class IntroductionMessageFragment extends BaseFragment
|
||||
introductionActivity.runOnDbThread(() -> {
|
||||
// actually make the introduction
|
||||
try {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
introductionManager.makeIntroduction(c1, c2, text, timestamp);
|
||||
introductionManager.makeIntroduction(c1, c2, text);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
introductionError();
|
||||
|
||||
Reference in New Issue
Block a user