diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-05-13 10:45:30 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-05-13 10:45:30 +0200 |
commit | b756d61c45f5cd3a3c69dd93115ad558f41de216 (patch) | |
tree | 85bbb056fae16db58d6ca37992582819bedbbd4f /src | |
parent | e6ff1539b47d71142d8de0186149117d10f5ce72 (diff) |
show presence of other resources as template
Diffstat (limited to '')
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 c6b655d0..1cdf0d67 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 3b3ce08d..c268b24c 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 754175ab..7630fd93 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 977524d1..807aa4f9 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3290,6 +3290,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 6d13e7ea..0962d209 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 3740097e..cc3647e6 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1315,10 +1315,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(); |