diff --git a/src/main/java/com/zoffcc/applications/trifa/HelperGroup.java b/src/main/java/com/zoffcc/applications/trifa/HelperGroup.java index c53dcd58..8138be15 100644 --- a/src/main/java/com/zoffcc/applications/trifa/HelperGroup.java +++ b/src/main/java/com/zoffcc/applications/trifa/HelperGroup.java @@ -283,4 +283,30 @@ static incoming_group_file_meta_data handle_incoming_group_file(long group_numbe } return null; } + + static void delete_group_all_messages(final String group_identifier) + { + try + { + TrifaToxService.Companion.getOrma().deleteFromGroupMessage().group_identifierEq(group_identifier.toLowerCase()).execute(); + } + catch (Exception e) + { + e.printStackTrace(); + Log.i(TAG, "group_conference_all_messages:EE:" + e.getMessage()); + } + } + + static void delete_group(final String group_identifier) + { + try + { + TrifaToxService.Companion.getOrma().deleteFromGroupDB().group_identifierEq(group_identifier.toLowerCase()).execute(); + } + catch (Exception e) + { + e.printStackTrace(); + Log.i(TAG, "delete_group:EE:" + e.getMessage()); + } + } } diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/GroupStore.kt b/src/main/kotlin/com/zoffcc/applications/trifa/GroupStore.kt index 14467027..e5ff9795 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/GroupStore.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/GroupStore.kt @@ -2,11 +2,10 @@ package com.zoffcc.applications.trifa import global_semaphore_grouplist_ui import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.consumeAsFlow import kotlinx.coroutines.launch +import org.briarproject.briar.desktop.contact.ContactItem import org.briarproject.briar.desktop.contact.GroupItem data class StateGroups(val groups: List = emptyList(), val selectedGroupId: String? = null, val selectedGroup: GroupItem? = null) @@ -55,7 +54,16 @@ fun CoroutineScope.createGroupStore(): GroupStore } if (!found) { - mutableStateFlow.value = state.copy(groups = (state.groups + item)) + var new_groups: ArrayList = ArrayList() + new_groups.addAll(state.groups) + new_groups.forEach { item2 -> + if (item2.groupId == item.groupId) + { + new_groups.remove(item2) + } + } + new_groups.add(item) + mutableStateFlow.value = state.copy(groups = new_groups) } global_semaphore_grouplist_ui.release() } @@ -65,13 +73,33 @@ fun CoroutineScope.createGroupStore(): GroupStore { launch { global_semaphore_grouplist_ui.acquire() - var found = false + var sel_groupid = state.selectedGroupId + var sel_item = state.selectedGroup + var new_groups: ArrayList = ArrayList() + new_groups.addAll(state.groups) + var to_remove_item: GroupItem? = null state.groups.forEach { if (item.groupId == it.groupId) { - mutableStateFlow.value = state.copy(groups = (state.groups - item)) + if (state.selectedGroupId == it.groupId) + { + sel_groupid = null + sel_item = null + } + new_groups.forEach { item2 -> + if (item2.groupId == it.groupId) + { + to_remove_item = item2 + } + } } } + if (to_remove_item != null) + { + new_groups.remove(to_remove_item) + } + mutableStateFlow.value = state.copy(groups = new_groups, + selectedGroup = sel_item, selectedGroupId = sel_groupid) global_semaphore_grouplist_ui.release() } } @@ -110,7 +138,21 @@ fun CoroutineScope.createGroupStore(): GroupStore } if (update_item != null) { - mutableStateFlow.value = state.copy(groups = (state.groups + item - update_item!!), selectedGroupId = state.selectedGroupId, selectedGroup = state.selectedGroup) + var new_groups: ArrayList = ArrayList() + new_groups.addAll(state.groups) + var to_remove_item: GroupItem? = null + new_groups.forEach { item2 -> + if (item2.groupId == update_item!!.groupId) + { + to_remove_item = item2 + } + } + if (to_remove_item != null) + { + new_groups.remove(to_remove_item) + } + new_groups.add(item) + mutableStateFlow.value = state.copy(groups = new_groups, selectedGroupId = state.selectedGroupId, selectedGroup = state.selectedGroup) } else { mutableStateFlow.value = state.copy(groups = (state.groups + item), selectedGroupId = state.selectedGroupId, selectedGroup = state.selectedGroup) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt b/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt index 6ff7cc20..68b5ff3a 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt @@ -25,12 +25,17 @@ import com.zoffcc.applications.trifa.HelperFiletransfer.set_filetransfer_state_f import com.zoffcc.applications.trifa.HelperFriend.delete_friend import com.zoffcc.applications.trifa.HelperFriend.delete_friend_all_filetransfers import com.zoffcc.applications.trifa.HelperFriend.delete_friend_all_messages +import com.zoffcc.applications.trifa.HelperGroup.delete_group +import com.zoffcc.applications.trifa.HelperGroup.delete_group_all_messages +import com.zoffcc.applications.trifa.HelperGroup.tox_group_by_groupid__wrapper import com.zoffcc.applications.trifa.HelperMessage.set_message_queueing_from_id import com.zoffcc.applications.trifa.HelperMessage.set_message_state_from_id import com.zoffcc.applications.trifa.MainActivity.Companion.modify_message_with_ft import com.zoffcc.applications.trifa.MainActivity.Companion.tox_file_control import com.zoffcc.applications.trifa.MainActivity.Companion.tox_friend_by_public_key import com.zoffcc.applications.trifa.MainActivity.Companion.tox_friend_delete +import com.zoffcc.applications.trifa.MainActivity.Companion.tox_group_by_chat_id +import com.zoffcc.applications.trifa.MainActivity.Companion.tox_group_leave import com.zoffcc.applications.trifa.MainActivity.Companion.update_savedata_file import com.zoffcc.applications.trifa.TrifaToxService.Companion.orma import kotlinx.coroutines.withContext @@ -73,6 +78,18 @@ object HelperGeneric { } } + fun delete_group_wrapper(group_id: String) + { + val group_num_temp: Long = tox_group_by_groupid__wrapper(group_id) + delete_group_all_messages(group_id) + delete_group(group_id) + if (group_num_temp > -1) + { + tox_group_leave(group_num_temp, "quit") + update_savedata_file_wrapper() + } + } + fun delete_friend_wrapper(friend_pubkey: String) { val friend_num_temp: Long = tox_friend_by_public_key(friend_pubkey) diff --git a/src/main/kotlin/com/zoffcc/applications/trifa2/GroupSendMessage.kt b/src/main/kotlin/com/zoffcc/applications/trifa2/GroupSendMessage.kt index 4506d943..d659fd1f 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa2/GroupSendMessage.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa2/GroupSendMessage.kt @@ -52,20 +52,26 @@ fun GroupSendMessage(sendGroupMessage: (String) -> Unit) { .focusRequester(textFieldFocusRequester) .onPreviewKeyEvent { when { - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyUp) -> { - sendGroupMessage(inputText) - inputText = "" + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyDown) -> { + if (inputText.isNotEmpty()) + { + sendGroupMessage(inputText) + inputText = "" + } true } - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyUp) -> { - sendGroupMessage(inputText) - inputText = "" + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyDown) -> { + if (inputText.isNotEmpty()) + { + sendGroupMessage(inputText) + inputText = "" + } true } - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyDown) -> { + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyUp) -> { true } - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyDown) -> { + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyUp) -> { true } else -> false diff --git a/src/main/kotlin/com/zoffcc/applications/trifa2/SendMessage.kt b/src/main/kotlin/com/zoffcc/applications/trifa2/SendMessage.kt index bb142b17..9a6bc7a9 100644 --- a/src/main/kotlin/com/zoffcc/applications/trifa2/SendMessage.kt +++ b/src/main/kotlin/com/zoffcc/applications/trifa2/SendMessage.kt @@ -55,20 +55,26 @@ fun SendMessage(sendMessage: (String) -> Unit) { .focusRequester(textFieldFocusRequester) .onPreviewKeyEvent { when { - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyUp) -> { - sendMessage(inputText) - inputText = "" + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyDown) -> { + if (inputText.isNotEmpty()) + { + sendMessage(inputText) + inputText = "" + } true } - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyUp) -> { - sendMessage(inputText) - inputText = "" + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyDown) -> { + if (inputText.isNotEmpty()) + { + sendMessage(inputText) + inputText = "" + } true } - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyDown) -> { + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.Enter && it.type == KeyEventType.KeyUp) -> { true } - (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyDown) -> { + (!it.isMetaPressed && !it.isAltPressed && !it.isCtrlPressed && !it.isShiftPressed && it.key == Key.NumPadEnter && it.type == KeyEventType.KeyUp) -> { true } else -> false diff --git a/src/main/kotlin/org/briarproject/briar/desktop/contact/GroupList.kt b/src/main/kotlin/org/briarproject/briar/desktop/contact/GroupList.kt index e1f8b109..85be863c 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/contact/GroupList.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/contact/GroupList.kt @@ -2,6 +2,8 @@ package org.briarproject.briar.desktop.contact import CONTACT_COLUMN_WIDTH import TOP_HEADER_SIZE +import androidx.compose.foundation.ContextMenuArea +import androidx.compose.foundation.ContextMenuItem import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn @@ -13,10 +15,14 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp +import com.zoffcc.applications.trifa.HelperGeneric import com.zoffcc.applications.trifa.StateContacts import com.zoffcc.applications.trifa.StateGroups import contactstore import groupstore +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import org.briarproject.briar.desktop.ui.ListItemView import org.briarproject.briar.desktop.ui.VerticallyScrollableArea import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n @@ -50,10 +56,22 @@ fun GroupList( .fillMaxWidth() .padding(vertical = 8.dp) .padding(start = 16.dp, end = 4.dp) - GroupItemView( - groupItem = item, - modifier = modifier - ) + ContextMenuArea(items = { + listOf( + ContextMenuItem("delete") { + groupstore.remove(item = GroupItem(privacyState = 0, name = "", isConnected = 0, groupId = item.groupId)) + GlobalScope.launch(Dispatchers.IO) { + HelperGeneric.delete_group_wrapper(item.groupId) + } + // delete a group including all messages + }, + ) + }) { + GroupItemView( + groupItem = item, + modifier = modifier + ) + } } } } diff --git a/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt b/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt index 93b17467..765fa1c1 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/utils/InternationalizationUtils.kt @@ -48,7 +48,7 @@ object InternationalizationUtils { val resourceBundle = createResourceBundle() resourceBundle.getString(key) } catch (e: MissingResourceException) { - Log.i(TAG, "Missing string resource for key '$key'" ) + // Log.i(TAG, "Missing string resource for key '$key'" ) key }