Skip to content

Commit

Permalink
Add support for XEP-0191 (Blocking command)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWhited committed Dec 22, 2014
1 parent 9656970 commit af7a644
Show file tree
Hide file tree
Showing 44 changed files with 1,485 additions and 904 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ run your own XMPP server for you and your friends. These XEP's are:
* XEP-0313: Message Archive Management synchronize message history with the
server. Catch up with messages that were sent while Conversations was
offline.
* XEP-0352: Client State Indication let the server know whether or not
* XEP-0352: Client State Indication lets the server know whether or not
Conversations is in the background. Allows the server to save bandwidth by
withholding unimportant packages.
* XEP-0191: Blocking command lets you blacklist spammers or block contacts
without removing them from your roster.

## Team

Expand Down
1 change: 1 addition & 0 deletions docs/XEPs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
* XEP-0313: Message Archive Management
* XEP-0333: Chat Markers
* XEP-0352: Client State Indication
* XEP-0191: Blocking command
3 changes: 3 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<activity
android:name=".ui.ChooseContactActivity"
android:label="@string/title_activity_choose_contact" />
<activity
android:name=".ui.BlocklistActivity"
android:label="@string/title_activity_block_list" />
<activity
android:name=".ui.ManageAccountActivity"
android:configChanges="orientation|screenSize"
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/eu/siacs/conversations/entities/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.json.JSONObject;

import java.security.interfaces.DSAPublicKey;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
Expand Down Expand Up @@ -56,7 +58,7 @@ public static enum State {
SECURITY_ERROR(true),
INCOMPATIBLE_SERVER(true);

private boolean isError;
private final boolean isError;

public boolean isError() {
return this.isError;
Expand Down Expand Up @@ -120,6 +122,7 @@ public int getReadableId() {
private String otrFingerprint;
private final Roster roster = new Roster(this);
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
private final Collection<Jid> blocklist = new CopyOnWriteArraySet<>();

public Account() {
this.uuid = "0";
Expand Down Expand Up @@ -279,7 +282,7 @@ public ContentValues getContentValues() {
return values;
}

public void initOtrEngine(XmppConnectionService context) {
public void initOtrEngine(final XmppConnectionService context) {
this.otrEngine = new OtrEngine(context, this);
}

Expand All @@ -291,7 +294,7 @@ public XmppConnection getXmppConnection() {
return this.xmppConnection;
}

public void setXmppConnection(XmppConnection connection) {
public void setXmppConnection(final XmppConnection connection) {
this.xmppConnection = connection;
}

Expand Down Expand Up @@ -323,7 +326,7 @@ public String getRosterVersion() {
}
}

public void setRosterVersion(String version) {
public void setRosterVersion(final String version) {
this.rosterVersion = version;
}

Expand Down Expand Up @@ -351,7 +354,7 @@ public List<Bookmark> getBookmarks() {
return this.bookmarks;
}

public void setBookmarks(List<Bookmark> bookmarks) {
public void setBookmarks(final List<Bookmark> bookmarks) {
this.bookmarks = bookmarks;
}

Expand Down Expand Up @@ -399,4 +402,21 @@ public String getShareableUri() {
return "xmpp:" + this.getJid().toBareJid().toString();
}
}

public boolean isBlocked(final ListItem contact) {
final Jid jid = contact.getJid();
return jid != null && (blocklist.contains(jid.toBareJid()) || blocklist.contains(jid.toDomainJid()));
}

public boolean isBlocked(final Jid jid) {
return jid != null && blocklist.contains(jid.toBareJid());
}

public Collection<Jid> getBlocklist() {
return this.blocklist;
}

public void clearBlocklist() {
getBlocklist().clear();
}
}
11 changes: 11 additions & 0 deletions src/main/java/eu/siacs/conversations/entities/Blockable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.siacs.conversations.entities;

import eu.siacs.conversations.xmpp.jid.Jid;

public interface Blockable {
public boolean isBlocked();
public boolean isDomainBlocked();
public Jid getBlockedJid();
public Jid getJid();
public Account getAccount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;

public class Bookmark extends Element implements ListItem {
Expand Down
52 changes: 36 additions & 16 deletions src/main/java/eu/siacs/conversations/entities/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;

public class Contact implements ListItem {
public class Contact implements ListItem, Blockable {
public static final String TABLENAME = "contacts";

public static final String SYSTEMNAME = "systemname";
Expand Down Expand Up @@ -47,8 +47,8 @@ public class Contact implements ListItem {
protected Account account;

public Contact(final String account, final String systemName, final String serverName,
final Jid jid, final int subscription, final String photoUri,
final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
final Jid jid, final int subscription, final String photoUri,
final String systemAccount, final String keys, final String avatar, final Lastseen lastseen, final String groups) {
this.accountUuid = account;
this.systemName = systemName;
this.serverName = serverName;
Expand Down Expand Up @@ -122,11 +122,10 @@ public Jid getJid() {

@Override
public List<Tag> getTags() {
ArrayList<Tag> tags = new ArrayList<Tag>();
for (String group : getGroups()) {
final ArrayList<Tag> tags = new ArrayList<>();
for (final String group : getGroups()) {
tags.add(new Tag(group, UIHelper.getColorForName(group)));
}
int status = getMostAvailableStatus();
switch (getMostAvailableStatus()) {
case Presences.CHAT:
case Presences.ONLINE:
Expand All @@ -142,6 +141,9 @@ public List<Tag> getTags() {
tags.add(new Tag("dnd", 0xffe51c23));
break;
}
if (isBlocked()) {
tags.add(new Tag("blocked", 0xff2e2f3b));
}
return tags;
}

Expand Down Expand Up @@ -176,7 +178,7 @@ private boolean matchInTag(String needle) {
}

public ContentValues getContentValues() {
ContentValues values = new ContentValues();
final ContentValues values = new ContentValues();
values.put(ACCOUNT, accountUuid);
values.put(SYSTEMNAME, systemName);
values.put(SERVERNAME, serverName);
Expand Down Expand Up @@ -213,11 +215,11 @@ public void setPresences(Presences pres) {
this.presences = pres;
}

public void updatePresence(String resource, int status) {
public void updatePresence(final String resource, final int status) {
this.presences.updatePresence(resource, status);
}

public void removePresence(String resource) {
public void removePresence(final String resource) {
this.presences.removePresence(resource);
}

Expand Down Expand Up @@ -337,8 +339,8 @@ public boolean getOption(int option) {

public boolean showInRoster() {
return (this.getOption(Contact.Options.IN_ROSTER) && (!this
.getOption(Contact.Options.DIRTY_DELETE)))
|| (this.getOption(Contact.Options.DIRTY_PUSH));
.getOption(Contact.Options.DIRTY_DELETE)))
|| (this.getOption(Contact.Options.DIRTY_PUSH));
}

public void parseSubscriptionFromElement(Element item) {
Expand Down Expand Up @@ -428,7 +430,7 @@ public boolean deleteOtrFingerprint(String fingerprint) {
if (this.keys.has("otr_fingerprints")) {
JSONArray newPrints = new JSONArray();
JSONArray oldPrints = this.keys
.getJSONArray("otr_fingerprints");
.getJSONArray("otr_fingerprints");
for (int i = 0; i < oldPrints.length(); ++i) {
if (!oldPrints.getString(i).equals(fingerprint)) {
newPrints.put(oldPrints.getString(i));
Expand Down Expand Up @@ -457,22 +459,40 @@ public String getShareableUri() {
}
}

@Override
public boolean isBlocked() {
return getAccount().isBlocked(this);
}

@Override
public boolean isDomainBlocked() {
return getAccount().isBlocked(this.getJid().toDomainJid());
}

@Override
public Jid getBlockedJid() {
if (isDomainBlocked()) {
return getJid().toDomainJid();
} else {
return getJid();
}
}

public static class Lastseen {
public long time;
public String presence;

public Lastseen() {
time = 0;
presence = null;
this(null, 0);
}

public Lastseen(final String presence, final long time) {
this.time = time;
this.presence = presence;
this.time = time;
}
}

public class Options {
public final class Options {
public static final int TO = 0;
public static final int FROM = 1;
public static final int ASKING = 2;
Expand Down
Loading

0 comments on commit af7a644

Please sign in to comment.