use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method fetchBookmarks.
public void fetchBookmarks(final Account account) {
final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
final Element query = iqPacket.query("jabber:iq:private");
query.addChild("storage", "storage:bookmarks");
final OnIqPacketReceived callback = new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
final Element query = packet.query();
final HashMap<Jid, Bookmark> bookmarks = new HashMap<>();
final Element storage = query.findChild("storage", "storage:bookmarks");
final boolean autojoin = respectAutojoin();
if (storage != null) {
for (final Element item : storage.getChildren()) {
if (item.getName().equals("conference")) {
final Bookmark bookmark = Bookmark.parse(item, account);
Bookmark old = bookmarks.put(bookmark.getJid(), bookmark);
if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) {
bookmark.setBookmarkName(old.getBookmarkName());
}
Conversation conversation = find(bookmark);
if (conversation != null) {
bookmark.setConversation(conversation);
} else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) {
conversation = findOrCreateConversation(account, bookmark.getJid(), true, true, false);
bookmark.setConversation(conversation);
}
}
}
}
account.setBookmarks(new CopyOnWriteArrayList<>(bookmarks.values()));
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks");
}
}
};
sendIqPacket(account, iqPacket, callback);
}
use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method getKnownConferenceHosts.
public List<String> getKnownConferenceHosts() {
final ArrayList<String> mucServers = new ArrayList<>();
for (final Account account : accounts) {
if (account.getXmppConnection() != null) {
final String server = account.getXmppConnection().getMucServer();
if (server != null && !mucServers.contains(server)) {
mucServers.add(server);
}
for (Bookmark bookmark : account.getBookmarks()) {
final Jid jid = bookmark.getJid();
final String s = jid == null ? null : jid.getDomainpart();
if (s != null && !mucServers.contains(s)) {
mucServers.add(s);
}
}
}
}
return mucServers;
}
use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method saveConversationAsBookmark.
public void saveConversationAsBookmark(Conversation conversation, String name) {
Account account = conversation.getAccount();
Bookmark bookmark = new Bookmark(account, conversation.getJid().toBareJid());
if (!conversation.getJid().isBareJid()) {
bookmark.setNick(conversation.getJid().getResourcepart());
}
if (name != null && !name.trim().isEmpty()) {
bookmark.setBookmarkName(name.trim());
}
bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin)));
account.getBookmarks().add(bookmark);
pushBookmarks(account);
bookmark.setConversation(conversation);
}
use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method pushBookmarks.
public void pushBookmarks(Account account) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": pushing bookmarks");
IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
Element query = iqPacket.query("jabber:iq:private");
Element storage = query.addChild("storage", "storage:bookmarks");
for (Bookmark bookmark : account.getBookmarks()) {
storage.addChild(bookmark);
}
sendIqPacket(account, iqPacket, mDefaultIqHandler);
}
use of de.pixart.messenger.entities.Bookmark in project Pix-Art-Messenger by kriztan.
the class XmppConnectionService method leaveMuc.
private void leaveMuc(Conversation conversation, boolean now) {
Account account = conversation.getAccount();
account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE || now) {
sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions()));
conversation.getMucOptions().setOffline();
Bookmark bookmark = conversation.getBookmark();
if (bookmark != null) {
bookmark.setConversation(null);
}
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": leaving muc " + conversation.getJid());
} else {
account.pendingConferenceLeaves.add(conversation);
}
}
Aggregations