Search in sources :

Example 66 with Jid

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

the class ExportLogsService method writeToFile.

private void writeToFile(Conversation conversation) {
    Jid accountJid = resolveAccountUuid(conversation.getAccountUuid());
    Jid contactJid = conversation.getJid();
    File dir = new File(String.format(DIRECTORY_STRING_FORMAT, accountJid.toBareJid().toString()));
    dir.mkdirs();
    BufferedWriter bw = null;
    try {
        for (Message message : mDatabaseBackend.getMessagesIterable(conversation)) {
            if (message == null)
                continue;
            if (message.getType() == Message.TYPE_TEXT || message.hasFileOnRemoteHost()) {
                String date = simpleDateFormat.format(new Date(message.getTimeSent()));
                if (bw == null) {
                    bw = new BufferedWriter(new FileWriter(new File(dir, contactJid.toBareJid().toString() + ".txt")));
                }
                String jid = null;
                switch(message.getStatus()) {
                    case Message.STATUS_RECEIVED:
                        jid = getMessageCounterpart(message);
                        break;
                    case Message.STATUS_SEND:
                    case Message.STATUS_SEND_RECEIVED:
                    case Message.STATUS_SEND_DISPLAYED:
                        jid = accountJid.toBareJid().toString();
                        break;
                }
                if (jid != null) {
                    String body = message.hasFileOnRemoteHost() ? message.getFileParams().url.toString() : message.getBody();
                    bw.write(String.format(MESSAGE_STRING_FORMAT, date, jid, body.replace("\\\n", "\\ \n").replace("\n", "\\ \n")));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (bw != null) {
                bw.close();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Message(de.pixart.messenger.entities.Message) FileWriter(java.io.FileWriter) IOException(java.io.IOException) EncryptDecryptFile(de.pixart.messenger.utils.EncryptDecryptFile) File(java.io.File) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Example 67 with Jid

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

the class XmppConnectionService method sendReadMarker.

public void sendReadMarker(final Conversation conversation) {
    final boolean isPrivateAndNonAnonymousMuc = conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous();
    final Message markable = conversation.getLatestMarkableMessage(isPrivateAndNonAnonymousMuc);
    if (this.markRead(conversation)) {
        updateConversationUi();
    }
    if (confirmMessages() && markable != null && (markable.trusted() || isPrivateAndNonAnonymousMuc) && markable.getRemoteMsgId() != null) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
        Account account = conversation.getAccount();
        final Jid to = markable.getCounterpart();
        final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI;
        MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId(), markable.getCounterpart(), groupChat);
        this.sendMessagePacket(conversation.getAccount(), packet);
    }
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Account(de.pixart.messenger.entities.Account) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) Jid(de.pixart.messenger.xmpp.jid.Jid)

Example 68 with Jid

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

the class XmppConnectionService method renameInMuc.

public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
    final MucOptions options = conversation.getMucOptions();
    final Jid joinJid = options.createJoinJid(nick);
    if (joinJid == null) {
        return false;
    }
    if (options.online()) {
        Account account = conversation.getAccount();
        options.setOnRenameListener(new OnRenameListener() {

            @Override
            public void onSuccess() {
                callback.success(conversation);
            }

            @Override
            public void onFailure() {
                callback.error(R.string.nick_in_use, conversation);
            }
        });
        PresencePacket packet = new PresencePacket();
        packet.setTo(joinJid);
        packet.setFrom(conversation.getAccount().getJid());
        String sig = account.getPgpSignature();
        if (sig != null) {
            packet.addChild("status").setContent("online");
            packet.addChild("x", "jabber:x:signed").setContent(sig);
        }
        sendPresencePacket(account, packet);
    } else {
        conversation.setContactJid(joinJid);
        databaseBackend.updateConversation(conversation);
        if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
            Bookmark bookmark = conversation.getBookmark();
            if (bookmark != null) {
                bookmark.setNick(nick);
                pushBookmarks(bookmark.getAccount());
            }
            joinMuc(conversation);
        }
    }
    return true;
}
Also used : Account(de.pixart.messenger.entities.Account) OnRenameListener(de.pixart.messenger.entities.MucOptions.OnRenameListener) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Bookmark(de.pixart.messenger.entities.Bookmark) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 69 with Jid

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

the class XmppConnectionService method fetchConferenceMembers.

private void fetchConferenceMembers(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final AxolotlService axolotlService = account.getAxolotlService();
    final String[] affiliations = { "member", "admin", "owner" };
    OnIqPacketReceived callback = new OnIqPacketReceived() {

        private int i = 0;

        private boolean success = true;

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element query = packet.query("http://jabber.org/protocol/muc#admin");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                for (Element child : query.getChildren()) {
                    if ("item".equals(child.getName())) {
                        MucOptions.User user = AbstractParser.parseItem(conversation, child);
                        if (!user.realJidMatchesAccount()) {
                            boolean isNew = conversation.getMucOptions().updateUser(user);
                            Contact contact = user.getContact();
                            if (isNew && user.getRealJid() != null && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
                                axolotlService.fetchDeviceIds(user.getRealJid());
                            }
                        }
                    }
                }
            } else {
                success = false;
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().toBareJid());
            }
            ++i;
            if (i >= affiliations.length) {
                List<Jid> members = conversation.getMucOptions().getMembers();
                if (success) {
                    List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
                    boolean changed = false;
                    for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
                        Jid jid = iterator.next();
                        if (!members.contains(jid)) {
                            iterator.remove();
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
                            changed = true;
                        }
                    }
                    if (changed) {
                        conversation.setAcceptedCryptoTargets(cryptoTargets);
                        updateConversation(conversation);
                    }
                }
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved members for " + conversation.getJid().toBareJid() + ": " + conversation.getMucOptions().getMembers());
                getAvatarService().clear(conversation);
                updateMucRosterUi();
                updateConversationUi();
            }
        }
    };
    for (String affiliation : affiliations) {
        sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
    }
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching members for " + conversation.getName());
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Contact(de.pixart.messenger.entities.Contact) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) MucOptions(de.pixart.messenger.entities.MucOptions)

Example 70 with Jid

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

the class XmppConnectionService method createAdhocConference.

public boolean createAdhocConference(final Account account, final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
    if (account.getStatus() == Account.State.ONLINE) {
        try {
            String server = findConferenceServer(account);
            if (server == null) {
                if (callback != null) {
                    callback.error(R.string.no_conference_server_found, null);
                }
                return false;
            }
            final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
            final Conversation conversation = findOrCreateConversation(account, jid, true, false, true);
            joinMuc(conversation, new OnConferenceJoined() {

                @Override
                public void onConferenceJoined(final Conversation conversation) {
                    pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConfigurationPushed() {

                        @Override
                        public void onPushSucceeded() {
                            if (subject != null && !subject.trim().isEmpty()) {
                                pushSubjectToConference(conversation, subject.trim());
                            }
                            for (Jid invite : jids) {
                                invite(conversation, invite);
                            }
                            if (account.countPresences() > 1) {
                                directInvite(conversation, account.getJid().toBareJid());
                            }
                            saveConversationAsBookmark(conversation, subject);
                            if (callback != null) {
                                callback.success(conversation);
                            }
                        }

                        @Override
                        public void onPushFailed() {
                            archiveConversation(conversation);
                            if (callback != null) {
                                callback.error(R.string.conference_creation_failed, conversation);
                            }
                        }
                    });
                }
            });
            return true;
        } catch (InvalidJidException e) {
            if (callback != null) {
                callback.error(R.string.conference_creation_failed, null);
            }
            return true;
        }
    } else {
        if (callback != null) {
            callback.error(R.string.not_connected_try_again, null);
        }
        return true;
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) BigInteger(java.math.BigInteger) Conversation(de.pixart.messenger.entities.Conversation)

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