mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Merge pull request #304 from RyanRory/open-group-message-order
Fix Open Group Message Ordering
This commit is contained in:
commit
a95af86796
@ -426,7 +426,9 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
@Override
|
||||
public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int position) {
|
||||
MessageRecord messageRecord = getRecordForPositionOrThrow(position);
|
||||
viewHolder.setText(DateUtils.getRelativeDate(getContext(), locale, messageRecord.getDateReceived()));
|
||||
long timestamp = messageRecord.getDateReceived();
|
||||
if (recipient.getAddress().isOpenGroup()) { timestamp = messageRecord.getTimestamp(); }
|
||||
viewHolder.setText(DateUtils.getRelativeDate(getContext(), locale, timestamp));
|
||||
}
|
||||
|
||||
public void onBindLastSeenViewHolder(HeaderViewHolder viewHolder, int position) {
|
||||
|
@ -816,7 +816,8 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
|
||||
private Optional<InsertResult> insertMessageInbox(IncomingMediaMessage retrieved,
|
||||
String contentLocation,
|
||||
long threadId, long mailbox)
|
||||
long threadId, long mailbox,
|
||||
long serverTimestamp)
|
||||
throws MmsException
|
||||
{
|
||||
if (threadId == -1 || retrieved.isGroupMessage()) {
|
||||
@ -839,7 +840,13 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
contentValues.put(THREAD_ID, threadId);
|
||||
contentValues.put(CONTENT_LOCATION, contentLocation);
|
||||
contentValues.put(STATUS, Status.DOWNLOAD_INITIALIZED);
|
||||
contentValues.put(DATE_RECEIVED, retrieved.getSentTimeMillis()); // Loki - This is important due to how we handle GIFs
|
||||
// If the messages are from open groups, there will be a serverTimestamp,
|
||||
// we use current time like a sortId of iOS as the receive time.
|
||||
// Since the messages has been sorted by server timestamp before they are processed,
|
||||
// the order here by actual receiving time should be correct.
|
||||
long receiveTimestamp = serverTimestamp;
|
||||
if (serverTimestamp == 0) { receiveTimestamp = retrieved.getSentTimeMillis(); }
|
||||
contentValues.put(DATE_RECEIVED, receiveTimestamp); // Loki - This is important due to how we handle GIFs
|
||||
contentValues.put(PART_COUNT, retrieved.getAttachments().size());
|
||||
contentValues.put(SUBSCRIPTION_ID, retrieved.getSubscriptionId());
|
||||
contentValues.put(EXPIRES_IN, retrieved.getExpiresIn());
|
||||
@ -893,10 +900,10 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
type |= Types.EXPIRATION_TIMER_UPDATE_BIT;
|
||||
}
|
||||
|
||||
return insertMessageInbox(retrieved, contentLocation, threadId, type);
|
||||
return insertMessageInbox(retrieved, contentLocation, threadId, type, 0);
|
||||
}
|
||||
|
||||
public Optional<InsertResult> insertSecureDecryptedMessageInbox(IncomingMediaMessage retrieved, long threadId)
|
||||
public Optional<InsertResult> insertSecureDecryptedMessageInbox(IncomingMediaMessage retrieved, long threadId, long serverTimestamp)
|
||||
throws MmsException
|
||||
{
|
||||
long type = Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT;
|
||||
@ -909,7 +916,13 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
type |= Types.EXPIRATION_TIMER_UPDATE_BIT;
|
||||
}
|
||||
|
||||
return insertMessageInbox(retrieved, "", threadId, type);
|
||||
return insertMessageInbox(retrieved, "", threadId, type, 0);
|
||||
}
|
||||
|
||||
public Optional<InsertResult> insertSecureDecryptedMessageInbox(IncomingMediaMessage retrieved, long threadId)
|
||||
throws MmsException
|
||||
{
|
||||
return insertSecureDecryptedMessageInbox(retrieved, threadId, 0);
|
||||
}
|
||||
|
||||
public Pair<Long, Long> insertMessageInbox(@NonNull NotificationInd notification, int subscriptionId) {
|
||||
|
@ -580,7 +580,7 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
return new Pair<>(messageId, threadId);
|
||||
}
|
||||
|
||||
protected Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, long type) {
|
||||
protected Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, long type, long serverTimestamp) {
|
||||
if (message.isJoined()) {
|
||||
type = (type & (Types.TOTAL_MASK - Types.BASE_TYPE_MASK)) | Types.JOINED_TYPE;
|
||||
} else if (message.isPreKeyBundle()) {
|
||||
@ -625,7 +625,13 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
ContentValues values = new ContentValues(6);
|
||||
values.put(ADDRESS, message.getSender().serialize());
|
||||
values.put(ADDRESS_DEVICE_ID, message.getSenderDeviceId());
|
||||
values.put(DATE_RECEIVED, message.getSentTimestampMillis()); // Loki - This is important due to how we handle GIFs
|
||||
// If the messages are from open groups, there will be a serverTimestamp,
|
||||
// we use current time like a sortId of iOS as the receive time.
|
||||
// Since the messages has been sorted by server timestamp before they are processed,
|
||||
// the order here by actual receiving time should be correct.
|
||||
long receiveTimestamp = serverTimestamp;
|
||||
if (serverTimestamp == 0) { receiveTimestamp = message.getSentTimestampMillis(); }
|
||||
values.put(DATE_RECEIVED, receiveTimestamp); // Loki - This is important due to how we handle GIFs
|
||||
values.put(DATE_SENT, message.getSentTimestampMillis());
|
||||
values.put(PROTOCOL, message.getProtocol());
|
||||
values.put(READ, unread ? 0 : 1);
|
||||
@ -672,7 +678,11 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
|
||||
public Optional<InsertResult> insertMessageInbox(IncomingTextMessage message) {
|
||||
return insertMessageInbox(message, Types.BASE_INBOX_TYPE);
|
||||
return insertMessageInbox(message, Types.BASE_INBOX_TYPE, 0);
|
||||
}
|
||||
|
||||
public Optional<InsertResult> insertMessageInbox(IncomingTextMessage message, long serverTimestamp) {
|
||||
return insertMessageInbox(message, Types.BASE_INBOX_TYPE, serverTimestamp);
|
||||
}
|
||||
|
||||
public long insertMessageOutbox(long threadId, OutgoingTextMessage message,
|
||||
|
@ -139,6 +139,9 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
if (isPush() && getDateSent() < getDateReceived()) {
|
||||
return getDateSent();
|
||||
}
|
||||
if (getRecipient().getAddress().isOpenGroup()) {
|
||||
return getDateSent();
|
||||
}
|
||||
return getDateReceived();
|
||||
}
|
||||
|
||||
|
@ -755,7 +755,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
Optional<InsertResult> insertResult;
|
||||
|
||||
try {
|
||||
if (message.isGroupMessage()) {
|
||||
insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1, content.getTimestamp());
|
||||
} else {
|
||||
insertResult = database.insertSecureDecryptedMessageInbox(mediaMessage, -1);
|
||||
}
|
||||
|
||||
if (insertResult.isPresent()) {
|
||||
List<DatabaseAttachment> allAttachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
|
||||
@ -952,7 +956,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
if (textMessage.getMessageBody().length() == 0) { return; }
|
||||
|
||||
// Insert the message into the database
|
||||
Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
|
||||
Optional<InsertResult> insertResult;
|
||||
if (message.isGroupMessage()) {
|
||||
insertResult = database.insertMessageInbox(textMessage, content.getTimestamp());
|
||||
} else {
|
||||
insertResult = database.insertMessageInbox(textMessage);
|
||||
}
|
||||
|
||||
if (insertResult.isPresent()) {
|
||||
threadId = insertResult.get().getThreadId();
|
||||
|
@ -166,7 +166,7 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
|
||||
}
|
||||
val senderHexEncodedPublicKey = masterHexEncodedPublicKey ?: message.senderPublicKey
|
||||
val serviceDataMessage = getDataMessage(message)
|
||||
val serviceContent = SignalServiceContent(serviceDataMessage, senderHexEncodedPublicKey, SignalServiceAddress.DEFAULT_DEVICE_ID, message.timestamp, false, false)
|
||||
val serviceContent = SignalServiceContent(serviceDataMessage, senderHexEncodedPublicKey, SignalServiceAddress.DEFAULT_DEVICE_ID, message.serverTimestamp, false, false)
|
||||
if (serviceDataMessage.quote.isPresent || (serviceDataMessage.attachments.isPresent && serviceDataMessage.attachments.get().size > 0) || serviceDataMessage.previews.isPresent) {
|
||||
PushDecryptJob(context).handleMediaMessage(serviceContent, serviceDataMessage, Optional.absent(), Optional.of(message.serverID))
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user