mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +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) {
|
||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
Recipient contactID = Recipient.from(context, Address.fromSerialized(pubKey), false);
|
||||
if (contactID.isGroupRecipient()) return;
|
||||
|
||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(contactID);
|
||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||
if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS) { return; }
|
||||
@ -1172,6 +1174,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
Recipient primaryDeviceRecipient = getMessagePrimaryDestination(content, message);
|
||||
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 primaryDeviceThreadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(primaryDeviceRecipient);
|
||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||
|
@ -16,20 +16,20 @@ object FriendRequestHandler {
|
||||
|
||||
@JvmStatic
|
||||
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
|
||||
// Note: Do we need to only update these if we're not friends?
|
||||
if (threadId >= 0) {
|
||||
val threadFriendStatus = when (type) {
|
||||
ActionType.Sending -> LokiThreadFriendRequestStatus.REQUEST_SENDING
|
||||
ActionType.Failed -> LokiThreadFriendRequestStatus.NONE
|
||||
ActionType.Sent -> LokiThreadFriendRequestStatus.REQUEST_SENT
|
||||
}
|
||||
DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(threadId, threadFriendStatus)
|
||||
val threadFriendStatus = when (type) {
|
||||
ActionType.Sending -> LokiThreadFriendRequestStatus.REQUEST_SENDING
|
||||
ActionType.Failed -> LokiThreadFriendRequestStatus.NONE
|
||||
ActionType.Sent -> LokiThreadFriendRequestStatus.REQUEST_SENT
|
||||
}
|
||||
DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(threadId, threadFriendStatus)
|
||||
|
||||
// Update message status
|
||||
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId)
|
||||
if (recipient != null && messageId >= 0) {
|
||||
if (messageId >= 0) {
|
||||
val messageDatabase = DatabaseFactory.getLokiMessageDatabase(context)
|
||||
val friendRequestStatus = messageDatabase.getFriendRequestStatus(messageId)
|
||||
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
|
||||
// This ensures that we don't spam the UI with accept/decline messages
|
||||
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId) ?: return
|
||||
if (!recipient.address.isPhone) { return }
|
||||
|
||||
isFriendsWithAnyLinkedDevice(context, recipient).successUi { isFriends ->
|
||||
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> {
|
||||
// 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 (publicKey == TextSecurePreferences.getMasterHexEncodedPublicKey(context)) {
|
||||
return Promise.of(true)
|
||||
|
Loading…
x
Reference in New Issue
Block a user