use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method sendPresence.
private void sendPresence(final Account account, final boolean includeIdleTimestamp) {
PresencePacket packet;
if (manuallyChangePresence()) {
packet = mPresenceGenerator.selfPresence(account, account.getPresenceStatus());
String message = account.getPresenceStatusMessage();
if (message != null && !message.isEmpty()) {
packet.addChild(new Element("status").setContent(message));
}
} else {
packet = mPresenceGenerator.selfPresence(account, getTargetPresence());
}
if (mLastActivity > 0 && includeIdleTimestamp) {
//don't send future dates
long since = Math.min(mLastActivity, System.currentTimeMillis());
packet.addChild("idle", "urn:xmpp:idle:1").setAttribute("since", AbstractGenerator.getTimestamp(since));
}
sendPresencePacket(account, packet);
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method fetchConferenceConfiguration.
public void fetchConferenceConfiguration(final Conversation conversation, final OnConferenceConfigurationFetched callback) {
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
request.setTo(conversation.getJid().toBareJid());
request.query("http://jabber.org/protocol/disco#info");
sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Element query = packet.findChild("query", "http://jabber.org/protocol/disco#info");
if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
ArrayList<String> features = new ArrayList<>();
for (Element child : query.getChildren()) {
if (child != null && child.getName().equals("feature")) {
String var = child.getAttribute("var");
if (var != null) {
features.add(var);
}
}
}
Element form = query.findChild("x", "jabber:x:data");
if (form != null) {
conversation.getMucOptions().updateFormData(Data.parse(form));
}
conversation.getMucOptions().updateFeatures(features);
if (callback != null) {
callback.onConferenceConfigurationFetched(conversation);
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetched muc configuration for " + conversation.getJid().toBareJid() + " - " + features.toString());
updateConversationUi();
} else if (packet.getType() == IqPacket.TYPE.ERROR) {
if (callback != null) {
callback.onFetchFailed(conversation, packet.getError());
}
}
}
});
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class MessageArchiveService method processFin.
public void processFin(Element fin) {
Query query = findQuery(fin.getAttribute("queryid"));
if (query == null) {
return;
}
boolean complete = fin.getAttributeAsBoolean("complete");
Element set = fin.findChild("set", "http://jabber.org/protocol/rsm");
Element last = set == null ? null : set.findChild("last");
Element first = set == null ? null : set.findChild("first");
Element relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
boolean abort = (!query.isCatchup() && query.getTotalCount() >= Config.PAGE_SIZE) || query.getTotalCount() >= Config.MAM_MAX_MESSAGES;
if (query.getConversation() != null) {
query.getConversation().setFirstMamReference(first == null ? null : first.getContent());
}
if (complete || relevant == null || abort) {
final boolean done = (complete || query.getActualMessageCount() == 0) && !query.isCatchup();
this.finalizeQuery(query, done);
Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done));
if (query.isCatchup() && query.getActualMessageCount() > 0) {
mXmppConnectionService.getNotificationService().finishBacklog(true, query.getAccount());
}
} else {
final Query nextQuery;
if (query.getPagingOrder() == PagingOrder.NORMAL) {
nextQuery = query.next(last == null ? null : last.getContent());
} else {
nextQuery = query.prev(first == null ? null : first.getContent());
}
this.execute(nextQuery);
this.finalizeQuery(query, false);
synchronized (this.queries) {
this.queries.add(nextQuery);
}
}
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method publishAvatar.
public void publishAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) {
final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) {
if (account.setAvatar(avatar.getFilename())) {
getAvatarService().clear(account);
databaseBackend.updateAccount(account);
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
if (callback != null) {
callback.success(avatar);
}
} else {
if (callback != null) {
callback.error(R.string.error_publish_avatar_server_reject, avatar);
}
}
}
});
} else {
Element error = result.findChild("error");
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server rejected avatar " + (avatar.size / 1024) + "KiB " + (error != null ? error.toString() : ""));
if (callback != null) {
callback.error(R.string.error_publish_avatar_server_reject, avatar);
}
}
}
});
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class XmppConnectionService method fetchAvatarPep.
private void fetchAvatarPep(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrievePepAvatar(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
synchronized (mInProgressAvatarFetches) {
mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
}
final String ERROR = account.getJid().toBareJid() + ": fetching avatar for " + avatar.owner + " failed ";
if (result.getType() == IqPacket.TYPE.RESULT) {
avatar.image = mIqParser.avatarData(result);
if (avatar.image != null) {
if (getFileBackend().save(avatar)) {
if (account.getJid().toBareJid().equals(avatar.owner)) {
if (account.setAvatar(avatar.getFilename())) {
databaseBackend.updateAccount(account);
}
getAvatarService().clear(account);
updateConversationUi();
updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(avatar.owner);
contact.setAvatar(avatar);
getAvatarService().clear(contact);
updateConversationUi();
updateRosterUi();
}
if (callback != null) {
callback.success(avatar);
}
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched pep avatar for " + avatar.owner);
return;
}
} else {
Log.d(Config.LOGTAG, ERROR + "(parsing error)");
}
} else {
Element error = result.findChild("error");
if (error == null) {
Log.d(Config.LOGTAG, ERROR + "(server error)");
} else {
Log.d(Config.LOGTAG, ERROR + error.toString());
}
}
if (callback != null) {
callback.error(0, null);
}
}
});
}
Aggregations