Skip to content

Commit 6df2740

Browse files
committed
Make it possible to leave channels
- In a chat, if the chat is an InBroadcast, and it's not a contact request, then the `Leave` menu option is shown with the translated stock string `menu_leave_channel` as its label. - If the user clicks on it, the confirmation dialog has `menu_leave_channel` (rather than `menu_leave_group`) as its positive option. Counterpart of chatmail/core#6984.
1 parent c60ab44 commit 6df2740

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/java/org/thoughtcrime/securesms/ConversationActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
import androidx.annotation.NonNull;
6161
import androidx.annotation.Nullable;
62+
import androidx.annotation.StringRes;
6263
import androidx.appcompat.app.ActionBar;
6364
import androidx.appcompat.app.AlertDialog;
6465
import androidx.appcompat.widget.SearchView;
@@ -446,9 +447,10 @@ public boolean onPrepareOptionsMenu(Menu menu) {
446447
}
447448

448449
if (isMultiUser()) {
449-
if (dcChat.isEncrypted()
450+
if (dcChat.isInBroadcast() && !dcChat.isContactRequest()) {
451+
menu.findItem(R.id.menu_leave).setTitle(R.string.menu_leave_channel).setVisible(true);
452+
} else if (dcChat.isEncrypted()
450453
&& dcChat.canSend()
451-
&& !dcChat.isInBroadcast()
452454
&& !dcChat.isOutBroadcast()
453455
&& !dcChat.isMailingList()) {
454456
menu.findItem(R.id.menu_leave).setVisible(true);
@@ -625,9 +627,16 @@ private void handleProfile(boolean showApps) {
625627
}
626628

627629
private void handleLeaveGroup() {
630+
@StringRes int leaveLabel;
631+
if (dcChat.isInBroadcast()) {
632+
leaveLabel = R.string.menu_leave_channel;
633+
} else {
634+
leaveLabel = R.string.menu_leave_group;
635+
}
636+
628637
AlertDialog dialog = new AlertDialog.Builder(this)
629638
.setMessage(getString(R.string.ask_leave_group))
630-
.setPositiveButton(R.string.menu_leave_group, (d, which) -> {
639+
.setPositiveButton(leaveLabel, (d, which) -> {
631640
dcContext.removeContactFromChat(chatId, DcContact.DC_CONTACT_ID_SELF);
632641
Toast.makeText(this, getString(R.string.done), Toast.LENGTH_SHORT).show();
633642
})

src/main/res/values/strings.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
<string name="menu_unarchive_chat">Unarchive Chat</string>
271271
<string name="menu_add_attachment">Add Attachment</string>
272272
<string name="menu_leave_group">Leave Group</string>
273+
<string name="menu_leave_channel">Leave Channel</string>
273274
<string name="menu_delete_chat">Delete Chat</string>
274275
<!-- Command to delete all messages in a chat. The chat itself will not be deleted but will be empty afterwards, so make sure to be different from "Delete Chat" here. "Clear" is a verb here, "Empty Chat" would also be fine (eg. in German "Chat leeren") -->
275276
<string name="clear_chat">Clear Chat</string>
@@ -390,7 +391,7 @@
390391
<string name="videochat_invitation_body">You are invited to a video chat, click %1$s to join.</string>
391392

392393
<!-- get confirmations -->
393-
<string name="ask_leave_group">Are you sure you want to leave this group?</string>
394+
<string name="ask_leave_group">Are you sure you want to leave?</string>
394395
<plurals name="ask_delete_chat">
395396
<item quantity="one">Delete %d chat on all your devices?</item>
396397
<item quantity="other">Delete %d chats on all your devices?</item>
@@ -920,7 +921,7 @@
920921
<!-- %1$s will be replaced by name and address of the contact removed from the group, %2$s will be replaced by name and address of the contact who did the action -->
921922
<string name="remove_member_by_other">Member %1$s removed by %2$s.</string>
922923
<!-- "left" in the meaning of "exited" -->
923-
<string name="group_left_by_you">You left the group.</string>
924+
<string name="group_left_by_you">You left.</string>
924925
<!-- "left" in the meaning of "exited"; %1$s will be replaced by name and address of the contact leaving the group -->
925926
<string name="group_left_by_other">Group left by %1$s.</string>
926927
<string name="group_image_deleted_by_you">You deleted the group image.</string>

0 commit comments

Comments
 (0)