aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-07-17 20:44:34 +0200
committerChristian Schneppe <christian@pix-art.de>2019-07-17 20:44:34 +0200
commitd52f09b6f4f165fda2d147cd968dcee23524c339 (patch)
tree74b2e4c17421cf285aee45801f189d577c01d057 /src/main
parentc88523b1b84e9226e524e8d9b7ef6987118cd2cd (diff)
handle blocking and unblocking of full jids
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/entities/RawBlockable.java92
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java4
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java5
-rw-r--r--src/main/java/de/pixart/messenger/services/AvatarService.java7
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java16
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlockContactDialog.java8
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlocklistActivity.java20
-rw-r--r--src/main/res/values/strings.xml2
8 files changed, 131 insertions, 23 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/RawBlockable.java b/src/main/java/de/pixart/messenger/entities/RawBlockable.java
new file mode 100644
index 000000000..0c8befc06
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/entities/RawBlockable.java
@@ -0,0 +1,92 @@
+package de.pixart.messenger.entities;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+import de.pixart.messenger.utils.UIHelper;
+import rocks.xmpp.addr.Jid;
+
+public class RawBlockable implements ListItem, Blockable {
+
+ private final Account account;
+ private final Jid jid;
+
+ public RawBlockable(Account account, Jid jid) {
+ this.account = account;
+ this.jid = jid;
+ }
+
+ @Override
+ public boolean isBlocked() {
+ return true;
+ }
+
+ @Override
+ public boolean isDomainBlocked() {
+ throw new AssertionError("not implemented");
+ }
+
+ @Override
+ public Jid getBlockedJid() {
+ return this.jid;
+ }
+
+ @Override
+ public String getDisplayName() {
+ if (jid.isFullJid()) {
+ return jid.getResource();
+ } else {
+ return jid.toEscapedString();
+ }
+ }
+
+ @Override
+ public int getOffline() {
+ return 0;
+ }
+
+ @Override
+ public Jid getJid() {
+ return this.jid;
+ }
+
+ @Override
+ public List<Tag> getTags(Context context) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean match(Context context, String needle) {
+ if (TextUtils.isEmpty(needle)) {
+ return true;
+ }
+ needle = needle.toLowerCase(Locale.US).trim();
+ String[] parts = needle.split("\\s+");
+ for (String part : parts) {
+ if (!jid.toEscapedString().contains(part)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public Account getAccount() {
+ return account;
+ }
+
+ @Override
+ public int getAvatarBackgroundColor() {
+ return UIHelper.getColorForName(jid.toEscapedString());
+ }
+
+ @Override
+ public int compareTo(ListItem o) {
+ return this.getDisplayName().compareToIgnoreCase(
+ o.getDisplayName());
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 52f9f5b01..e533dd723 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -304,7 +304,7 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
final Element block = iq.addChild("block", Namespace.BLOCKING);
- final Element item = block.addChild("item").setAttribute("jid", jid.asBareJid().toString());
+ final Element item = block.addChild("item").setAttribute("jid", jid.toEscapedString());
if (reportSpam) {
item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
}
@@ -315,7 +315,7 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket generateSetUnblockRequest(final Jid jid) {
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
final Element block = iq.addChild("unblock", Namespace.BLOCKING);
- block.addChild("item").setAttribute("jid", jid.asBareJid().toString());
+ block.addChild("item").setAttribute("jid", jid.toEscapedString());
return iq;
}
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index a0080e4da..d0831aef9 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -220,7 +220,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
service.reportBrokenSessionException(e, postpone);
return new Message(conversation, "", Message.ENCRYPTION_AXOLOTL_FAILED, status);
} else {
- Log.d(Config.LOGTAG, "ignoring broken session exception because checkForDuplicase failed");
+ Log.d(Config.LOGTAG, "ignoring broken session exception because checkForDuplicates failed");
+ //TODO should be still emit a failed message?
return null;
}
} catch (NotEncryptedForThisDeviceException e) {
@@ -557,7 +558,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
fallbacksBySourceId = Collections.emptySet();
origin = from;
}
-
+ //TODO either or is probably fine?
final boolean checkedForDuplicates = serverMsgId != null && remoteMsgId != null && !conversation.possibleDuplicate(serverMsgId, remoteMsgId);
if (origin != null) {
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java
index c38fdcc99..a07b3a6e5 100644
--- a/src/main/java/de/pixart/messenger/services/AvatarService.java
+++ b/src/main/java/de/pixart/messenger/services/AvatarService.java
@@ -38,6 +38,7 @@ import de.pixart.messenger.entities.Conversational;
import de.pixart.messenger.entities.ListItem;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.MucOptions;
+import de.pixart.messenger.entities.RawBlockable;
import de.pixart.messenger.http.services.MuclumbusService;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.OnAdvancedStreamFeaturesLoaded;
@@ -86,7 +87,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
} else if (avatarable instanceof MuclumbusService.Room) {
return get((MuclumbusService.Room) avatarable, size, cachedOnly);
}
- throw new AssertionError("AvatarService does not know how to generate avatar from "+avatarable.getClass().getName());
+ throw new AssertionError("AvatarService does not know how to generate avatar from " + avatarable.getClass().getName());
}
private Bitmap get(final MuclumbusService.Room result, final int size, boolean cacheOnly) {
@@ -275,7 +276,9 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
}
public Bitmap get(ListItem item, int size, boolean cachedOnly) {
- if (item instanceof Contact) {
+ if (item instanceof RawBlockable) {
+ return get(item.getDisplayName(), item.getJid().toEscapedString(), size, cachedOnly);
+ } else if (item instanceof Contact) {
return get((Contact) item, size, cachedOnly);
} else if (item instanceof Bookmark) {
Bookmark bookmark = (Bookmark) item;
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index cb18a1d7e..a0d298d47 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -4606,17 +4606,15 @@ public class XmppConnectionService extends Service {
public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
if (blockable != null && blockable.getBlockedJid() != null) {
final Jid jid = blockable.getBlockedJid();
- this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() {
-
- @Override
- public void onIqPacketReceived(final Account account, final IqPacket packet) {
- if (packet.getType() == IqPacket.TYPE.RESULT) {
- account.getBlocklist().add(jid);
- updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
- }
+ this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), (a, response) -> {
+ if (response.getType() == IqPacket.TYPE.RESULT) {
+ a.getBlocklist().add(jid);
+ updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
}
});
- if (removeBlockedConversations(blockable.getAccount(), jid)) {
+ if (blockable.getBlockedJid().isFullJid()) {
+ return false;
+ } else if (removeBlockedConversations(blockable.getAccount(), jid)) {
updateConversationUi();
return true;
} else {
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
index 4f768b009..562bf2efa 100644
--- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
@@ -25,14 +25,18 @@ public final class BlockContactDialog {
final String value;
@StringRes int res;
- if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(Jid.ofDomain(blockable.getJid().getDomain()))) {
+ if (blockable.getJid().isFullJid()) {
+ builder.setTitle(isBlocked ? R.string.action_unblock_participant : R.string.action_block_participant);
+ value = blockable.getJid().toEscapedString();
+ res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
+ } else if (blockable.getJid().getLocal() == null || blockable.getAccount().isBlocked(Jid.ofDomain(blockable.getJid().getDomain()))) {
builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
value = Jid.ofDomain(blockable.getJid().getDomain()).toString();
res = isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text;
} else {
int resBlockAction = blockable instanceof Conversation && ((Conversation) blockable).isWithStranger() ? R.string.block_stranger : R.string.action_block_contact;
builder.setTitle(isBlocked ? R.string.action_unblock_contact : resBlockAction);
- value = blockable.getJid().asBareJid().toString();
+ value = blockable.getJid().asBareJid().toEscapedString();
res = isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text;
}
binding.text.setText(JidDialog.style(xmppActivity, res, value));
diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
index 49422583d..2927fe3e3 100644
--- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
@@ -10,7 +10,10 @@ import java.util.Collections;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
+import de.pixart.messenger.entities.Blockable;
import de.pixart.messenger.entities.Contact;
+import de.pixart.messenger.entities.ListItem;
+import de.pixart.messenger.entities.RawBlockable;
import de.pixart.messenger.ui.interfaces.OnBackendConnected;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import rocks.xmpp.addr.Jid;
@@ -22,7 +25,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getListView().setOnItemLongClickListener((parent, view, position, id) -> {
- BlockContactDialog.show(BlocklistActivity.this, (Contact) getListItems().get(position));
+ BlockContactDialog.show(BlocklistActivity.this, (Blockable) getListItems().get(position));
return true;
});
this.binding.fab.show();
@@ -49,9 +52,14 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
getListItems().clear();
if (account != null) {
for (final Jid jid : account.getBlocklist()) {
- final Contact contact = account.getRoster().getContact(jid);
- if (contact.match(this, needle) && contact.isBlocked()) {
- getListItems().add(contact);
+ ListItem item;
+ if (jid.isFullJid()) {
+ item = new RawBlockable(account, jid);
+ } else {
+ item = account.getRoster().getContact(jid);
+ }
+ if (item.match(this, needle)) {
+ getListItems().add(item);
}
}
Collections.sort(getListItems());
@@ -78,8 +86,8 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
);
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
- Contact contact = account.getRoster().getContact(contactJid);
- if (xmppConnectionService.sendBlockRequest(contact, false)) {
+ Blockable blockable = new RawBlockable(account, contactJid);
+ if (xmppConnectionService.sendBlockRequest(blockable, false)) {
Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
}
return true;
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index ba865ca52..3407f6e9e 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -920,4 +920,6 @@
<string name="enable_message_encryption">This chat is unencrypted. For security reasons you should enable message encryption, preferable OMEMO. If anything isn\'t working for you, you could disable message encryption by pressing the key lock icon.</string>
<string name="hide_warning">Hide warning</string>
<string name="change_password_in_next_step">You can change the generated password in the next step to your needs.</string>
+ <string name="action_unblock_participant">Unblock participant</string>
+ <string name="action_block_participant">Block participant</string>
</resources>