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

Support AddToFolder for Multiple Selected Threads #13973

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sagar0-0
Copy link
Contributor

@Sagar0-0 Sagar0-0 commented Feb 6, 2025

First time contributor checklist

Contributor checklist

  • Device A, Android X.Y.Z
  • Device B, Android Z.Y
  • Virtual device W, Android Y.Y.Z
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Reason:
A user may want to add multiple chats in an existing or new folder, which was impossible YET.
I tested it thoroughly, previously I was having some FOREIGN KEY CONFLICT exception which crashed the app everytime when I try to "select all" chats and add it to an existing folder. This is not reproducing it for me. Let me know if anyone is able to reproduce it.

Next plans:
Remove from Folder for multi-select. Let me know if this sounds good.

I have also observed many initialization improvements in the code that we can improve to make the app opening time faster. Like Lazily adding the callbacks and more. Let me know if those PRs are welcomed.

@Sagar0-0
Copy link
Contributor Author

Sagar0-0 commented Feb 7, 2025

The issue was caused by allowing to add an archived chat to a folder. If an archived chat was added to any folder and then we tried to "select all" chats and then add them to any folder, the app crashed with android.database.sqlite.SQLiteConstraintException: FullCode: 787 | ErrorCode: 19 | ExtendedErrorCode: 3 | Message: FOREIGN KEY constraint failed | ExtraMessage: null.
Fixed this by not allowing "add to folder" from archived chats screen.

@Sagar0-0 Sagar0-0 force-pushed the support-addToFolder-for-multiple-threads branch from f952222 to d4980e0 Compare February 7, 2025 04:13
Copy link
Contributor

@mtang-signal mtang-signal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think this would be an amazing thing to add to chat folders :). Added some comments below, let me know if you have any questions!

Comment on lines +288 to +292
val threadIdsAndIsIncluded = threadIds.map { threadId ->
val isAlreadyIncluded = folders.find { it.chatFolder.id == folderId }?.chatFolder?.includedChats?.contains(threadId) ?: false
Pair(threadId,isAlreadyIncluded)
}
SignalDatabase.chatFolders.addToFolderIfNotIncluded(folderId, threadIdsAndIsIncluded)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mapping to pair, you can use threadIds.filter instead to filter out any included chats which will simplify the call and check made in addToFolderIfNotIncluded

Comment on lines +1511 to +1514
List<Conversation> conversations = new ArrayList<>();
conversations.add(conversation);
items.add(new ActionItem(R.drawable.symbol_folder_add, getString(R.string.ConversationListFragment_add_to_folder), () ->
AddToFolderBottomSheet.showChatFolderSheet(folders, conversation.getThreadRecord().getThreadId(), conversation.getThreadRecord().getRecipient().isIndividual()).show(getParentFragmentManager(), BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG)
showAddToFolderBottomSheet(conversations)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use Collections.singletonList or Arrays.listOf() instead within showAddToFolderBottomSheet here. But also see my point below about just passing in conversation.

@@ -1580,6 +1581,27 @@ public void onEvent(MessageSender.MessageSentEvent event) {
closeSearchIfOpen();
}

private void showAddToFolderBottomSheet(List<Conversation> conversations) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I'm wrong - it looks like this only gets called once with the singular conversation. If so, you can drop the size check and stream map, but I'd actually consider changing the parameter for this to just Conversation and then wrapping it in a list right before the call to showAddToFolderBottomSheet(List<Long> threadIds, Boolean isIndividual) since there's no benefit in having it be a list at this point.

Comment on lines 139 to +141
val isIncludedViaChatType = (isIndividualChat && folder.showIndividualChats) || (!isIndividualChat && folder.showGroupChats)
val isIncludedExplicitly = folder.includedChats.contains(threadId)
val isExcludedExplicitly = folder.excludedChats.contains(threadId)
val isIncludedExplicitly = folder.includedChats.containsAll(threadIds)
val isExcludedExplicitly = folder.excludedChats.containsAll(threadIds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first check won't fully work because in ConversationListFragment Line 1653, you're always passing false in. This means if you have a folder that is only "All 1:1 chats", isAlreadyAdded will always be false if you try to add multiple 1:1 chats. To fix, you can do what you did for thread -> threads, but there might be a cleaner way too.

Comment on lines 94 to 95
Toast.makeText(context, requireContext().getString(R.string.AddToFolderBottomSheet_this_chat_is_already, folder.name), Toast.LENGTH_SHORT).show()
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thing - this is a singular This chat is already in the folder x, but in cases where threadIds is plural, we'll want to change it to These chats are already in the folder x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants