Check for gateway/pstn after caps has been fetched

Previously we would check for the identity at contact presence change,
but the first time the contact comes online (say, during onboarding or
first app use) the contact has never had service discovery done and so
the identity is not known.  Move the identity check to after the service
discovery has certainly been done in order to be sure it works first
time.
This commit is contained in:
Stephen Paul Weber 2022-04-19 08:34:17 -05:00
parent abde1336e8
commit af12ac91d0
No known key found for this signature in database
GPG Key ID: D11C2911CE519CDE
1 changed files with 8 additions and 4 deletions

View File

@ -237,10 +237,6 @@ public class XmppConnectionService extends Service {
}
}
}
if (contact.getPresences().anyIdentity("gateway", "pstn")) {
contact.registerAsPhoneAccount(this);
}
};
private final PresenceGenerator mPresenceGenerator = new PresenceGenerator(this);
private List<Account> accounts;
@ -4677,12 +4673,16 @@ public class XmppConnectionService extends Service {
public void fetchCaps(Account account, final Jid jid, final Presence presence) {
final Pair<String, String> key = new Pair<>(presence.getHash(), presence.getVer());
final ServiceDiscoveryResult disco = getCachedServiceDiscoveryResult(key);
if (disco != null) {
presence.setServiceDiscoveryResult(disco);
final Contact contact = account.getRoster().getContact(jid);
if (contact.refreshRtpCapability()) {
syncRoster(account);
}
if (disco.hasIdentity("gateway", "pstn")) {
contact.registerAsPhoneAccount(this);
}
} else {
final IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.setTo(jid);
@ -4699,6 +4699,10 @@ public class XmppConnectionService extends Service {
if (presence.getVer().equals(discoveryResult.getVer())) {
databaseBackend.insertDiscoveryResult(discoveryResult);
injectServiceDiscoveryResult(a.getRoster(), presence.getHash(), presence.getVer(), discoveryResult);
if (discoveryResult.hasIdentity("gateway", "pstn")) {
final Contact contact = account.getRoster().getContact(jid);
contact.registerAsPhoneAccount(this);
}
} else {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + discoveryResult.getVer());
}