mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Partially fix note to self
This commit is contained in:
parent
45706b8e66
commit
e2ca40952e
@ -230,6 +230,7 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.loki.api.opengroups.LokiPublicChat;
|
||||
import org.whispersystems.signalservice.loki.protocol.mentions.Mention;
|
||||
import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager;
|
||||
import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol;
|
||||
import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol;
|
||||
import org.whispersystems.signalservice.loki.protocol.todo.LokiThreadFriendRequestStatus;
|
||||
import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation;
|
||||
@ -2447,7 +2448,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
// Loki - Send a friend request if we're not yet friends with the user in question
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadId);
|
||||
message.isFriendRequest = !isGroupConversation() && friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS; // Needed for stageOutgoingMessage(...)
|
||||
message.isFriendRequest = !isGroupConversation() && friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS
|
||||
&& !SessionMetaProtocol.shared.isNoteToSelf(recipient.getAddress().serialize()); // Needed for stageOutgoingMessage(...)
|
||||
|
||||
silentlySetComposeText("");
|
||||
final long id = fragment.stageOutgoingMessage(message);
|
||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki.database
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.util.Log
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
@ -60,6 +61,7 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
|
||||
override fun setFriendRequestStatus(threadID: Long, friendRequestStatus: LokiThreadFriendRequestStatus) {
|
||||
if (threadID < 0) { return }
|
||||
Log.d("Loki", "Setting FR status for thread with ID $threadID to $friendRequestStatus.")
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(2)
|
||||
contentValues.put(Companion.threadID, threadID)
|
||||
|
@ -151,7 +151,7 @@ object FriendRequestProtocol {
|
||||
// Guard against invalid state transitions
|
||||
if (threadFRStatus != LokiThreadFriendRequestStatus.REQUEST_SENDING && threadFRStatus != LokiThreadFriendRequestStatus.REQUEST_SENT
|
||||
&& threadFRStatus != LokiThreadFriendRequestStatus.REQUEST_RECEIVED) { return }
|
||||
Log.d("Loki", "Accepting friend request from $publicKey.")
|
||||
Log.d("Loki", "Received a friend request accepted message from $publicKey.")
|
||||
lokiThreadDB.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS)
|
||||
val lastMessageID = getLastMessageID(context, threadID)
|
||||
if (lastMessageID != null) {
|
||||
@ -242,7 +242,7 @@ object FriendRequestProtocol {
|
||||
// The order of these checks matters
|
||||
if (message.recipient.isGroupRecipient) { return false }
|
||||
if (message.recipient.address.serialize() == TextSecurePreferences.getLocalNumber(context)) { return false }
|
||||
// TODO: Return false if the message is a device linking request
|
||||
// TODO: Return true if the message is a device linking request
|
||||
// TODO: Return false if the message is a session request
|
||||
return message.isFriendRequest
|
||||
}
|
||||
@ -252,7 +252,7 @@ object FriendRequestProtocol {
|
||||
// The order of these checks matters
|
||||
if (message.recipient.isGroupRecipient) { return false }
|
||||
if (message.recipient.address.serialize() == TextSecurePreferences.getLocalNumber(context)) { return false }
|
||||
// TODO: Return false if the message is a device linking request
|
||||
// TODO: Return true if the message is a device linking request
|
||||
// TODO: Return false if the message is a session request
|
||||
return message.isFriendRequest
|
||||
}
|
||||
|
@ -46,8 +46,9 @@ object MultiDeviceProtocol {
|
||||
private fun sendMessagePushToDevice(context: Context, recipient: Recipient, messageID: Long, messageType: MessageType): PushSendJob {
|
||||
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient)
|
||||
val threadFRStatus = DatabaseFactory.getLokiThreadDatabase(context).getFriendRequestStatus(threadID)
|
||||
val isContactFriend = (threadFRStatus == LokiThreadFriendRequestStatus.FRIENDS)
|
||||
val isFRMessage = (threadFRStatus != LokiThreadFriendRequestStatus.FRIENDS) // Holds true assuming this method isn't invoked for control messages
|
||||
val isNoteToSelf = SessionMetaProtocol.shared.isNoteToSelf(recipient.address.serialize())
|
||||
val isContactFriend = (threadFRStatus == LokiThreadFriendRequestStatus.FRIENDS || isNoteToSelf) // In the note to self case the device linking request was the FR
|
||||
val isFRMessage = !isContactFriend // Holds true assuming this method isn't invoked for control messages
|
||||
val hasVisibleContent = when (messageType) {
|
||||
MessageType.Text -> DatabaseFactory.getSmsDatabase(context).getMessage(messageID).body.isNotBlank()
|
||||
MessageType.Media -> {
|
||||
@ -55,9 +56,9 @@ object MultiDeviceProtocol {
|
||||
outgoingMediaMessage.body.isNotBlank() || outgoingMediaMessage.attachments.isNotEmpty()
|
||||
}
|
||||
}
|
||||
if (isFRMessage && !hasVisibleContent && BuildConfig.DEBUG) { throw IllegalStateException() }
|
||||
if (isFRMessage && !hasVisibleContent && BuildConfig.DEBUG) { throw IllegalStateException() } // Verify the above assumption
|
||||
val shouldSendAutoGeneratedFR = !isContactFriend && !isFRMessage
|
||||
&& !SessionMetaProtocol.shared.isNoteToSelf(recipient.address.serialize()) && !recipient.address.isGroup // Group threads work through session requests
|
||||
&& !isNoteToSelf && !recipient.address.isGroup // Group threads work through session requests
|
||||
&& hasVisibleContent
|
||||
if (!shouldSendAutoGeneratedFR) {
|
||||
when (messageType) {
|
||||
@ -178,6 +179,8 @@ object MultiDeviceProtocol {
|
||||
}
|
||||
val isValid = isValidDeviceLinkMessage(context, deviceLink)
|
||||
if (!isValid) { return }
|
||||
// The line below isn't actually necessary because this is called after PushDecryptJob
|
||||
// calls handlePreKeyBundleMessageIfNeeded, but it also doesn't hurt.
|
||||
SessionManagementProtocol.handlePreKeyBundleMessageIfNeeded(context, content)
|
||||
linkingSession.processLinkingRequest(deviceLink)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user