Search in sources :

Example 66 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class OtrService method sendOtrErrorMessage.

public void sendOtrErrorMessage(SessionID session, String errorText) {
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
        if (id != null) {
            MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid, id, errorText);
            packet.setFrom(account.getJid());
            mXmppConnectionService.sendMessagePacket(account, packet);
            Log.d(Config.LOGTAG, packet.toString());
            Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": unreadable OTR message in " + conversation.getName());
        }
    } catch (InvalidJidException e) {
        return;
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation)

Example 67 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class JingleConnection method init.

public void init(Account account, JinglePacket packet) {
    this.mJingleStatus = JINGLE_STATUS_INITIATED;
    Conversation conversation = this.mXmppConnectionService.findOrCreateConversation(account, packet.getFrom().toBareJid(), false);
    this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
    this.message.setStatus(Message.STATUS_RECEIVED);
    this.mStatus = Transferable.STATUS_OFFER;
    this.message.setTransferable(this);
    final Jid from = packet.getFrom();
    this.message.setCounterpart(from);
    this.account = account;
    this.initiator = packet.getFrom();
    this.responder = this.account.getJid();
    this.sessionId = packet.getSessionId();
    Content content = packet.getJingleContent();
    this.contentCreator = content.getAttribute("creator");
    this.contentName = content.getAttribute("name");
    this.transportId = content.getTransportId();
    this.mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
    this.ftVersion = content.getVersion();
    if (ftVersion == null) {
        this.sendCancel();
        this.fail();
        return;
    }
    this.fileOffer = content.getFileOffer(this.ftVersion);
    mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
    if (fileOffer != null) {
        Element encrypted = fileOffer.findChild("encrypted", AxolotlService.PEP_PREFIX);
        if (encrypted != null) {
            this.mXmppAxolotlMessage = XmppAxolotlMessage.fromElement(encrypted, packet.getFrom().toBareJid());
        }
        Element fileSize = fileOffer.findChild("size");
        Element fileNameElement = fileOffer.findChild("name");
        if (fileNameElement != null) {
            String[] filename = fileNameElement.getContent().toLowerCase(Locale.US).toLowerCase().split("\\.");
            String extension = filename[filename.length - 1];
            if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
                message.setType(Message.TYPE_IMAGE);
                message.setRelativeFilePath(message.getUuid() + "." + extension);
            } else if (VALID_CRYPTO_EXTENSIONS.contains(filename[filename.length - 1])) {
                if (filename.length == 3) {
                    extension = filename[filename.length - 2];
                    if (VALID_IMAGE_EXTENSIONS.contains(extension)) {
                        message.setType(Message.TYPE_IMAGE);
                        message.setRelativeFilePath(message.getUuid() + "." + extension);
                    } else {
                        message.setType(Message.TYPE_FILE);
                    }
                    if (filename[filename.length - 1].equals("otr")) {
                        message.setEncryption(Message.ENCRYPTION_OTR);
                    } else {
                        message.setEncryption(Message.ENCRYPTION_PGP);
                    }
                }
            } else {
                message.setType(Message.TYPE_FILE);
            }
            if (message.getType() == Message.TYPE_FILE) {
                String suffix = "";
                if (!fileNameElement.getContent().isEmpty()) {
                    String[] parts = fileNameElement.getContent().split("/");
                    suffix = parts[parts.length - 1];
                    if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
                        suffix = suffix.substring(0, suffix.length() - 4);
                    } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) {
                        suffix = suffix.substring(0, suffix.length() - 4);
                    }
                }
                message.setRelativeFilePath(message.getUuid() + "_" + suffix);
            }
            long size = Long.parseLong(fileSize.getContent());
            message.setBody(Long.toString(size));
            conversation.add(message);
            mJingleConnectionManager.updateConversationUi(true);
            if (mJingleConnectionManager.hasStoragePermission() && size < this.mJingleConnectionManager.getAutoAcceptFileSize() && mXmppConnectionService.isDataSaverDisabled()) {
                Log.d(Config.LOGTAG, "auto accepting file from " + packet.getFrom());
                this.acceptedAutomatically = true;
                this.sendAccept();
            } else {
                message.markUnread();
                Log.d(Config.LOGTAG, "not auto accepting new file offer with size: " + size + " allowed size:" + this.mJingleConnectionManager.getAutoAcceptFileSize());
                this.mXmppConnectionService.getNotificationService().push(message);
            }
            this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
            if (mXmppAxolotlMessage != null) {
                XmppAxolotlMessage.XmppAxolotlKeyTransportMessage transportMessage = account.getAxolotlService().processReceivingKeyTransportMessage(mXmppAxolotlMessage);
                if (transportMessage != null) {
                    message.setEncryption(Message.ENCRYPTION_AXOLOTL);
                    this.file.setKey(transportMessage.getKey());
                    this.file.setIv(transportMessage.getIv());
                    message.setFingerprint(transportMessage.getFingerprint());
                } else {
                    Log.d(Config.LOGTAG, "could not process KeyTransportMessage");
                }
            } else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                byte[] key = conversation.getSymmetricKey();
                if (key == null) {
                    this.sendCancel();
                    this.fail();
                    return;
                } else {
                    this.file.setKeyAndIv(key);
                }
            }
            this.mFileOutputStream = AbstractConnectionManager.createOutputStream(this.file, message.getEncryption() == Message.ENCRYPTION_AXOLOTL);
            if (message.getEncryption() == Message.ENCRYPTION_OTR && Config.REPORT_WRONG_FILESIZE_IN_OTR_JINGLE) {
                this.file.setExpectedSize((size / 16 + 1) * 16);
            } else {
                this.file.setExpectedSize(size);
            }
            Log.d(Config.LOGTAG, "receiving file: expecting size of " + this.file.getExpectedSize());
        } else {
            this.sendCancel();
            this.fail();
        }
    } else {
        this.sendCancel();
        this.fail();
    }
}
Also used : XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)

Example 68 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class JingleConnection method sendInitRequest.

private void sendInitRequest() {
    JinglePacket packet = this.bootstrapPacket("session-initiate");
    Content content = new Content(this.contentCreator, this.contentName);
    if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
        content.setTransportId(this.transportId);
        this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
        Pair<InputStream, Integer> pair;
        try {
            if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                Conversation conversation = this.message.getConversation();
                if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key");
                    cancel();
                }
                this.file.setKeyAndIv(conversation.getSymmetricKey());
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, true, this.ftVersion);
            } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
                this.file.setKey(mXmppAxolotlMessage.getInnerKey());
                this.file.setIv(mXmppAxolotlMessage.getIV());
                pair = AbstractConnectionManager.createInputStream(this.file, true);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement());
            } else {
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion);
            }
        } catch (FileNotFoundException e) {
            cancel();
            return;
        }
        this.mFileInputStream = pair.first;
        content.setTransportId(this.transportId);
        content.socks5transport().setChildren(getCandidatesAsElements());
        packet.setContent(content);
        this.sendJinglePacket(packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": other party received offer");
                    mJingleStatus = JINGLE_STATUS_INITIATED;
                    mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 69 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class ConversationAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.conversation_list_row, parent, false);
    }
    Conversation conversation = getItem(position);
    if (this.activity instanceof ConversationActivity) {
        View swipeableItem = view.findViewById(R.id.swipeable_item);
        ConversationActivity a = (ConversationActivity) this.activity;
        int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
        swipeableItem.setBackgroundColor(c);
    }
    TextView convName = (TextView) view.findViewById(R.id.conversation_name);
    if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
        convName.setText(conversation.getName());
    } else {
        convName.setText(conversation.getJid().toBareJid().toString());
    }
    TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg);
    TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate);
    TextView mSenderName = (TextView) view.findViewById(R.id.sender_name);
    ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage);
    ImageView notificationStatus = (ImageView) view.findViewById(R.id.notification_status);
    UnreadCountCustomView unreadCountCustomView = (UnreadCountCustomView) view.findViewById(R.id.unread_count);
    Message message = conversation.getLatestMessage();
    int unreadCount = conversation.unreadCount();
    if (unreadCount > 0) {
        unreadCountCustomView.setVisibility(View.VISIBLE);
        unreadCountCustomView.setUnreadCount(unreadCount);
    } else {
        unreadCountCustomView.setVisibility(View.GONE);
    }
    if (!conversation.isRead()) {
        convName.setTypeface(null, Typeface.BOLD);
    } else {
        convName.setTypeface(null, Typeface.NORMAL);
    }
    if (message.getFileParams().width > 0 && (message.getTransferable() == null || message.getTransferable().getStatus() != Transferable.STATUS_DELETED)) {
        mSenderName.setVisibility(View.GONE);
        mLastMessage.setVisibility(View.GONE);
        imagePreview.setVisibility(View.VISIBLE);
        activity.loadBitmap(message, imagePreview);
    } else {
        Pair<String, Boolean> preview = UIHelper.getMessagePreview(activity, message);
        mLastMessage.setVisibility(View.VISIBLE);
        imagePreview.setVisibility(View.GONE);
        mLastMessage.setText(preview.first);
        if (preview.second) {
            if (conversation.isRead()) {
                mLastMessage.setTypeface(null, Typeface.ITALIC);
                mSenderName.setTypeface(null, Typeface.NORMAL);
            } else {
                mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
                mSenderName.setTypeface(null, Typeface.BOLD);
            }
        } else {
            if (conversation.isRead()) {
                mLastMessage.setTypeface(null, Typeface.NORMAL);
                mSenderName.setTypeface(null, Typeface.NORMAL);
            } else {
                mLastMessage.setTypeface(null, Typeface.BOLD);
                mSenderName.setTypeface(null, Typeface.BOLD);
            }
        }
        if (message.getStatus() == Message.STATUS_RECEIVED) {
            if (conversation.getMode() == Conversation.MODE_MULTI) {
                mSenderName.setVisibility(View.VISIBLE);
                mSenderName.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
            } else {
                mSenderName.setVisibility(View.GONE);
            }
        } else if (message.getType() != Message.TYPE_STATUS) {
            mSenderName.setVisibility(View.VISIBLE);
            mSenderName.setText(activity.getString(R.string.me) + ':');
        } else {
            mSenderName.setVisibility(View.GONE);
        }
    }
    long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
    if (muted_till == Long.MAX_VALUE) {
        notificationStatus.setVisibility(View.VISIBLE);
        int ic_notifications_off = activity.getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black54_24dp);
        notificationStatus.setImageResource(ic_notifications_off);
    } else if (muted_till >= System.currentTimeMillis()) {
        notificationStatus.setVisibility(View.VISIBLE);
        int ic_notifications_paused = activity.getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black54_24dp);
        notificationStatus.setImageResource(ic_notifications_paused);
    } else if (conversation.alwaysNotify()) {
        notificationStatus.setVisibility(View.GONE);
    } else {
        notificationStatus.setVisibility(View.VISIBLE);
        int ic_notifications_none = activity.getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black54_24dp);
        notificationStatus.setImageResource(ic_notifications_none);
    }
    mTimestamp.setText(UIHelper.readableTimeDifference(activity, conversation.getLatestMessage().getTimeSent()));
    ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image);
    loadAvatar(conversation, profilePicture);
    return view;
}
Also used : ConversationActivity(eu.siacs.conversations.ui.ConversationActivity) UnreadCountCustomView(eu.siacs.conversations.ui.widget.UnreadCountCustomView) Message(eu.siacs.conversations.entities.Message) Conversation(eu.siacs.conversations.entities.Conversation) ImageView(android.widget.ImageView) View(android.view.View) UnreadCountCustomView(eu.siacs.conversations.ui.widget.UnreadCountCustomView) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 70 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class ExceptionHelper method checkForCrash.

public static boolean checkForCrash(ConversationActivity activity, final XmppConnectionService service) {
    try {
        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
        boolean neverSend = preferences.getBoolean("never_send", false);
        if (neverSend || Config.BUG_REPORTS == null) {
            return false;
        }
        List<Account> accounts = service.getAccounts();
        Account account = null;
        for (int i = 0; i < accounts.size(); ++i) {
            if (!accounts.get(i).isOptionSet(Account.OPTION_DISABLED)) {
                account = accounts.get(i);
                break;
            }
        }
        if (account == null) {
            return false;
        }
        final Account finalAccount = account;
        FileInputStream file = activity.openFileInput("stacktrace.txt");
        InputStreamReader inputStreamReader = new InputStreamReader(file);
        BufferedReader stacktrace = new BufferedReader(inputStreamReader);
        final StringBuilder report = new StringBuilder();
        PackageManager pm = activity.getPackageManager();
        PackageInfo packageInfo;
        try {
            packageInfo = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES);
            report.append("Version: " + packageInfo.versionName + '\n');
            report.append("Last Update: " + DATE_FORMATs.format(new Date(packageInfo.lastUpdateTime)) + '\n');
            Signature[] signatures = packageInfo.signatures;
            if (signatures != null && signatures.length >= 1) {
                report.append("SHA-1: " + CryptoHelper.getFingerprintCert(packageInfo.signatures[0].toByteArray()) + "\n");
            }
            report.append('\n');
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        String line;
        while ((line = stacktrace.readLine()) != null) {
            report.append(line);
            report.append('\n');
        }
        file.close();
        activity.deleteFile("stacktrace.txt");
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(activity.getString(R.string.crash_report_title));
        builder.setMessage(activity.getText(R.string.crash_report_message));
        builder.setPositiveButton(activity.getText(R.string.send_now), new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Log.d(Config.LOGTAG, "using account=" + finalAccount.getJid().toBareJid() + " to send in stack trace");
                Conversation conversation = null;
                try {
                    conversation = service.findOrCreateConversation(finalAccount, Jid.fromString(Config.BUG_REPORTS), false);
                } catch (final InvalidJidException ignored) {
                }
                Message message = new Message(conversation, report.toString(), Message.ENCRYPTION_NONE);
                service.sendMessage(message);
            }
        });
        builder.setNegativeButton(activity.getText(R.string.send_never), new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                preferences.edit().putBoolean("never_send", true).apply();
            }
        });
        builder.create().show();
        return true;
    } catch (final IOException ignored) {
        return false;
    }
}
Also used : AlertDialog(android.app.AlertDialog) Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) DialogInterface(android.content.DialogInterface) Conversation(eu.siacs.conversations.entities.Conversation) PackageManager(android.content.pm.PackageManager) InputStreamReader(java.io.InputStreamReader) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Date(java.util.Date) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Signature(android.content.pm.Signature) BufferedReader(java.io.BufferedReader) OnClickListener(android.content.DialogInterface.OnClickListener)

Aggregations

Conversation (eu.siacs.conversations.entities.Conversation)110 Account (eu.siacs.conversations.entities.Account)27 Message (eu.siacs.conversations.entities.Message)24 Jid (eu.siacs.conversations.xmpp.Jid)22 Contact (eu.siacs.conversations.entities.Contact)17 MucOptions (eu.siacs.conversations.entities.MucOptions)10 Intent (android.content.Intent)9 Element (eu.siacs.conversations.xml.Element)9 PendingIntent (android.app.PendingIntent)8 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)8 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Uri (android.net.Uri)7 Conversational (eu.siacs.conversations.entities.Conversational)7 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)7 SuppressLint (android.annotation.SuppressLint)6 SpannableString (android.text.SpannableString)6 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)6 Jid (eu.siacs.conversations.xmpp.jid.Jid)6 ArrayList (java.util.ArrayList)6 Fragment (android.app.Fragment)4