get rid of special self presence object and incorporate that into roster
This commit is contained in:
		
							parent
							
								
									ce4848f742
								
							
						
					
					
						commit
						1517641713
					
				| 
						 | 
					@ -116,10 +116,9 @@ public class Account extends AbstractEntity {
 | 
				
			||||||
	protected boolean online = false;
 | 
						protected boolean online = false;
 | 
				
			||||||
	private OtrEngine otrEngine = null;
 | 
						private OtrEngine otrEngine = null;
 | 
				
			||||||
	private XmppConnection xmppConnection = null;
 | 
						private XmppConnection xmppConnection = null;
 | 
				
			||||||
	private Presences presences = new Presences();
 | 
					 | 
				
			||||||
	private long mEndGracePeriod = 0L;
 | 
						private long mEndGracePeriod = 0L;
 | 
				
			||||||
	private String otrFingerprint;
 | 
						private String otrFingerprint;
 | 
				
			||||||
	private Roster roster = null;
 | 
						private final Roster roster = new Roster(this);
 | 
				
			||||||
	private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
 | 
						private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Account() {
 | 
						public Account() {
 | 
				
			||||||
| 
						 | 
					@ -328,20 +327,8 @@ public class Account extends AbstractEntity {
 | 
				
			||||||
		this.rosterVersion = version;
 | 
							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() {
 | 
						public int countPresences() {
 | 
				
			||||||
		return this.presences.size();
 | 
							return this.getRoster().getContact(this.getJid().toBareJid()).getPresences().size();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public String getPgpSignature() {
 | 
						public String getPgpSignature() {
 | 
				
			||||||
| 
						 | 
					@ -357,9 +344,6 @@ public class Account extends AbstractEntity {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Roster getRoster() {
 | 
						public Roster getRoster() {
 | 
				
			||||||
		if (this.roster == null) {
 | 
					 | 
				
			||||||
			this.roster = new Roster(this);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return this.roster;
 | 
							return this.roster;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,68 +45,56 @@ public class PresenceParser extends AbstractParser implements
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		final Jid from = packet.getFrom();
 | 
							final Jid from = packet.getFrom();
 | 
				
			||||||
		String type = packet.getAttribute("type");
 | 
							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 (!from.isBareJid()) {
 | 
				
			||||||
				if (type == null) {
 | 
									presence = from.getResourcepart();
 | 
				
			||||||
					account.updatePresence(from.getResourcepart(),
 | 
								} else {
 | 
				
			||||||
							Presences.parseShow(packet.findChild("show")));
 | 
									presence = "";
 | 
				
			||||||
				} else if (type.equals("unavailable")) {
 | 
					 | 
				
			||||||
					account.removePresence(from.getResourcepart());
 | 
					 | 
				
			||||||
					account.deactivateGracePeriod();
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
								int sizeBefore = contact.getPresences().size();
 | 
				
			||||||
			Contact contact = account.getRoster().getContact(packet.getFrom());
 | 
								contact.updatePresence(presence,
 | 
				
			||||||
			if (type == null) {
 | 
										Presences.parseShow(packet.findChild("show")));
 | 
				
			||||||
				String presence;
 | 
								PgpEngine pgp = mXmppConnectionService.getPgpEngine();
 | 
				
			||||||
				if (!from.isBareJid()) {
 | 
								if (pgp != null) {
 | 
				
			||||||
					presence = from.getResourcepart();
 | 
									Element x = packet.findChild("x", "jabber:x:signed");
 | 
				
			||||||
				} else {
 | 
									if (x != null) {
 | 
				
			||||||
					presence = "";
 | 
										Element status = packet.findChild("status");
 | 
				
			||||||
				}
 | 
										String msg;
 | 
				
			||||||
				int sizeBefore = contact.getPresences().size();
 | 
										if (status != null) {
 | 
				
			||||||
				contact.updatePresence(presence,
 | 
											msg = status.getContent();
 | 
				
			||||||
						Presences.parseShow(packet.findChild("show")));
 | 
										} else {
 | 
				
			||||||
				PgpEngine pgp = mXmppConnectionService.getPgpEngine();
 | 
											msg = "";
 | 
				
			||||||
				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()));
 | 
					 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
										contact.setPgpKeyId(pgp.fetchKeyId(account, msg,
 | 
				
			||||||
				boolean online = sizeBefore < contact.getPresences().size();
 | 
												x.getContent()));
 | 
				
			||||||
				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",
 | 
								boolean online = sizeBefore < contact.getPresences().size();
 | 
				
			||||||
					"http://jabber.org/protocol/nick");
 | 
								updateLastseen(packet, account, true);
 | 
				
			||||||
			if (nick != null) {
 | 
								mXmppConnectionService.onContactStatusChanged
 | 
				
			||||||
				contact.setPresenceName(nick.getContent());
 | 
										.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();
 | 
							mXmppConnectionService.updateRosterUi();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -241,7 +241,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
 | 
				
			||||||
		@Override
 | 
							@Override
 | 
				
			||||||
		public void onBind(final Account account) {
 | 
							public void onBind(final Account account) {
 | 
				
			||||||
			account.getRoster().clearPresences();
 | 
								account.getRoster().clearPresences();
 | 
				
			||||||
			account.clearPresences(); // self presences
 | 
					 | 
				
			||||||
			account.pendingConferenceJoins.clear();
 | 
								account.pendingConferenceJoins.clear();
 | 
				
			||||||
			account.pendingConferenceLeaves.clear();
 | 
								account.pendingConferenceLeaves.clear();
 | 
				
			||||||
			fetchRosterFromServer(account);
 | 
								fetchRosterFromServer(account);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue