mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 13:23:40 +00:00
Only handle friend requests for direct chats.
This commit is contained in:
parent
55ecd3cae4
commit
aea686c856
@ -1137,6 +1137,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
private void becomeFriendsWithContact(String pubKey, boolean syncContact) {
|
private void becomeFriendsWithContact(String pubKey, boolean syncContact) {
|
||||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||||
Recipient contactID = Recipient.from(context, Address.fromSerialized(pubKey), false);
|
Recipient contactID = Recipient.from(context, Address.fromSerialized(pubKey), false);
|
||||||
|
if (contactID.isGroupRecipient()) return;
|
||||||
|
|
||||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(contactID);
|
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(contactID);
|
||||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||||
if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS) { return; }
|
if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS) { return; }
|
||||||
@ -1172,6 +1174,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
Recipient primaryDeviceRecipient = getMessagePrimaryDestination(content, message);
|
Recipient primaryDeviceRecipient = getMessagePrimaryDestination(content, message);
|
||||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||||
|
|
||||||
|
// Loki - Friend requests only work in direct chats
|
||||||
|
if (!originalRecipient.getAddress().isPhone()) { return; }
|
||||||
|
|
||||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(originalRecipient);
|
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(originalRecipient);
|
||||||
long primaryDeviceThreadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(primaryDeviceRecipient);
|
long primaryDeviceThreadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(primaryDeviceRecipient);
|
||||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||||
|
@ -16,20 +16,20 @@ object FriendRequestHandler {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun updateFriendRequestState(context: Context, type: ActionType, messageId: Long, threadId: Long) {
|
fun updateFriendRequestState(context: Context, type: ActionType, messageId: Long, threadId: Long) {
|
||||||
|
if (threadId < 0) return
|
||||||
|
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) ?: return
|
||||||
|
if (!recipient.address.isPhone) { return }
|
||||||
|
|
||||||
// Update thread status
|
// Update thread status
|
||||||
// Note: Do we need to only update these if we're not friends?
|
val threadFriendStatus = when (type) {
|
||||||
if (threadId >= 0) {
|
ActionType.Sending -> LokiThreadFriendRequestStatus.REQUEST_SENDING
|
||||||
val threadFriendStatus = when (type) {
|
ActionType.Failed -> LokiThreadFriendRequestStatus.NONE
|
||||||
ActionType.Sending -> LokiThreadFriendRequestStatus.REQUEST_SENDING
|
ActionType.Sent -> LokiThreadFriendRequestStatus.REQUEST_SENT
|
||||||
ActionType.Failed -> LokiThreadFriendRequestStatus.NONE
|
|
||||||
ActionType.Sent -> LokiThreadFriendRequestStatus.REQUEST_SENT
|
|
||||||
}
|
|
||||||
DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(threadId, threadFriendStatus)
|
|
||||||
}
|
}
|
||||||
|
DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(threadId, threadFriendStatus)
|
||||||
|
|
||||||
// Update message status
|
// Update message status
|
||||||
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId)
|
if (messageId >= 0) {
|
||||||
if (recipient != null && messageId >= 0) {
|
|
||||||
val messageDatabase = DatabaseFactory.getLokiMessageDatabase(context)
|
val messageDatabase = DatabaseFactory.getLokiMessageDatabase(context)
|
||||||
val friendRequestStatus = messageDatabase.getFriendRequestStatus(messageId)
|
val friendRequestStatus = messageDatabase.getFriendRequestStatus(messageId)
|
||||||
if (type == ActionType.Sending) {
|
if (type == ActionType.Sending) {
|
||||||
@ -73,6 +73,8 @@ object FriendRequestHandler {
|
|||||||
// We only want to update the last message status if we're not friends with any of their linked devices
|
// We only want to update the last message status if we're not friends with any of their linked devices
|
||||||
// This ensures that we don't spam the UI with accept/decline messages
|
// This ensures that we don't spam the UI with accept/decline messages
|
||||||
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) ?: return
|
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) ?: return
|
||||||
|
if (!recipient.address.isPhone) { return }
|
||||||
|
|
||||||
isFriendsWithAnyLinkedDevice(context, recipient).successUi { isFriends ->
|
isFriendsWithAnyLinkedDevice(context, recipient).successUi { isFriends ->
|
||||||
if (isFriends) { return@successUi }
|
if (isFriends) { return@successUi }
|
||||||
|
|
||||||
|
@ -61,6 +61,11 @@ fun getFriendCount(context: Context, devices: Set<String>): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun shouldAutomaticallyBecomeFriendsWithDevice(publicKey: String, context: Context): Promise<Boolean, Exception> {
|
fun shouldAutomaticallyBecomeFriendsWithDevice(publicKey: String, context: Context): Promise<Boolean, Exception> {
|
||||||
|
// Don't become friends if we're a group
|
||||||
|
if (!Address.fromSerialized(publicKey).isPhone) {
|
||||||
|
return Promise.of(false)
|
||||||
|
}
|
||||||
|
|
||||||
// If this public key is our primary device then we should become friends
|
// If this public key is our primary device then we should become friends
|
||||||
if (publicKey == TextSecurePreferences.getMasterHexEncodedPublicKey(context)) {
|
if (publicKey == TextSecurePreferences.getMasterHexEncodedPublicKey(context)) {
|
||||||
return Promise.of(true)
|
return Promise.of(true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user