introduce setting to ignore invites from strangers

This commit is contained in:
Daniel Gultsch 2024-04-22 12:49:27 +02:00 committed by Arne
parent a101605597
commit 72b5591012
6 changed files with 54 additions and 23 deletions

View file

@ -5,7 +5,6 @@ import android.util.Pair;
import android.net.Uri;
import de.monocles.chat.BobTransfer;
import de.monocles.chat.WebxdcUpdate;
import java.io.File;
@ -611,7 +610,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (selfAddressed) {
counterpart = from;
} else {
counterpart = to != null ? to : account.getJid();
counterpart = to;
}
} else {
status = Message.STATUS_RECEIVED;
@ -1509,33 +1508,55 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
this.inviter = inviter;
}
public boolean execute(Account account) {
return execute(account, null);
}
public boolean execute(final Account account, LocalizedContent body) {
if (this.jid == null) {
return false;
}
final Contact contact = this.inviter != null ? account.getRoster().getContact(this.inviter) : null;
final Contact contact =
this.inviter != null ? account.getRoster().getContact(this.inviter) : null;
if (contact != null && contact.isBlocked()) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ignore invite from "+contact.getJid()+" because contact is blocked");
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": ignore invite from "
+ contact.getJid()
+ " because contact is blocked");
return false;
}
final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true, false);
if (conversation.getMucOptions().online()) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received invite to " + jid + " but muc is considered to be online");
mXmppConnectionService.mucSelfPingAndRejoin(conversation);
} else {
conversation.getMucOptions().setPassword(password);
mXmppConnectionService.databaseBackend.updateConversation(conversation);
mXmppConnectionService.joinMuc(conversation, contact != null && contact.showInContactList());
mXmppConnectionService.updateConversationUi();
if (body != null) {
mXmppConnectionService.showInvitationNotification(conversation, contact, body);
if ((contact != null && contact.showInContactList())
|| mXmppConnectionService.getBooleanPreference("accept_invites_from_strangers", R.bool.accept_invites_from_strangers)) {
final Conversation conversation =
mXmppConnectionService.findOrCreateConversation(account, jid, true, false);
if (conversation.getMucOptions().online()) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": received invite to "
+ jid
+ " but muc is considered to be online");
mXmppConnectionService.mucSelfPingAndRejoin(conversation);
} else {
conversation.getMucOptions().setPassword(password);
mXmppConnectionService.databaseBackend.updateConversation(conversation);
mXmppConnectionService.joinMuc(
conversation, contact != null && contact.showInContactList());
mXmppConnectionService.updateConversationUi();
if (body != null) {
mXmppConnectionService.showInvitationNotification(conversation, contact, body);
}
}
return true;
} else {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": ignoring invite from "
+ this.inviter
+ " because we are not accepting invites from strangers. direct="
+ direct);
return false;
}
return true;
}
}
}

View file

@ -1392,14 +1392,15 @@ public abstract class XmppActivity extends ActionBarActivity {
return invite;
}
public boolean execute(XmppActivity activity) {
XmppConnectionService service = activity.xmppConnectionService;
Conversation conversation = service.findConversationByUuid(this.uuid);
public boolean execute(final XmppActivity activity) {
final XmppConnectionService service = activity.xmppConnectionService;
final Conversation conversation = service.findConversationByUuid(this.uuid);
if (conversation == null) {
return false;
}
if (conversation.getMode() == Conversation.MODE_MULTI) {
for (Jid jid : jids) {
for (final Jid jid : jids) {
// TODO use direct invites for public conferences
service.invite(conversation, jid);
}
return false;

View file

@ -310,6 +310,7 @@ public final class MucDetailsContextMenuHelper {
activity.privateMsgInMuc(conversation, user.getNick());
return true;
case R.id.invite:
// TODO use direct invites for public conferences
if (user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {
activity.xmppConnectionService.directInvite(conversation, jid.asBareJid());
} else {

View file

@ -14,4 +14,5 @@
<bool name="app_is_locked">false</bool>
<bool name="app_lock_enabled">false</bool>
<bool name="open_links_inapp">true</bool>
<bool name="accept_invites_from_strangers">false</bool>
</resources>

View file

@ -1439,4 +1439,6 @@
<string name="gif_imported">GIFs imported</string>
<string name="import_own_gifs">Import own GIFs</string>
<string name="import_own_gifs_summary">Import your own GIFs. They will be sorted by the filename.</string>
<string name="pref_accept_invites_from_strangers">Invites from strangers</string>
<string name="pref_accept_invites_from_strangers_summary">Accept invites to group chats from strangers</string>
</resources>

View file

@ -488,6 +488,11 @@
android:key="last_activity"
android:summary="@string/pref_broadcast_last_activity_summary"
android:title="@string/pref_broadcast_last_activity" />
<SwitchPreference
android:defaultValue="@bool/accept_invites_from_strangers"
android:key="accept_invites_from_strangers"
android:summary="@string/pref_accept_invites_from_strangers_summary"
android:title="@string/pref_accept_invites_from_strangers" />
<SwitchPreference
android:defaultValue="@bool/send_link_previews"
android:key="send_link_previews"