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

delete groups, send on enter tweak #22

Merged
merged 2 commits into from
Oct 22, 2023
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
26 changes: 26 additions & 0 deletions src/main/java/com/zoffcc/applications/trifa/HelperGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
54 changes: 48 additions & 6 deletions src/main/kotlin/com/zoffcc/applications/trifa/GroupStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupItem> = emptyList(), val selectedGroupId: String? = null, val selectedGroup: GroupItem? = null)
Expand Down Expand Up @@ -55,7 +54,16 @@ fun CoroutineScope.createGroupStore(): GroupStore
}
if (!found)
{
mutableStateFlow.value = state.copy(groups = (state.groups + item))
var new_groups: ArrayList<GroupItem> = 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()
}
Expand All @@ -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<GroupItem> = 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()
}
}
Expand Down Expand Up @@ -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<GroupItem> = 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)
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/HelperGeneric.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 14 additions & 8 deletions src/main/kotlin/com/zoffcc/applications/trifa2/GroupSendMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions src/main/kotlin/com/zoffcc/applications/trifa2/SendMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading