Ask to moderate recent when banning if MUC supports it

This commit is contained in:
Stephen Paul Weber 2023-08-29 17:53:25 +02:00 committed by Arne
parent cbf96e846c
commit 04fd5257fa

View file

@ -17,14 +17,17 @@ import android.view.MenuItem;
import android.view.View;
import androidx.appcompat.app.AlertDialog;
import androidx.databinding.DataBindingUtil;
import java.util.ArrayList;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.DialogQuickeditBinding;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.entities.RawBlockable;
@ -198,6 +201,23 @@ public final class MucDetailsContextMenuHelper {
return onContextItemSelected(item, user, activity, null);
}
public static void maybeModerateRecent(XmppActivity activity, Conversation conversation, User user) {
if (!conversation.getMucOptions().getSelf().getRole().ranks(MucOptions.Role.MODERATOR) || !conversation.getMucOptions().hasFeature("urn:xmpp:message-moderate:0")) return;
DialogQuickeditBinding binding = DataBindingUtil.inflate(activity.getLayoutInflater(), R.layout.dialog_quickedit, null, false);
binding.inputEditText.setText("Spam");
new AlertDialog.Builder(activity)
.setTitle(R.string.moderate_recent)
.setMessage("Do you want to moderate all recent messages from this user?")
.setView(binding.getRoot())
.setPositiveButton(R.string.yes, (dialog, whichButton) -> {
for (Message m : conversation.findMessagesBy(user)) {
activity.xmppConnectionService.moderateMessage(conversation.getAccount(), m, binding.inputEditText.getText().toString());
}
})
.setNegativeButton(R.string.no, null).show();
}
public static boolean onContextItemSelected(MenuItem item, User user, XmppActivity activity, final String fingerprint) {
final Conversation conversation = user.getConversation();
final XmppConnectionService.OnAffiliationChanged onAffiliationChanged = activity instanceof XmppConnectionService.OnAffiliationChanged ? (XmppConnectionService.OnAffiliationChanged) activity : null;
@ -255,6 +275,7 @@ public final class MucDetailsContextMenuHelper {
if (user.getRole() != MucOptions.Role.NONE) {
activity.xmppConnectionService.changeRoleInConference(conversation, user.getName(), MucOptions.Role.NONE);
}
maybeModerateRecent(activity, conversation, user);
break;
case ACTION_GRANT_MEMBERSHIP:
case ACTION_REMOVE_ADMIN: