get rid of special self presence object and incorporate that into roster

This commit is contained in:
iNPUTmice 2014-12-20 17:23:03 +01:00
parent ce4848f742
commit 1517641713
3 changed files with 46 additions and 75 deletions

View File

@ -116,10 +116,9 @@ public class Account extends AbstractEntity {
protected boolean online = false;
private OtrEngine otrEngine = null;
private XmppConnection xmppConnection = null;
private Presences presences = new Presences();
private long mEndGracePeriod = 0L;
private String otrFingerprint;
private Roster roster = null;
private final Roster roster = new Roster(this);
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
public Account() {
@ -328,20 +327,8 @@ public class Account extends AbstractEntity {
this.rosterVersion = version;
}
public void updatePresence(String resource, int status) {
this.presences.updatePresence(resource, status);
}
public void removePresence(String resource) {
this.presences.removePresence(resource);
}
public void clearPresences() {
this.presences = new Presences();
}
public int countPresences() {
return this.presences.size();
return this.getRoster().getContact(this.getJid().toBareJid()).getPresences().size();
}
public String getPgpSignature() {
@ -357,9 +344,6 @@ public class Account extends AbstractEntity {
}
public Roster getRoster() {
if (this.roster == null) {
this.roster = new Roster(this);
}
return this.roster;
}

View File

@ -45,68 +45,56 @@ public class PresenceParser extends AbstractParser implements
}
final Jid from = packet.getFrom();
String type = packet.getAttribute("type");
if (from.toBareJid().equals(account.getJid().toBareJid())) {
Contact contact = account.getRoster().getContact(packet.getFrom());
if (type == null) {
String presence;
if (!from.isBareJid()) {
if (type == null) {
account.updatePresence(from.getResourcepart(),
Presences.parseShow(packet.findChild("show")));
} else if (type.equals("unavailable")) {
account.removePresence(from.getResourcepart());
account.deactivateGracePeriod();
}
presence = from.getResourcepart();
} else {
presence = "";
}
} else {
Contact contact = account.getRoster().getContact(packet.getFrom());
if (type == null) {
String presence;
if (!from.isBareJid()) {
presence = from.getResourcepart();
} else {
presence = "";
}
int sizeBefore = contact.getPresences().size();
contact.updatePresence(presence,
Presences.parseShow(packet.findChild("show")));
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
if (pgp != null) {
Element x = packet.findChild("x", "jabber:x:signed");
if (x != null) {
Element status = packet.findChild("status");
String msg;
if (status != null) {
msg = status.getContent();
} else {
msg = "";
}
contact.setPgpKeyId(pgp.fetchKeyId(account, msg,
x.getContent()));
int sizeBefore = contact.getPresences().size();
contact.updatePresence(presence,
Presences.parseShow(packet.findChild("show")));
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
if (pgp != null) {
Element x = packet.findChild("x", "jabber:x:signed");
if (x != null) {
Element status = packet.findChild("status");
String msg;
if (status != null) {
msg = status.getContent();
} else {
msg = "";
}
}
boolean online = sizeBefore < contact.getPresences().size();
updateLastseen(packet, account, true);
mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact, online);
} else if (type.equals("unavailable")) {
if (from.isBareJid()) {
contact.clearPresences();
} else {
contact.removePresence(from.getResourcepart());
}
mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact, false);
} else if (type.equals("subscribe")) {
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
mXmppConnectionService.sendPresencePacket(account,
mPresenceGenerator.sendPresenceUpdatesTo(contact));
} else {
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
contact.setPgpKeyId(pgp.fetchKeyId(account, msg,
x.getContent()));
}
}
Element nick = packet.findChild("nick",
"http://jabber.org/protocol/nick");
if (nick != null) {
contact.setPresenceName(nick.getContent());
boolean online = sizeBefore < contact.getPresences().size();
updateLastseen(packet, account, true);
mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact, online);
} else if (type.equals("unavailable")) {
if (from.isBareJid()) {
contact.clearPresences();
} else {
contact.removePresence(from.getResourcepart());
}
mXmppConnectionService.onContactStatusChanged
.onContactStatusChanged(contact, false);
} else if (type.equals("subscribe")) {
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
mXmppConnectionService.sendPresencePacket(account,
mPresenceGenerator.sendPresenceUpdatesTo(contact));
} else {
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
}
}
Element nick = packet.findChild("nick",
"http://jabber.org/protocol/nick");
if (nick != null) {
contact.setPresenceName(nick.getContent());
}
mXmppConnectionService.updateRosterUi();
}

View File

@ -241,7 +241,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onBind(final Account account) {
account.getRoster().clearPresences();
account.clearPresences(); // self presences
account.pendingConferenceJoins.clear();
account.pendingConferenceLeaves.clear();
fetchRosterFromServer(account);