mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-05 00:35:01 -05:00
show presence of other resources as template
This commit is contained in:
parent
e6ff1539b4
commit
b756d61c45
@ -79,6 +79,10 @@ public class Account extends AbstractEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public Contact getSelfContact() {
|
||||
return getRoster().getContact(jid);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
DISABLED,
|
||||
OFFLINE,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user