Search in sources :

Example 6 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method changeAffiliationsInConference.

public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) {
    List<Jid> jids = new ArrayList<>();
    for (MucOptions.User user : conference.getMucOptions().getUsers()) {
        if (user.getAffiliation() == before && user.getRealJid() != null) {
            jids.add(user.getRealJid());
        }
    }
    IqPacket request = this.mIqGenerator.changeAffiliation(conference, jids, after.toString());
    sendIqPacket(conference.getAccount(), request, mDefaultIqHandler);
}
Also used : MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 7 with Jid

use of de.pixart.messenger.xmpp.jid.Jid 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;
}
Also used : Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark) Jid(de.pixart.messenger.xmpp.jid.Jid) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 8 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method persistSelfNick.

public void persistSelfNick(MucOptions.User self) {
    final Conversation conversation = self.getConversation();
    Jid full = self.getFullJid();
    if (!full.equals(conversation.getJid())) {
        Log.d(Config.LOGTAG, "nick changed. updating");
        conversation.setContactJid(full);
        databaseBackend.updateConversation(conversation);
    }
    Bookmark bookmark = conversation.getBookmark();
    if (bookmark != null && !full.getResourcepart().equals(bookmark.getNick())) {
        bookmark.setNick(full.getResourcepart());
        pushBookmarks(bookmark.getAccount());
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Bookmark(de.pixart.messenger.entities.Bookmark) Conversation(de.pixart.messenger.entities.Conversation)

Example 9 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class BlocklistActivity method filterContacts.

@Override
protected void filterContacts(final String needle) {
    getListItems().clear();
    if (account != null) {
        for (final Jid jid : account.getBlocklist()) {
            final Contact contact = account.getRoster().getContact(jid);
            if (contact.match(this, needle) && contact.isBlocked()) {
                getListItems().add(contact);
            }
        }
        Collections.sort(getListItems());
    }
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Contact(de.pixart.messenger.entities.Contact)

Example 10 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class HttpUploadConnection method init.

public void init(Message message, boolean delay) {
    this.message = message;
    final Account account = message.getConversation().getAccount();
    this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
    if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
        this.mime = "application/pgp-encrypted";
    } else {
        this.mime = this.file.getMimeType();
    }
    this.delayed = delay;
    if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
        // todo: change this to 44 for 12-byte IV instead of 16-byte at some point in future
        this.key = new byte[48];
        mXmppConnectionService.getRNG().nextBytes(this.key);
        this.file.setKeyAndIv(this.key);
    }
    Pair<InputStream, Integer> pair;
    try {
        pair = AbstractConnectionManager.createInputStream(file, true);
    } catch (FileNotFoundException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage());
        fail(e.getMessage());
        return;
    }
    this.file.setExpectedSize(pair.second);
    message.resetFileParams();
    this.mFileInputStream = pair.first;
    Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
    IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
    mXmppConnectionService.sendIqPacket(account, request, (a, packet) -> {
        if (packet.getType() == IqPacket.TYPE.RESULT) {
            Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
            if (slot != null) {
                try {
                    final Element put = slot.findChild("put");
                    final Element get = slot.findChild("get");
                    final String putUrl = put == null ? null : put.getAttribute("url");
                    final String getUrl = get == null ? null : get.getAttribute("url");
                    if (getUrl != null && putUrl != null) {
                        this.mGetUrl = new URL(getUrl);
                        this.mPutUrl = new URL(putUrl);
                        this.mPutHeaders = new HashMap<>();
                        for (Element child : put.getChildren()) {
                            if ("header".equals(child.getName())) {
                                final String name = child.getAttribute("name");
                                final String value = child.getContent();
                                if (WHITE_LISTED_HEADERS.contains(name) && value != null && !value.trim().contains("\n")) {
                                    this.mPutHeaders.put(name, value.trim());
                                }
                            }
                        }
                        if (!canceled) {
                            new Thread(this::upload).start();
                        }
                        return;
                    }
                } catch (MalformedURLException e) {
                // fall through
                }
            }
        }
        Log.d(Config.LOGTAG, account.getJid().toString() + ": invalid response to slot request " + packet);
        fail(IqParser.extractErrorMessage(packet));
    });
    message.setTransferable(this);
    mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
}
Also used : Account(de.pixart.messenger.entities.Account) MalformedURLException(java.net.MalformedURLException) Jid(de.pixart.messenger.xmpp.jid.Jid) InputStream(java.io.InputStream) Element(de.pixart.messenger.xml.Element) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Jid (de.pixart.messenger.xmpp.jid.Jid)75 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)26 Account (de.pixart.messenger.entities.Account)24 Element (de.pixart.messenger.xml.Element)19 Conversation (de.pixart.messenger.entities.Conversation)18 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)15 Contact (de.pixart.messenger.entities.Contact)14 MucOptions (de.pixart.messenger.entities.MucOptions)11 ArrayList (java.util.ArrayList)11 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)8 Message (de.pixart.messenger.entities.Message)7 Intent (android.content.Intent)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)6 Bookmark (de.pixart.messenger.entities.Bookmark)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 AlertDialog (android.support.v7.app.AlertDialog)3 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)3 HashMap (java.util.HashMap)3