Search in sources :

Example 1 with PendingMessagesStorage

use of im.actor.core.modules.messaging.actions.entity.PendingMessagesStorage in project actor-platform by actorapp.

the class SenderActor method preStart.

@Override
public void preStart() {
    pendingMessages = new PendingMessagesStorage();
    byte[] p = preferences().getBytes(PREFERENCES);
    if (p != null) {
        try {
            pendingMessages = PendingMessagesStorage.fromBytes(p);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    boolean isChanged = false;
    ArrayList<PendingMessage> messages = pendingMessages.getPendingMessages();
    for (PendingMessage pending : messages.toArray(new PendingMessage[messages.size()])) {
        if (pending.getContent() instanceof TextContent) {
            performSendContent(pending.getPeer(), pending.getRid(), pending.getContent());
        } else if (pending.getContent() instanceof DocumentContent) {
            DocumentContent documentContent = (DocumentContent) pending.getContent();
            if (documentContent.getSource() instanceof FileLocalSource) {
                if (Storage.isFsPersistent()) {
                    performUploadFile(pending.getRid(), ((FileLocalSource) documentContent.getSource()).getFileDescriptor(), ((FileLocalSource) documentContent.getSource()).getFileName());
                } else {
                    List<Long> rids = new ArrayList<>();
                    rids.add(pending.getRid());
                    context().getMessagesModule().getRouter().onMessagesDeleted(pending.getPeer(), rids);
                    pendingMessages.getPendingMessages().remove(pending);
                    isChanged = true;
                }
            } else {
                performSendContent(pending.getPeer(), pending.getRid(), pending.getContent());
            }
        }
    }
    if (isChanged) {
        savePending();
    }
}
Also used : PendingMessagesStorage(im.actor.core.modules.messaging.actions.entity.PendingMessagesStorage) DocumentContent(im.actor.core.entity.content.DocumentContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TextContent(im.actor.core.entity.content.TextContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Aggregations

DocumentContent (im.actor.core.entity.content.DocumentContent)1 FileLocalSource (im.actor.core.entity.content.FileLocalSource)1 TextContent (im.actor.core.entity.content.TextContent)1 PendingMessage (im.actor.core.modules.messaging.actions.entity.PendingMessage)1 PendingMessagesStorage (im.actor.core.modules.messaging.actions.entity.PendingMessagesStorage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1