session-android/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupViewModel.kt
ceokot fbd1721eaf
Menu redesign (#958)
* feat: Menu redesign

* Add bottomsheet

* Handle default peek height

* Smooth out setting peek height

* Move contacts prep to util

* Dialog layout tweaks

* Contact grouping tweaks

* Add new message dialog

* Add public key input delegate

* Add create group dialog

* Add join community dialog

* Handle dialog back navigation

* Enter community url tab tweaks

* Scan QR code tab refactor

* Scan qr code refactor

* Direct and community tabs refactor

* Add session id copy context menu item

* Set dialog background colours

* Set full dialog background colour

* Minor tweaks

* Add closed group contact search

* Cleanup

* Add content descriptions

* Resize community chips

* Fix new conversation screen paddings

* Fix fade in/out of join community screen

* Prevent creating conversation with empty public key

* Resize and position create group loader

* Fix back nav after creating direct message conversation

* Fix inter-screen transitions

* Fix new conversation background colours

* Fix background colours

* Rename contact list header for clarity

* Bug fixes

* Enable scrolling of Enter Session ID tab of the new message dialog

* Minor refactor

* Switch to child fragment manager

* Fix member search on create group screen

Co-authored-by: charles <charles@oxen.io>
2022-09-30 13:32:07 +10:00

46 lines
1.7 KiB
Kotlin

package org.thoughtcrime.securesms.groups
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.database.ThreadDatabase
import javax.inject.Inject
@HiltViewModel
class CreateGroupViewModel @Inject constructor(
private val threadDb: ThreadDatabase,
private val textSecurePreferences: TextSecurePreferences
) : ViewModel() {
private val _recipients = MutableLiveData<List<Recipient>>()
val recipients: LiveData<List<Recipient>> = _recipients
init {
viewModelScope.launch {
threadDb.approvedConversationList.use { openCursor ->
val reader = threadDb.readerFor(openCursor)
val recipients = mutableListOf<Recipient>()
while (true) {
recipients += reader.next?.recipient ?: break
}
withContext(Dispatchers.Main) {
_recipients.value = recipients
.filter { !it.isGroupRecipient && it.hasApprovedMe() && it.address.serialize() != textSecurePreferences.getLocalNumber() }
}
}
}
}
fun filter(query: String): List<Recipient> {
return _recipients.value?.filter {
it.address.serialize().contains(query, ignoreCase = true) || it.name?.contains(query, ignoreCase = true) == true
} ?: emptyList()
}
}