Search in sources :

Example 6 with Message

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

the class ConversationFragment method updateDateBubbles.

protected void updateDateBubbles() {
    synchronized (this.messageList) {
        for (int i = 0; i < this.messageList.size(); ++i) {
            final Message current = this.messageList.get(i);
            if (i == 0 || !UIHelper.sameDay(this.messageList.get(i - 1).getTimeSent(), current.getTimeSent())) {
                this.messageList.add(i, Message.createDateSeparator(current));
                i++;
            }
        }
    }
}
Also used : EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) SuppressLint(android.annotation.SuppressLint)

Example 7 with Message

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

the class ConversationFragment method updateStatusMessages.

protected void updateStatusMessages() {
    updateDateBubbles();
    synchronized (this.messageList) {
        if (showLoadMoreMessages(conversation)) {
            this.messageList.add(0, Message.createLoadMoreMessage(conversation));
        }
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            final MucOptions mucOptions = conversation.getMucOptions();
            final List<MucOptions.User> allUsers = mucOptions.getUsers();
            final Set<ReadByMarker> addedMarkers = new HashSet<>();
            ChatState state = ChatState.COMPOSING;
            List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
            if (users.size() == 0) {
                state = ChatState.PAUSED;
                users = conversation.getMucOptions().getUsersWithChatState(state, 5);
            }
            if (mucOptions.isPrivateAndNonAnonymous()) {
                for (int i = this.messageList.size() - 1; i >= 0; --i) {
                    final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
                    final List<MucOptions.User> shownMarkers = new ArrayList<>();
                    for (ReadByMarker marker : markersForMessage) {
                        if (!ReadByMarker.contains(marker, addedMarkers)) {
                            // may be put outside this condition. set should do dedup anyway
                            addedMarkers.add(marker);
                            MucOptions.User user = mucOptions.findUser(marker);
                            shownMarkers.add(user);
                        }
                    }
                    final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
                    final Message statusMessage;
                    final int size = shownMarkers.size();
                    if (size > 1) {
                        final String body;
                        if (size <= 4) {
                            body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
                        } else {
                            body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
                        }
                        statusMessage = Message.createStatusMessage(conversation, body);
                        statusMessage.setCounterparts(shownMarkers);
                    } else if (size == 1) {
                        statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
                        statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
                        statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
                    } else {
                        statusMessage = null;
                    }
                    if (statusMessage != null) {
                        this.messageList.add(i + 1, statusMessage);
                    }
                    addedMarkers.add(markerForSender);
                    if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) MucOptions(de.pixart.messenger.entities.MucOptions) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) ReadByMarker(de.pixart.messenger.entities.ReadByMarker) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) HashSet(java.util.HashSet)

Example 8 with Message

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

the class XmppConnectionService method markRead.

public boolean markRead(final Conversation conversation, boolean clear) {
    if (clear) {
        mNotificationService.clear(conversation);
    }
    final List<Message> readMessages = conversation.markRead();
    if (readMessages.size() > 0) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                for (Message message : readMessages) {
                    databaseBackend.updateMessage(message);
                }
            }
        };
        mDatabaseWriterExecutor.execute(runnable);
        updateUnreadCountBadge();
        return true;
    } else {
        return false;
    }
}
Also used : XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message)

Example 9 with Message

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

the class XmppConnectionService method attachFileToConversation.

public void attachFileToConversation(final Conversation conversation, final Uri uri, final String type, 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 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_FILE);
    final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this, uri, type, message, callback);
    if (runnable.isVideoMessage()) {
        mVideoCompressionExecutor.execute(runnable);
    } else {
        mFileAddingExecutor.execute(runnable);
    }
}
Also used : XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message)

Example 10 with Message

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

the class XmppConnectionService method resendFailedMessages.

public void resendFailedMessages(final Message message) {
    final Collection<Message> messages = new ArrayList<>();
    Message current = message;
    while (current.getStatus() == Message.STATUS_SEND_FAILED) {
        messages.add(current);
        if (current.mergeable(current.next())) {
            current = current.next();
        } else {
            break;
        }
    }
    for (final Message msg : messages) {
        msg.setTime(System.currentTimeMillis());
        markMessage(msg, Message.STATUS_WAITING);
        this.resendMessage(msg, false);
    }
    message.getConversation().sort();
    updateConversationUi();
}
Also used : XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

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