-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix friend request messages not always being logged
They were missing if you accepted a friend request from the long-press menu on a friend request in the contact list. This commit moves the logic for adding it down one layer, so now it can't be missed unless you skip over abstractions.
- Loading branch information
1 parent
286cc3f
commit 338e544
Showing
3 changed files
with
22 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2020-2022 aTox contributors | ||
// SPDX-FileCopyrightText: 2020-2024 Robin Lindén <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 aTox contributors | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
|
@@ -7,36 +8,13 @@ package ltd.evilcorp.atox.ui.friendrequest | |
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.asLiveData | ||
import java.util.Date | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import ltd.evilcorp.core.repository.MessageRepository | ||
import ltd.evilcorp.core.vo.FriendRequest | ||
import ltd.evilcorp.core.vo.Message | ||
import ltd.evilcorp.core.vo.MessageType | ||
import ltd.evilcorp.core.vo.Sender | ||
import ltd.evilcorp.domain.feature.FriendRequestManager | ||
import ltd.evilcorp.domain.tox.PublicKey | ||
|
||
class FriendRequestViewModel @Inject constructor( | ||
private val scope: CoroutineScope, | ||
private val friendRequests: FriendRequestManager, | ||
private val messageRepository: MessageRepository, | ||
) : ViewModel() { | ||
class FriendRequestViewModel @Inject constructor(private val friendRequests: FriendRequestManager) : ViewModel() { | ||
fun byId(pk: PublicKey): LiveData<FriendRequest> = friendRequests.get(pk).asLiveData() | ||
fun accept(request: FriendRequest) = friendRequests.accept(request) | ||
fun reject(request: FriendRequest) = friendRequests.reject(request) | ||
fun addToChatLog(request: FriendRequest) = scope.launch { | ||
messageRepository.add( | ||
Message( | ||
request.publicKey, | ||
request.message, | ||
Sender.Received, | ||
MessageType.Normal, | ||
0, | ||
Date().time, | ||
), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters