use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchCaps.
public void fetchCaps(Account account, final Jid jid, final Presence presence) {
final Pair<String, String> key = new Pair<>(presence.getHash(), presence.getVer());
ServiceDiscoveryResult disco = getCachedServiceDiscoveryResult(key);
if (disco != null) {
presence.setServiceDiscoveryResult(disco);
} else {
if (!account.inProgressDiscoFetches.contains(key)) {
account.inProgressDiscoFetches.add(key);
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.setTo(jid);
request.query("http://jabber.org/protocol/disco#info");
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": making disco request for " + key.second + " to " + jid);
sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket discoPacket) {
if (discoPacket.getType() == IqPacket.TYPE.RESULT) {
ServiceDiscoveryResult disco = new ServiceDiscoveryResult(discoPacket);
if (presence.getVer().equals(disco.getVer())) {
databaseBackend.insertDiscoveryResult(disco);
injectServiceDiscorveryResult(account.getRoster(), presence.getHash(), presence.getVer(), disco);
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + disco.getVer());
}
}
account.inProgressDiscoFetches.remove(key);
}
});
}
}
}
use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchConferenceMembers.
private void fetchConferenceMembers(final Conversation conversation) {
final Account account = conversation.getAccount();
final AxolotlService axolotlService = account.getAxolotlService();
final String[] affiliations = { "member", "admin", "owner" };
OnIqPacketReceived callback = new OnIqPacketReceived() {
private int i = 0;
private boolean success = true;
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Element query = packet.query("http://jabber.org/protocol/muc#admin");
if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
for (Element child : query.getChildren()) {
if ("item".equals(child.getName())) {
MucOptions.User user = AbstractParser.parseItem(conversation, child);
if (!user.realJidMatchesAccount()) {
boolean isNew = conversation.getMucOptions().updateUser(user);
Contact contact = user.getContact();
if (isNew && user.getRealJid() != null && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
axolotlService.fetchDeviceIds(user.getRealJid());
}
}
}
}
} else {
success = false;
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().toBareJid());
}
++i;
if (i >= affiliations.length) {
List<Jid> members = conversation.getMucOptions().getMembers();
if (success) {
List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
boolean changed = false;
for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
Jid jid = iterator.next();
if (!members.contains(jid)) {
iterator.remove();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
changed = true;
}
}
if (changed) {
conversation.setAcceptedCryptoTargets(cryptoTargets);
updateConversation(conversation);
}
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved members for " + conversation.getJid().toBareJid() + ": " + conversation.getMucOptions().getMembers());
getAvatarService().clear(conversation);
updateMucRosterUi();
updateConversationUi();
}
}
};
for (String affiliation : affiliations) {
sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching members for " + conversation.getName());
}
use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchRosterFromServer.
public void fetchRosterFromServer(final Account account) {
final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
if (!"".equals(account.getRosterVersion())) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster version " + account.getRosterVersion());
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster");
}
iqPacket.query(Namespace.ROSTER).setAttribute("ver", account.getRosterVersion());
sendIqPacket(account, iqPacket, mIqParser);
}
use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method destroyConference.
public void destroyConference(final Conversation conference, final OnDestroyMuc callback) {
IqPacket request = this.mIqGenerator.destroyConference(conference);
sendIqPacket(conference.getAccount(), request, (account, packet) -> {
if (packet.getType() == IqPacket.TYPE.RESULT) {
callback.OnDestroyMucSuccessful(R.string.destroy_muc_succeed);
} else {
callback.OnDestroyMucFailed(R.string.destroy_muc_failed);
}
});
}
use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method pushConferenceConfiguration.
public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConfigurationPushed callback) {
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.setTo(conversation.getJid().toBareJid());
request.query("http://jabber.org/protocol/muc#owner");
sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
Data data = Data.parse(packet.query().findChild("x", Namespace.DATA));
data.submit(options);
IqPacket set = new IqPacket(IqPacket.TYPE.SET);
set.setTo(conversation.getJid().toBareJid());
set.query("http://jabber.org/protocol/muc#owner").addChild(data);
sendIqPacket(account, set, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
if (callback != null) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
callback.onPushSucceeded();
} else {
callback.onPushFailed();
}
}
}
});
} else {
if (callback != null) {
callback.onPushFailed();
}
}
}
});
}
Aggregations