use of im.actor.core.api.rpc.ResponseSeqDate in project actor-platform by actorapp.
the class GroupAvatarChangeActor method removeAvatar.
public void removeAvatar(final int gid) {
if (currentTasks.containsKey(gid)) {
context().getFilesModule().cancelUpload(currentTasks.get(gid));
currentTasks.remove(gid);
}
final long rid = RandomUtils.nextRid();
currentTasks.put(gid, rid);
tasksMap.put(rid, gid);
Group group = context().getGroupsModule().getGroups().getValue(gid);
ApiGroupOutPeer outPeer = new ApiGroupOutPeer(gid, group.getAccessHash());
context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, true));
api(new RequestRemoveGroupAvatar(outPeer, rid, ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateGroupAvatarChangedObsolete(gid, rid, myUid(), null, responseSeqDate.getDate()))).then(aVoid -> avatarChanged(gid, rid)).failure(e -> {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid2 = tasksMap.get(rid);
if (currentTasks.get(gid) != rid) {
return;
}
currentTasks.remove(gid2);
tasksMap.remove(rid);
context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
});
}
use of im.actor.core.api.rpc.ResponseSeqDate 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)));
}
use of im.actor.core.api.rpc.ResponseSeqDate in project actor-platform by actorapp.
the class SenderActor method performSendApiContent.
private void performSendApiContent(final Peer peer, final long rid, ApiMessage message, final WakeLock wakeLock) {
final ApiOutPeer outPeer = buidOutPeer(peer);
final ApiPeer apiPeer = buildApiPeer(peer);
if (outPeer == null || apiPeer == null) {
return;
}
request(new RequestSendMessage(outPeer, rid, message, null, null), new RpcCallback<ResponseSeqDate>() {
@Override
public void onResult(ResponseSeqDate response) {
self().send(new MessageSent(peer, rid));
updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateMessageSent.HEADER, new UpdateMessageSent(apiPeer, rid, response.getDate()).toByteArray()));
wakeLock.releaseLock();
}
@Override
public void onError(RpcException e) {
self().send(new MessageError(peer, rid));
wakeLock.releaseLock();
}
});
}
Aggregations