Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search in groupmessages and messages #220

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ import com.vanniktech.emoji.search.SearchEmojiManager
import com.zoffcc.applications.ffmpegav.AVActivity
import com.zoffcc.applications.ffmpegav.AVActivity.JAVA_AUDIO_IN_DEVICE_NAME
import com.zoffcc.applications.sorm.BootstrapNodeEntryDB
import com.zoffcc.applications.sorm.GroupMessage
import com.zoffcc.applications.sorm.Message
import com.zoffcc.applications.trifa.AVState
import com.zoffcc.applications.trifa.AudioBar
import com.zoffcc.applications.trifa.AudioBar.audio_in_bar
Expand All @@ -125,6 +127,7 @@ import com.zoffcc.applications.trifa.CustomSemaphore
import com.zoffcc.applications.trifa.EmojiStrAndName
import com.zoffcc.applications.trifa.FriendSettingDetails
import com.zoffcc.applications.trifa.GroupSettingDetails
import com.zoffcc.applications.trifa.GroupStoreFilterFilter
import com.zoffcc.applications.trifa.HelperGeneric.PubkeyShort
import com.zoffcc.applications.trifa.HelperGeneric.ngc_video_frame_last_incoming_ts
import com.zoffcc.applications.trifa.HelperGroup
Expand Down Expand Up @@ -191,7 +194,6 @@ import org.briarproject.briar.desktop.ui.UiMode
import org.briarproject.briar.desktop.ui.UiPlaceholder
import org.briarproject.briar.desktop.ui.VerticalDivider
import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
import java.awt.GraphicsEnvironment
import java.awt.Toolkit
import java.io.File
import java.net.URI
Expand Down Expand Up @@ -1203,7 +1205,10 @@ fun App()
}
ChatAppWithScaffold(focusRequester = focusRequester, contactList = contacts, ui_scale = ui_scale)
LaunchedEffect(contacts.selectedContactPubkey) {
// HINT: focus on the message input field
focusRequester.requestFocus()
Log.i(TAG, "FFFFFF1111111111111: focus on the message input field")
contactstore.messageresetFilter()
}
}
}
Expand Down Expand Up @@ -1248,7 +1253,10 @@ fun App()
}
GroupAppWithScaffold(focusRequester = groupfocusRequester, groupList = groups, ui_scale = ui_scale)
LaunchedEffect(groups.selectedGroupId) {
// HINT: focus on the group message input field
groupfocusRequester.requestFocus()
Log.i(TAG, "FFFFgg1111111111111: focus on the group message input field")
groupstore.groupmessageresetFilter()
}
}
}
Expand Down Expand Up @@ -1327,8 +1335,28 @@ fun load_messages_for_friend(selectedContactPubkey: String?)
} catch(_: Exception) {
}
val uimessages = ArrayList<UIMessage>()
val messages = orma!!.selectFromMessage().
tox_friendpubkeyEq(toxpk).orderBySent_timestampAsc().toList()
var messages: MutableList<Message>? = null
val filter_active = contactstore.state.messageFilterActive
val filter_value_raw = contactstore.state.messageFilterString
val filter_value = GroupStoreFilterFilter(filter_value_raw)
if ((filter_active) &&
(!filter_value_raw.isNullOrEmpty()) &&
(filter_value_raw.isNotBlank()) &&
(filter_value_raw.length > 0))
{
messages = orma!!.
selectFromMessage().
tox_friendpubkeyEq(toxpk).
textLike("%" + filter_value + "%").
orderBySent_timestampAsc().toList()
}
else
{
messages = orma!!.
selectFromMessage().
tox_friendpubkeyEq(toxpk).
orderBySent_timestampAsc().toList()
}
messages.forEach() {
when (it.direction)
{
Expand Down Expand Up @@ -1383,7 +1411,7 @@ fun load_groupmessages(selectedGroupId: String?)
{
if (selectedGroupId != null)
{
// Log.i(TAG, "load_groupmessages")
Log.i(TAG, "load_groupmessages")
try
{
val groupid = selectedGroupId.lowercase()
Expand All @@ -1393,7 +1421,30 @@ fun load_groupmessages(selectedGroupId: String?)
} catch(_: Exception) {
}
val uigroupmessages = ArrayList<UIGroupMessage>()
val messages = orma!!.selectFromGroupMessage().group_identifierEq(selectedGroupId).orderBySent_timestampAsc().toList()
var messages: MutableList<GroupMessage>? = null
val filter_active = groupstore.state.groupmessageFilterActive
val filter_value_raw = groupstore.state.groupmessageFilterString
val filter_value = GroupStoreFilterFilter(filter_value_raw)
if ((filter_active) &&
(!filter_value_raw.isNullOrEmpty()) &&
(filter_value_raw.isNotBlank()) &&
(filter_value_raw.length > 0))
{
messages = orma!!
.selectFromGroupMessage()
.group_identifierEq(selectedGroupId)
.textLike("%" + filter_value + "%")
.orderBySent_timestampAsc()
.toList()
}
else
{
messages = orma!!
.selectFromGroupMessage()
.group_identifierEq(selectedGroupId)
.orderBySent_timestampAsc()
.toList()
}
messages.forEach() { // 0 -> msg received, 1 -> msg sent
when (it.direction)
{
Expand Down
28 changes: 27 additions & 1 deletion src/main/kotlin/com/zoffcc/applications/trifa/ContactStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import org.briarproject.briar.desktop.contact.ContactItem

data class StateContacts(val contacts: List<ContactItem> = emptyList(), val visible: Boolean = false, val selectedContactPubkey: String? = null, val selectedContact: ContactItem? = null)
data class StateContacts(val contacts: List<ContactItem> = emptyList(), val visible: Boolean = false,
val selectedContactPubkey: String? = null, val selectedContact: ContactItem? = null,
var messageFilterActive: Boolean = false, var messageFilterString: String = "")

const val TAG = "trifa.ContactsStore"

Expand All @@ -17,6 +19,9 @@ interface ContactStore
fun select(pubkey: String?)
fun visible(value: Boolean)
fun clear()
fun messagefilterActive(value: Boolean)
fun messagefilterString(value: String)
fun messageresetFilter()
fun update(item: ContactItem)
fun update_ipaddr(pubkey: String, ipaddr: String)
val stateFlow: StateFlow<StateContacts>
Expand Down Expand Up @@ -216,6 +221,27 @@ fun CoroutineScope.createContactStore(): ContactStore
global_semaphore_contactlist_ui.release()
//}
}

override fun messagefilterActive(value: Boolean)
{
global_semaphore_contactlist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(messageFilterActive = value )
global_semaphore_contactlist_ui.release()
}

override fun messageresetFilter()
{
global_semaphore_contactlist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(messageFilterString = "", messageFilterActive = false)
global_semaphore_contactlist_ui.release()
}

override fun messagefilterString(value: String)
{
global_semaphore_contactlist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(messageFilterString = value)
global_semaphore_contactlist_ui.release()
}
}
}

Expand Down
41 changes: 38 additions & 3 deletions src/main/kotlin/com/zoffcc/applications/trifa/GroupStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import global_semaphore_grouplist_ui
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.briarproject.briar.desktop.contact.ContactItem
import org.briarproject.briar.desktop.contact.GroupItem

data class StateGroups(val groups: List<GroupItem> = emptyList(), val visible: Boolean = false, val selectedGroupId: String? = null, val selectedGroup: GroupItem? = null)
data class StateGroups(val groups: List<GroupItem> = emptyList(), val visible: Boolean = false,
val selectedGroupId: String? = null, val selectedGroup: GroupItem? = null,
var groupmessageFilterActive: Boolean = false, var groupmessageFilterString: String = "")

interface GroupStore
{
Expand All @@ -17,11 +17,25 @@ interface GroupStore
fun select(pubkey: String?)
fun visible(value: Boolean)
fun clear()
fun groupmessagefilterActive(value: Boolean)
fun groupmessagefilterString(value: String)
fun groupmessageresetFilter()
fun update(item: GroupItem)
val stateFlow: StateFlow<StateGroups>
val state get() = stateFlow.value
}

fun GroupStoreFilterFilter(filterstring_raw: String): String
{
try
{
return filterstring_raw.replace("\\", "\\\\").replace("%", "\\%")
} catch (_: Exception)
{
return filterstring_raw
}
}

fun CoroutineScope.createGroupStore(): GroupStore
{
val TAG = "trifa.GroupStore"
Expand Down Expand Up @@ -180,5 +194,26 @@ fun CoroutineScope.createGroupStore(): GroupStore
global_semaphore_grouplist_ui.release()
//}
}

override fun groupmessagefilterActive(value: Boolean)
{
global_semaphore_grouplist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(groupmessageFilterActive = value )
global_semaphore_grouplist_ui.release()
}

override fun groupmessageresetFilter()
{
global_semaphore_grouplist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(groupmessageFilterString = "", groupmessageFilterActive = false)
global_semaphore_grouplist_ui.release()
}

override fun groupmessagefilterString(value: String)
{
global_semaphore_grouplist_ui.acquire((Throwable().stackTrace[0].fileName + ":" + Throwable().stackTrace[0].lineNumber))
mutableStateFlow.value = state.copy(groupmessageFilterString = value)
global_semaphore_grouplist_ui.release()
}
}
}
Loading
Loading