use of im.actor.core.api.rpc.RequestUpdateMessage in project actor-platform by actorapp.
the class MessagesModule method updateMessage.
public Promise<Void> updateMessage(final Peer peer, final String message, final long rid) {
context().getTypingModule().onMessageSent(peer);
ArrayList<Integer> mentions = new ArrayList<>();
TextContent content = TextContent.create(message, null, mentions);
if (peer.getPeerType() == PeerType.GROUP) {
Group group = groups().getValue(peer.getPeerId());
String lowText = message.toLowerCase();
for (GroupMember member : group.getMembers()) {
User user = users().getValue(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());
}
}
}
}
ApiMessage editMessage = new ApiTextMessage(message, content.getMentions(), content.getTextMessageEx());
return buildOutPeer(peer).flatMap(apiOutPeer -> api(new RequestUpdateMessage(apiOutPeer, rid, editMessage))).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateMessageContentChanged(new ApiPeer(peer.getPeerType().toApi(), peer.getPeerId()), rid, editMessage)));
}
Aggregations