use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.
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) {
// disabled for testing strange MUC leaves
sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
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() || onConferenceJoined != null);
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().getTimestamp()));
}
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.isPrivateAndNonAnonymous()) {
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);
updateConversationUi();
} else {
join(conversation);
fetchConferenceConfiguration(conversation);
}
}
});
updateConversationUi();
} else {
account.pendingConferenceJoins.add(conversation);
conversation.resetMucOptions();
conversation.setHasMessagesLeftOnServer(false);
updateConversationUi();
}
}
use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.
the class PresenceGenerator method selfPresence.
public PresencePacket selfPresence(Account account, Presence.Status status, boolean includePgpAnnouncement) {
PresencePacket packet = new PresencePacket();
if (status.toShowString() != null) {
packet.addChild("show").setContent(status.toShowString());
}
packet.setFrom(account.getJid());
String sig = account.getPgpSignature();
if (includePgpAnnouncement && sig != null && mXmppConnectionService.getPgpEngine() != null) {
packet.addChild("x", "jabber:x:signed").setContent(sig);
}
String capHash = getCapHash();
if (capHash != null) {
Element cap = packet.addChild("c", "http://jabber.org/protocol/caps");
cap.setAttribute("hash", "sha-1");
cap.setAttribute("node", "http://jabber.pix-art.de");
cap.setAttribute("ver", capHash);
}
return packet;
}
use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.
the class PresenceGenerator method subscription.
private PresencePacket subscription(String type, Contact contact) {
PresencePacket packet = new PresencePacket();
packet.setAttribute("type", type);
packet.setTo(contact.getJid());
packet.setFrom(contact.getAccount().getJid().toBareJid());
return packet;
}
use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.
the class PresenceGenerator method sendOfflinePresence.
public PresencePacket sendOfflinePresence(Account account) {
PresencePacket packet = new PresencePacket();
packet.setFrom(account.getJid());
packet.setAttribute("type", "unavailable");
return packet;
}
use of de.pixart.messenger.xmpp.stanzas.PresencePacket in project Pix-Art-Messenger by kriztan.
the class XmppConnection method processPresence.
private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
this.presenceListener.onPresencePacketReceived(account, packet);
}
Aggregations