Search in sources :

Example 1 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class NotificationService method pushToStack.

private void pushToStack(final Message message) {
    final String conversationUuid = message.getConversationUuid();
    if (notifications.containsKey(conversationUuid)) {
        notifications.get(conversationUuid).add(message);
    } else {
        final ArrayList<Message> mList = new ArrayList<>();
        mList.add(message);
        notifications.put(conversationUuid, mList);
    }
}
Also used : Message(de.pixart.messenger.entities.Message) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString)

Example 2 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class NotificationService method buildSingleConversations.

private Builder buildSingleConversations(final ArrayList<Message> messages) {
    final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
    if (messages.size() >= 1) {
        final Conversation conversation = messages.get(0).getConversation();
        final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName());
        mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService().get(conversation, getPixel(64)));
        mBuilder.setContentTitle(conversation.getName());
        if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
            int count = messages.size();
            mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
        } else {
            Message message;
            if ((message = getImage(messages)) != null) {
                modifyForImage(mBuilder, mUnreadBuilder, message, messages);
            } else {
                modifyForTextOnly(mBuilder, mUnreadBuilder, messages);
            }
            RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
            PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
            NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(R.drawable.ic_email_open_outline_white_24dp, mXmppConnectionService.getString(R.string.mark_as_read), markAsReadPendingIntent).build();
            String replyLabel = mXmppConnectionService.getString(R.string.reply);
            NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_white_24dp, replyLabel, createReplyIntent(conversation, false)).addRemoteInput(remoteInput).build();
            NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply, replyLabel, createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
            mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
            mUnreadBuilder.setReplyAction(createReplyIntent(conversation, true), remoteInput);
            mUnreadBuilder.setReadPendingIntent(markAsReadPendingIntent);
            mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(mUnreadBuilder.build()));
            int addedActionsCount = 1;
            mBuilder.addAction(markReadAction);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                mBuilder.addAction(replyAction);
                ++addedActionsCount;
            }
            if (displaySnoozeAction(messages)) {
                String label = mXmppConnectionService.getString(R.string.snooze);
                PendingIntent pendingSnoozeIntent = createSnoozeIntent(conversation);
                NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder(R.drawable.ic_notifications_paused_white_24dp, label, pendingSnoozeIntent).build();
                mBuilder.addAction(snoozeAction);
                ++addedActionsCount;
            }
            if (addedActionsCount < 3) {
                final Message firstLocationMessage = getFirstLocationMessage(messages);
                if (firstLocationMessage != null) {
                    String label = mXmppConnectionService.getResources().getString(R.string.show_location);
                    PendingIntent pendingShowLocationIntent = createShowLocationIntent(firstLocationMessage);
                    NotificationCompat.Action locationAction = new NotificationCompat.Action.Builder(R.drawable.ic_room_white_24dp, label, pendingShowLocationIntent).build();
                    mBuilder.addAction(locationAction);
                    ++addedActionsCount;
                }
            }
            if (addedActionsCount < 3) {
                Message firstDownloadableMessage = getFirstDownloadableMessage(messages);
                if (firstDownloadableMessage != null) {
                    String label = mXmppConnectionService.getResources().getString(R.string.download_x_file, UIHelper.getFileDescriptionString(mXmppConnectionService, firstDownloadableMessage));
                    PendingIntent pendingDownloadIntent = createDownloadIntent(firstDownloadableMessage);
                    NotificationCompat.Action downloadAction = new NotificationCompat.Action.Builder(R.drawable.ic_file_download_white_24dp, label, pendingDownloadIntent).build();
                    mBuilder.addAction(downloadAction);
                    ++addedActionsCount;
                }
            }
        }
        if (conversation.getMode() == Conversation.MODE_SINGLE) {
            Contact contact = conversation.getContact();
            Uri systemAccount = contact.getSystemAccount();
            if (systemAccount != null) {
                mBuilder.addPerson(systemAccount.toString());
            }
        }
        mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
        mBuilder.setSmallIcon(R.drawable.ic_notification);
        mBuilder.setDeleteIntent(createDeleteIntent(conversation));
        mBuilder.setContentIntent(createContentIntent(conversation));
    }
    return mBuilder;
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) Message(de.pixart.messenger.entities.Message) UnreadConversation(android.support.v4.app.NotificationCompat.CarExtender.UnreadConversation) Builder(android.support.v4.app.NotificationCompat.Builder) UnreadConversation(android.support.v4.app.NotificationCompat.CarExtender.UnreadConversation) Conversation(de.pixart.messenger.entities.Conversation) SpannableString(android.text.SpannableString) Uri(android.net.Uri) Contact(de.pixart.messenger.entities.Contact) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 3 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class NotificationService method modifyForImage.

private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder, final Message message, final ArrayList<Message> messages) {
    try {
        final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false);
        final ArrayList<Message> tmp = new ArrayList<>();
        for (final Message msg : messages) {
            if (msg.getType() == Message.TYPE_TEXT && msg.getTransferable() == null) {
                tmp.add(msg);
            }
        }
        final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        bigPictureStyle.bigPicture(bitmap);
        if (tmp.size() > 0) {
            CharSequence text = getMergedBodies(tmp);
            bigPictureStyle.setSummaryText(text);
            builder.setContentText(text);
        } else {
            builder.setContentText(mXmppConnectionService.getString(R.string.received_x_file, UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
        }
        builder.setStyle(bigPictureStyle);
    } catch (final FileNotFoundException e) {
        modifyForTextOnly(builder, uBuilder, messages);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Message(de.pixart.messenger.entities.Message) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) BigPictureStyle(android.support.v4.app.NotificationCompat.BigPictureStyle)

Example 4 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method attachImageToConversation.

public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) {
    if (FileBackend.weOwnFile(this, uri)) {
        Log.d(Config.LOGTAG, "trying to attach file that belonged to us");
        callback.error(R.string.security_error_invalid_file_access, null);
        return;
    }
    final String mimeType = MimeUtils.guessMimeTypeFromUri(this, uri);
    final String compressPictures = getCompressPicturesPreference();
    if ("never".equals(compressPictures) || ("auto".equals(compressPictures) && getFileBackend().useImageAsIs(uri)) || (mimeType != null && mimeType.endsWith("/gif"))) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": not compressing picture. sending as file");
        attachFileToConversation(conversation, uri, mimeType, callback);
        return;
    }
    final Message message;
    if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
        message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
    } else {
        message = new Message(conversation, "", conversation.getNextEncryption());
    }
    message.setCounterpart(conversation.getNextCounterpart());
    message.setType(Message.TYPE_IMAGE);
    mFileAddingExecutor.execute(new Runnable() {

        @Override
        public void run() {
            try {
                getFileBackend().copyImageToPrivateStorage(message, uri);
                if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
                    final PgpEngine pgpEngine = getPgpEngine();
                    if (pgpEngine != null) {
                        pgpEngine.encrypt(message, callback);
                    } else if (callback != null) {
                        callback.error(R.string.unable_to_connect_to_keychain, null);
                    }
                } else {
                    sendMessage(message);
                    callback.success(message);
                }
            } catch (final FileBackend.FileCopyException e) {
                callback.error(e.getResId(), message);
            }
        }
    });
}
Also used : XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) PgpEngine(de.pixart.messenger.crypto.PgpEngine)

Example 5 with Message

use of de.pixart.messenger.entities.Message in project Pix-Art-Messenger by kriztan.

the class DatabaseBackend method getMessages.

public ArrayList<Message> getMessages(Conversation conversation, int limit, long timestamp) {
    ArrayList<Message> list = new ArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor;
    if (timestamp == -1) {
        String[] selectionArgs = { conversation.getUuid() };
        cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION + "=?", selectionArgs, null, null, Message.TIME_SENT + " DESC", String.valueOf(limit));
    } else {
        String[] selectionArgs = { conversation.getUuid(), Long.toString(timestamp) };
        cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION + "=? and " + Message.TIME_SENT + "<?", selectionArgs, null, null, Message.TIME_SENT + " DESC", String.valueOf(limit));
    }
    if (cursor.getCount() > 0) {
        cursor.moveToLast();
        do {
            Message message = Message.fromCursor(cursor, conversation);
            if (message != null) {
                list.add(message);
            }
        } while (cursor.moveToPrevious());
    }
    cursor.close();
    return list;
}
Also used : Message(de.pixart.messenger.entities.Message) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Message (de.pixart.messenger.entities.Message)47 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)16 Conversation (de.pixart.messenger.entities.Conversation)13 EditMessage (de.pixart.messenger.ui.widget.EditMessage)12 SuppressLint (android.annotation.SuppressLint)11 PendingIntent (android.app.PendingIntent)7 SpannableString (android.text.SpannableString)7 Account (de.pixart.messenger.entities.Account)7 Jid (de.pixart.messenger.xmpp.jid.Jid)7 ArrayList (java.util.ArrayList)5 Uri (android.net.Uri)4 Toast (android.widget.Toast)4 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 StyleSpan (android.text.style.StyleSpan)3 RelativeLayout (android.widget.RelativeLayout)3 Element (de.pixart.messenger.xml.Element)3 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)3 Date (java.util.Date)3 SharedPreferences (android.content.SharedPreferences)2 PackageManager (android.content.pm.PackageManager)2