aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-05-13 10:45:30 +0200
committerChristian Schneppe <christian@pix-art.de>2016-05-13 21:56:27 +0200
commitfb5bd2488b7ca50b09bd8f561bcd14ad65a67893 (patch)
tree6ba25d42271ee95e08bed6dc997aad708a207b86 /src/main
parent5cd17f98a522964043ad6b7aa9c262fbab4e8a17 (diff)
show presence of other resources as template
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java4
-rw-r--r--src/main/java/eu/siacs/conversations/entities/PresenceTemplate.java20
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Presences.java11
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java10
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java4
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java6
6 files changed, 49 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java
index c6b655d0a..1cdf0d673 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -79,6 +79,10 @@ public class Account extends AbstractEntity {
}
}
+ public Contact getSelfContact() {
+ return getRoster().getContact(jid);
+ }
+
public enum State {
DISABLED,
OFFLINE,
diff --git a/src/main/java/eu/siacs/conversations/entities/PresenceTemplate.java b/src/main/java/eu/siacs/conversations/entities/PresenceTemplate.java
index 3b3ce08db..c268b24c2 100644
--- a/src/main/java/eu/siacs/conversations/entities/PresenceTemplate.java
+++ b/src/main/java/eu/siacs/conversations/entities/PresenceTemplate.java
@@ -53,4 +53,24 @@ public class PresenceTemplate extends AbstractEntity {
public String getStatusMessage() {
return statusMessage;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PresenceTemplate template = (PresenceTemplate) o;
+
+ if (statusMessage != null ? !statusMessage.equals(template.statusMessage) : template.statusMessage != null)
+ return false;
+ return status == template.status;
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = statusMessage != null ? statusMessage.hashCode() : 0;
+ result = 31 * result + status.hashCode();
+ return result;
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/entities/Presences.java b/src/main/java/eu/siacs/conversations/entities/Presences.java
index 754175ab2..7630fd936 100644
--- a/src/main/java/eu/siacs/conversations/entities/Presences.java
+++ b/src/main/java/eu/siacs/conversations/entities/Presences.java
@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import eu.siacs.conversations.xml.Element;
@@ -54,6 +55,16 @@ public class Presences {
}
}
+ public List<PresenceTemplate> asTemplates() {
+ synchronized (this.presences) {
+ ArrayList<PresenceTemplate> templates = new ArrayList<>(presences.size());
+ for(Presence p : presences.values()) {
+ templates.add(new PresenceTemplate(p.getStatus(),p.getMessage()));
+ }
+ return templates;
+ }
+ }
+
public boolean has(String presence) {
synchronized (this.presences) {
return presences.containsKey(presence);
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index ff84e6567..1da05ce5e 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -3285,6 +3285,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
}
+ public List<PresenceTemplate> getPresenceTemplates(Account account) {
+ List<PresenceTemplate> templates = databaseBackend.getPresenceTemplates();
+ for(PresenceTemplate template : account.getSelfContact().getPresences().asTemplates()) {
+ if (!templates.contains(template)) {
+ templates.add(0, template);
+ }
+ }
+ return templates;
+ }
+
public interface OnMamPreferencesFetched {
void onPreferencesFetched(Element prefs);
void onPreferencesFetchFailed();
diff --git a/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java b/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java
index 6d13e7eac..0962d209b 100644
--- a/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SetPresenceActivity.java
@@ -118,7 +118,7 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
xmppConnectionService.changeStatus(status, statusMessage);
finish();
} else if (mAccount != null) {
- if (mAccount.getPgpId() == 0 && hasPgp()) {
+ if (mAccount.getPgpId() == 0 || !hasPgp()) {
xmppConnectionService.changeStatus(mAccount, status, statusMessage, true);
finish();
} else {
@@ -177,7 +177,7 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
if (mStatusMessage.getText().length() == 0 && message != null) {
mStatusMessage.append(message);
}
- mTemplates = xmppConnectionService.databaseBackend.getPresenceTemplates();
+ mTemplates = xmppConnectionService.getPresenceTemplates(mAccount);
if (this.mPostponedActivityResult != null) {
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
}
diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
index f9f8fb3bf..c4d5bfdf1 100644
--- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -1328,10 +1328,8 @@ public class XmppConnection implements Runnable {
}
socket.close();
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": closed tcp without closing stream");
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
+ } catch (IOException | InterruptedException e) {
+ return;
}
}
}).start();