use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class SenderActor method doSendText.
// Sending text
public void doSendText(@NotNull Peer peer, @NotNull String text, @Nullable ArrayList<Integer> mentions, /*Ignored*/
@Nullable String markDownText, boolean autoDetect) {
text = text.trim();
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
if (autoDetect) {
mentions = new ArrayList<>();
if (peer.getPeerType() == PeerType.GROUP) {
Group group = getGroup(peer.getPeerId());
String lowText = text.toLowerCase();
if (group.getMembers() != null) {
for (GroupMember member : group.getMembers()) {
User user = getUser(member.getUid());
if (user.getNick() != null) {
String nick = "@" + user.getNick().toLowerCase();
// TODO: Better filtering
if (lowText.contains(nick + ":") || lowText.contains(nick + " ") || lowText.contains(" " + nick) || lowText.endsWith(nick) || lowText.equals(nick)) {
mentions.add(user.getUid());
}
}
}
}
}
}
TextContent content = TextContent.create(text, null, mentions);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
savePending();
performSendContent(peer, rid, content);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class SenderActor method doSendDocument.
// Sending documents
public void doSendDocument(Peer peer, String fileName, String mimeType, int fileSize, FastThumb fastThumb, String descriptor) {
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
DocumentContent documentContent = DocumentContent.createLocal(fileName, fileSize, descriptor, mimeType, fastThumb);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, documentContent);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, documentContent));
savePending();
performUploadFile(rid, descriptor, fileName);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class RouterActor method onChatHistoryLoaded.
private Promise<Void> onChatHistoryLoaded(Peer peer, List<Message> messages, Long maxReadDate, Long maxReceiveDate, boolean isEnded) {
Log.d(TAG, "History Loaded");
long maxMessageDate = 0;
// Processing all new messages
ArrayList<Message> updated = new ArrayList<>();
for (Message historyMessage : messages) {
// Ignore already present messages
if (conversation(peer).getValue(historyMessage.getEngineId()) != null) {
continue;
}
updated.add(historyMessage);
if (historyMessage.getSenderId() != myUid()) {
maxMessageDate = Math.max(maxMessageDate, historyMessage.getSortDate());
}
}
// Writing messages
conversation(peer).addOrUpdateItems(updated);
// Updating conversation state
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
if (state.getInMaxMessageDate() < maxMessageDate) {
state = state.changeInMaxDate(maxMessageDate);
isChanged = true;
}
if (maxReadDate != null && maxReadDate != 0 && state.getOutReadDate() < maxMessageDate) {
state = state.changeOutReadDate(maxReadDate);
isChanged = true;
}
if (maxReceiveDate != null && maxReceiveDate != 0 && state.getOutReceiveDate() < maxReceiveDate) {
state = state.changeOutReceiveDate(maxReceiveDate);
isChanged = true;
}
if (state.isLoaded() != isEnded) {
state = state.changeIsLoaded(isEnded);
isChanged = true;
}
boolean isEmpty = conversation(peer).isEmpty();
if (state.isEmpty() != isEmpty) {
state = state.changeIsEmpty(isEmpty);
isChanged = true;
}
if (isChanged) {
conversationStates.addOrUpdateItem(state);
}
// Reading messages if needed
markAsReadIfNeeded(peer);
return Promise.success(null);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class SenderActor method doSendJson.
public void doSendJson(Peer peer, JsonContent content) {
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
savePending();
performSendContent(peer, rid, content);
}
use of im.actor.core.entity.Message in project actor-platform by actorapp.
the class SenderActor method doSendAudio.
public void doSendAudio(Peer peer, String descriptor, String fileName, int fileSize, int duration) {
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
VoiceContent audioContent = VoiceContent.createLocalAudio(descriptor, fileName, fileSize, duration);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, audioContent);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, audioContent));
savePending();
performUploadFile(rid, descriptor, fileName);
}
Aggregations