use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class MessageParser method extractInvite.
private Invite extractInvite(Element message) {
final Element mucUser = message.findChild("x", Namespace.MUC_USER);
if (mucUser != null) {
Element invite = mucUser.findChild("invite");
if (invite != null) {
String password = mucUser.findChildContent("password");
Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from"));
Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
if (room == null) {
return null;
}
return new Invite(room, password, false, from);
}
}
final Element conference = message.findChild("x", "jabber:x:conference");
if (conference != null) {
Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
Jid room = InvalidJid.getNullForInvalid(conference.getAttributeAsJid("jid"));
if (room == null) {
return null;
}
return new Invite(room, conference.getAttribute("password"), true, from);
}
return null;
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class MessageParser method handleErrorMessage.
private boolean handleErrorMessage(final Account account, final MessagePacket packet) {
if (packet.getType() == MessagePacket.TYPE_ERROR) {
if (packet.fromServer(account)) {
final Pair<MessagePacket, Long> forwarded = packet.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
if (forwarded != null) {
return handleErrorMessage(account, forwarded.first);
}
}
final Jid from = packet.getFrom();
final String id = packet.getId();
if (from != null && id != null) {
if (id.startsWith(JingleRtpConnection.JINGLE_MESSAGE_PROPOSE_ID_PREFIX)) {
final String sessionId = id.substring(JingleRtpConnection.JINGLE_MESSAGE_PROPOSE_ID_PREFIX.length());
mXmppConnectionService.getJingleConnectionManager().updateProposedSessionDiscovered(account, from, sessionId, JingleConnectionManager.DeviceDiscoveryState.FAILED);
return true;
}
if (id.startsWith(JingleRtpConnection.JINGLE_MESSAGE_PROCEED_ID_PREFIX)) {
final String sessionId = id.substring(JingleRtpConnection.JINGLE_MESSAGE_PROCEED_ID_PREFIX.length());
mXmppConnectionService.getJingleConnectionManager().failProceed(account, from, sessionId);
return true;
}
mXmppConnectionService.markMessage(account, from.asBareJid(), id, Message.STATUS_SEND_FAILED, extractErrorMessage(packet));
final Element error = packet.findChild("error");
final boolean pingWorthyError = error != null && (error.hasChild("not-acceptable") || error.hasChild("remote-server-timeout") || error.hasChild("remote-server-not-found"));
if (pingWorthyError) {
Conversation conversation = mXmppConnectionService.find(account, from);
if (conversation != null && conversation.getMode() == Conversational.MODE_MULTI) {
if (conversation.getMucOptions().online()) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received ping worthy error for seemingly online muc at " + from);
mXmppConnectionService.mucSelfPingAndRejoin(conversation);
}
}
}
}
return true;
}
return false;
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class IqParser method rosterItems.
private void rosterItems(final Account account, final Element query) {
final String version = query.getAttribute("ver");
if (version != null) {
account.getRoster().setVersion(version);
}
for (final Element item : query.getChildren()) {
if (item.getName().equals("item")) {
final Jid jid = InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
if (jid == null) {
continue;
}
final String name = item.getAttribute("name");
final String subscription = item.getAttribute("subscription");
final Contact contact = account.getRoster().getContact(jid);
boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
contact.setServerName(name);
contact.parseGroupsFromElement(item);
}
if ("remove".equals(subscription)) {
contact.resetOption(Contact.Options.IN_ROSTER);
contact.resetOption(Contact.Options.DIRTY_DELETE);
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
} else {
contact.setOption(Contact.Options.IN_ROSTER);
contact.resetOption(Contact.Options.DIRTY_PUSH);
contact.parseSubscriptionFromElement(item);
}
boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
if ((both != bothPre) && both) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": gained mutual presence subscription with " + contact.getJid());
AxolotlService axolotlService = account.getAxolotlService();
if (axolotlService != null) {
axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
}
}
mXmppConnectionService.getAvatarService().clear(contact);
}
}
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
mXmppConnectionService.getShortcutService().refresh();
mXmppConnectionService.syncRoster(account);
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class IqParser method items.
public static List<Jid> items(IqPacket packet) {
ArrayList<Jid> items = new ArrayList<>();
final Element query = packet.findChild("query", Namespace.DISCO_ITEMS);
if (query == null) {
return items;
}
for (Element child : query.getChildren()) {
if ("item".equals(child.getName())) {
Jid jid = child.getAttributeAsJid("jid");
if (jid != null) {
items.add(jid);
}
}
}
return items;
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class DatabaseBackend method getAccountJids.
public List<Jid> getAccountJids(final boolean enabledOnly) {
SQLiteDatabase db = this.getReadableDatabase();
final List<Jid> jids = new ArrayList<>();
final String[] columns = new String[] { Account.USERNAME, Account.SERVER };
String where = enabledOnly ? "not options & (1 <<1)" : null;
Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null);
try {
while (cursor.moveToNext()) {
jids.add(Jid.of(cursor.getString(0), cursor.getString(1), null));
}
return jids;
} catch (Exception e) {
return jids;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
Aggregations