use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class SenderActor method doSendPhoto.
public void doSendPhoto(Peer peer, FastThumb fastThumb, String descriptor, String fileName, int fileSize, int w, int h) {
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
PhotoContent photoContent = PhotoContent.createLocalPhoto(descriptor, fileName, fileSize, w, h, fastThumb);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, photoContent);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, photoContent));
savePending();
performUploadFile(rid, descriptor, fileName);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class RouterActor method onMessageDeleted.
//
// Message Deletions
//
private Promise<Void> onMessageDeleted(Peer peer, List<Long> rids) {
// Delete Messages
conversation(peer).removeItems(JavaUtil.unbox(rids));
updateChatState(peer);
Message head = conversation(peer).getHeadValue();
if (head != null) {
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
state = state.changeInReadDate(head.getSortDate()).changeOutSendDate(head.getSortDate());
conversationStates.addOrUpdateItem(state);
if (head.getMessageState() == MessageState.PENDING) {
head = null;
}
}
return getDialogsRouter().onMessageDeleted(peer, head);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class RouterActor method onUpdate.
//
// Messages
//
public Promise<Void> onUpdate(Update update) {
if (update instanceof UpdateMessage) {
UpdateMessage msg = (UpdateMessage) update;
Peer peer = convert(msg.getPeer());
AbsContent msgContent = AbsContent.fromMessage(msg.getMessage());
Message message = new Message(msg.getRid(), msg.getDate(), msg.getDate(), msg.getSenderUid(), myUid() == msg.getSenderUid() ? MessageState.SENT : MessageState.UNKNOWN, msgContent);
ArrayList<Message> messages = new ArrayList<>();
messages.add(message);
return onNewMessages(peer, messages);
} else if (update instanceof UpdateMessageSent) {
UpdateMessageSent messageSent = (UpdateMessageSent) update;
Peer peer = convert(messageSent.getPeer());
if (isValidPeer(peer)) {
// Notify Sender
context().getMessagesModule().getSendMessageActor().send(new SenderActor.MessageSent(peer, messageSent.getRid()));
return onOutgoingSent(peer, messageSent.getRid(), messageSent.getDate());
}
return Promise.success(null);
} else if (update instanceof UpdateMessageRead) {
UpdateMessageRead read = (UpdateMessageRead) update;
Peer peer = convert(read.getPeer());
if (isValidPeer(peer)) {
return onMessageRead(peer, read.getStartDate());
}
return Promise.success(null);
} else if (update instanceof UpdateMessageReadByMe) {
UpdateMessageReadByMe readByMe = (UpdateMessageReadByMe) update;
Peer peer = convert(readByMe.getPeer());
if (isValidPeer(peer)) {
int counter = 0;
if (readByMe.getUnreadCounter() != null) {
counter = readByMe.getUnreadCounter();
}
return onMessageReadByMe(peer, readByMe.getStartDate(), counter);
}
return Promise.success(null);
} else if (update instanceof UpdateMessageReceived) {
UpdateMessageReceived received = (UpdateMessageReceived) update;
Peer peer = convert(received.getPeer());
if (isValidPeer(peer)) {
return onMessageReceived(peer, received.getStartDate());
}
return Promise.success(null);
} else if (update instanceof UpdateChatDelete) {
UpdateChatDelete delete = (UpdateChatDelete) update;
Peer peer = convert(delete.getPeer());
if (isValidPeer(peer)) {
return onChatDelete(peer);
}
return Promise.success(null);
} else if (update instanceof UpdateChatClear) {
UpdateChatClear clear = (UpdateChatClear) update;
Peer peer = convert(clear.getPeer());
if (isValidPeer(peer)) {
return onChatClear(peer);
}
return Promise.success(null);
} else if (update instanceof UpdateChatDropCache) {
UpdateChatDropCache dropCache = (UpdateChatDropCache) update;
Peer peer = convert(dropCache.getPeer());
if (isValidPeer(peer)) {
return onChatDropCache(peer);
}
return Promise.success(null);
} else if (update instanceof UpdateChatGroupsChanged) {
UpdateChatGroupsChanged chatGroupsChanged = (UpdateChatGroupsChanged) update;
onActiveDialogsChanged(chatGroupsChanged.getDialogs(), true, true);
return Promise.success(null);
} else if (update instanceof UpdateMessageDelete) {
UpdateMessageDelete delete = (UpdateMessageDelete) update;
Peer peer = convert(delete.getPeer());
if (isValidPeer(peer)) {
return onMessageDeleted(peer, delete.getRids());
}
return Promise.success(null);
} else if (update instanceof UpdateMessageContentChanged) {
UpdateMessageContentChanged contentChanged = (UpdateMessageContentChanged) update;
Peer peer = convert(contentChanged.getPeer());
if (isValidPeer(peer)) {
AbsContent content = AbsContent.fromMessage(contentChanged.getMessage());
return onContentUpdate(peer, contentChanged.getRid(), content);
}
return Promise.success(null);
} else if (update instanceof UpdateReactionsUpdate) {
UpdateReactionsUpdate reactionsUpdate = (UpdateReactionsUpdate) update;
Peer peer = convert(reactionsUpdate.getPeer());
if (isValidPeer(peer)) {
ArrayList<Reaction> reactions = new ArrayList<>();
for (ApiMessageReaction r : reactionsUpdate.getReactions()) {
reactions.add(new Reaction(r.getCode(), r.getUsers()));
}
return onReactionsUpdate(peer, reactionsUpdate.getRid(), reactions);
}
return Promise.success(null);
}
return Promise.success(null);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class I18nEngine method formatMessagesExport.
//
// Exporting messages
//
/**
* Formatting messages for exporting
*
* @param messages messages to export
* @return formatted text
*/
@ObjectiveCName("formatMessagesExport:")
public String formatMessagesExport(Message[] messages) {
String text = "";
Arrays.sort(messages, new Comparator<Message>() {
int compare(long lhs, long rhs) {
return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
}
@Override
public int compare(Message lhs, Message rhs) {
return compare(lhs.getEngineSort(), rhs.getEngineSort());
}
});
if (messages.length == 1) {
for (Message model : messages) {
if (!(model.getContent() instanceof TextContent)) {
continue;
}
text += ((TextContent) model.getContent()).getText();
}
} else {
for (Message model : messages) {
if (!(model.getContent() instanceof TextContent)) {
continue;
}
if (text.length() > 0) {
text += "\n";
}
text += getUser(model.getSenderId()).getName() + ": ";
text += ((TextContent) model.getContent()).getText();
}
}
return text;
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class MessagesAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(AbsMessageViewHolder dialogHolder, int index, Message item) {
Message prev = null;
Message next = null;
if (index > 1) {
next = getItem(index - 1);
}
if (index < getItemCount() - 1) {
prev = getItem(index + 1);
}
PreprocessedList list = ((PreprocessedList) getPreprocessedList());
dialogHolder.bindData(item, prev, next, readDate, receiveDate, list.getPreprocessedData()[index]);
}
Aggregations