better self contact handling

This commit is contained in:
kosyak 2023-12-27 01:11:01 +01:00
parent 6284ee12af
commit 78410291b7
5 changed files with 28 additions and 0 deletions

View file

@ -720,6 +720,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
@Override
public int compareTo(@NonNull Conversation another) {
return ComparisonChain.start()
.compareFalseFirst(another.getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false) && another.withSelf(), getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false) && withSelf())
.compareFalseFirst(another.getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false), getBooleanAttribute(ATTRIBUTE_PINNED_ON_TOP, false))
.compare(another.getSortableTime(), getSortableTime())
.result();

View file

@ -64,6 +64,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.FragmentConversationsOverviewBinding;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.services.XmppConnectionService;
@ -74,6 +75,7 @@ import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PendingActionHelper;
import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.ui.util.ScrollState;
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.utils.AccountUtils;
import eu.siacs.conversations.utils.EasyOnboardingInvite;
@ -315,7 +317,12 @@ public class ConversationsOverviewFragment extends XmppFragment {
menuInflater.inflate(R.menu.fragment_conversations_overview, menu);
AccountUtils.showHideMenuItems(menu);
final MenuItem easyOnboardInvite = menu.findItem(R.id.action_easy_invite);
MenuItem noteToSelf = menu.findItem(R.id.action_note_to_self);
easyOnboardInvite.setVisible(EasyOnboardingInvite.anyHasSupport(activity == null ? null : activity.xmppConnectionService));
if (activity == null || activity.xmppConnectionService == null || activity.xmppConnectionService.getAccounts().size() != 1) {
noteToSelf.setVisible(false);
}
}
@Override
@ -430,6 +437,14 @@ public class ConversationsOverviewFragment extends XmppFragment {
case R.id.action_easy_invite:
selectAccountToStartEasyInvite();
return true;
case R.id.action_note_to_self:
final List<Account> accounts = activity.xmppConnectionService.getAccounts();
if (accounts.size() == 1) {
final Contact self = new Contact(accounts.get(0).getSelfContact());
Conversation conversation = activity.xmppConnectionService.findOrCreateConversation(self.getAccount(), self.getJid(), null, false, false, true, null);
SoftKeyboardUtils.hideSoftKeyboard(activity);
activity.switchToConversation(conversation);
}
}
return super.onOptionsItemSelected(item);
}

View file

@ -72,6 +72,10 @@ public class ConversationAdapter
name = viewHolder.binding.getRoot().getResources().getString(R.string.muc_private_conversation_title, conversation.getNextCounterpart().getResource(), conversation.getName());
}
if (conversation.withSelf()) {
name = viewHolder.binding.getRoot().getResources().getString(R.string.note_to_self_conversation_title, name);
}
if (name instanceof Jid) {
viewHolder.binding.conversationName.setText(
IrregularUnicodeDetector.style(activity, (Jid) name));

View file

@ -35,6 +35,13 @@
android:title="@string/search_messages"
android:visible="@bool/show_individual_search_options"
app:showAsAction="never" />
<item
android:id="@+id/action_note_to_self"
android:orderInCategory="80"
android:title="@string/note_to_self"
app:showAsAction="never"/>
<item
android:id="@+id/action_easy_invite"
android:orderInCategory="89"

View file

@ -1072,6 +1072,7 @@
<string name="filter">filter</string>
<string name="could_not_create_file">could_not_create_file</string>
<string name="muc_private_conversation_title">%1$s (%2$s)</string>
<string name="note_to_self_conversation_title">Note to self (%1$s)</string>
<string name="muc_private_conversation_info_title">Private conversation with:</string>
<string name="message_selection_title">%1$d selected</string>
<string name="contact_tag_general">General</string>