use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method joinMuc.
private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
Account account = conversation.getAccount();
account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE) {
conversation.resetMucOptions();
if (onConferenceJoined != null) {
conversation.getMucOptions().flagNoAutoPushConfiguration();
}
conversation.setHasMessagesLeftOnServer(false);
fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() {
private void join(Conversation conversation) {
Account account = conversation.getAccount();
final MucOptions mucOptions = conversation.getMucOptions();
final Jid joinJid = mucOptions.getSelf().getFullJid();
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString());
PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous());
packet.setTo(joinJid);
Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
if (conversation.getMucOptions().getPassword() != null) {
x.addChild("password").setContent(mucOptions.getPassword());
}
if (mucOptions.mamSupport()) {
// Use MAM instead of the limited muc history to get history
x.addChild("history").setAttribute("maxchars", "0");
} else {
// Fallback to muc history
x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted()));
}
sendPresencePacket(account, packet);
if (onConferenceJoined != null) {
onConferenceJoined.onConferenceJoined(conversation);
}
if (!joinJid.equals(conversation.getJid())) {
conversation.setContactJid(joinJid);
databaseBackend.updateConversation(conversation);
}
if (mucOptions.mamSupport()) {
getMessageArchiveService().catchupMUC(conversation);
}
if (mucOptions.membersOnly() && mucOptions.nonanonymous()) {
fetchConferenceMembers(conversation);
if (followedInvite && conversation.getBookmark() == null) {
saveConversationAsBookmark(conversation, null);
}
}
sendUnsentMessages(conversation);
}
@Override
public void onConferenceConfigurationFetched(Conversation conversation) {
join(conversation);
}
@Override
public void onFetchFailed(final Conversation conversation, Element error) {
if (error != null && "remote-server-not-found".equals(error.getName())) {
conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND);
} else {
join(conversation);
fetchConferenceConfiguration(conversation);
}
}
});
updateConversationUi();
} else {
account.pendingConferenceJoins.add(conversation);
conversation.resetMucOptions();
conversation.setHasMessagesLeftOnServer(false);
updateConversationUi();
}
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method deleteContactOnServer.
public void deleteContactOnServer(Contact contact) {
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
contact.resetOption(Contact.Options.DIRTY_PUSH);
contact.setOption(Contact.Options.DIRTY_DELETE);
Account account = contact.getAccount();
if (account.getStatus() == Account.State.ONLINE) {
IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
Element item = iq.query(Namespace.ROSTER).addChild("item");
item.setAttribute("jid", contact.getJid().toString());
item.setAttribute("subscription", "remove");
account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
}
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method fetchMamPreferences.
public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.addChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
sendIqPacket(account, request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Element prefs = packet.findChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
callback.onPreferencesFetched(prefs);
} else {
callback.onPreferencesFetchFailed();
}
}
});
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class MessageParser method extractInvite.
private Invite extractInvite(Account account, Element message) {
Element x = message.findChild("x", "http://jabber.org/protocol/muc#user");
if (x != null) {
Element invite = x.findChild("invite");
if (invite != null) {
Element pw = x.findChild("password");
Jid from = invite.getAttributeAsJid("from");
Contact contact = from == null ? null : account.getRoster().getContact(from);
return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent() : null, contact);
}
} else {
x = message.findChild("x", "jabber:x:conference");
if (x != null) {
Jid from = message.getAttributeAsJid("from");
Contact contact = from == null ? null : account.getRoster().getContact(from);
return new Invite(x.getAttributeAsJid("jid"), x.getAttribute("password"), contact);
}
}
return null;
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class MessageParser method parseEvent.
private void parseEvent(final Element event, final Jid from, final Account account) {
Element items = event.findChild("items");
String node = items == null ? null : items.getAttribute("node");
if ("urn:xmpp:avatar:metadata".equals(node)) {
Avatar avatar = Avatar.parseMetadata(items);
if (avatar != null) {
avatar.owner = from.toBareJid();
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
if (account.getJid().toBareJid().equals(from)) {
if (account.setAvatar(avatar.getFilename())) {
mXmppConnectionService.databaseBackend.updateAccount(account);
}
mXmppConnectionService.getAvatarService().clear(account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(from);
contact.setAvatar(avatar);
mXmppConnectionService.getAvatarService().clear(contact);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
}
} else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(account, avatar);
}
}
} else if ("http://jabber.org/protocol/nick".equals(node)) {
Element i = items.findChild("item");
Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick");
if (nick != null && nick.getContent() != null) {
Contact contact = account.getRoster().getContact(from);
contact.setPresenceName(nick.getContent());
mXmppConnectionService.getAvatarService().clear(account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
}
} else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
Element item = items.findChild("item");
Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list (" + deviceIds + ") update from " + from + ", processing...");
AxolotlService axolotlService = account.getAxolotlService();
axolotlService.registerDevices(from, deviceIds);
mXmppConnectionService.updateAccountUi();
}
}
Aggregations