use of im.actor.core.api.rpc.ResponseSeq in project actor-platform by actorapp.
the class OwnAvatarChangeActor method removeAvatar.
public void removeAvatar() {
if (currentChangeTask != 0) {
context().getFilesModule().cancelUpload(currentChangeTask);
currentChangeTask = 0;
}
currentChangeTask = RandomUtils.nextRid();
context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, true));
final long currentRid = currentChangeTask;
request(new RequestRemoveAvatar(), new RpcCallback<ResponseSeq>() {
@Override
public void onResult(ResponseSeq response) {
updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateUserAvatarChanged.HEADER, new UpdateUserAvatarChanged(myUid(), null).toByteArray()));
// After update applied turn of uploading state
updates().onUpdateReceived(new ExecuteAfter(response.getSeq(), () -> self().send(new AvatarChanged(currentRid))));
}
@Override
public void onError(RpcException e) {
if (currentRid != currentChangeTask) {
return;
}
currentChangeTask = 0;
context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, false));
}
});
}
use of im.actor.core.api.rpc.ResponseSeq in project actor-platform by actorapp.
the class ContactsModule method removeContact.
public Command<Boolean> removeContact(final int uid) {
return callback -> {
User user = users().getValue(uid);
if (user == null) {
runOnUiThread(() -> callback.onError(new RpcInternalException()));
return;
}
request(new RequestRemoveContact(uid, user.getAccessHash()), new RpcCallback<ResponseSeq>() {
@Override
public void onResult(ResponseSeq response) {
ArrayList<Integer> uids = new ArrayList<>();
uids.add(uid);
SeqUpdate update = new SeqUpdate(response.getSeq(), response.getState(), UpdateContactsRemoved.HEADER, new UpdateContactsRemoved(uids).toByteArray());
updates().onUpdateReceived(update);
runOnUiThread(() -> callback.onResult(true));
}
@Override
public void onError(RpcException e) {
runOnUiThread(() -> callback.onError(new RpcInternalException()));
}
});
};
}
use of im.actor.core.api.rpc.ResponseSeq in project actor-platform by actorapp.
the class ContactsModule method addContact.
public Command<Boolean> addContact(final int uid) {
return callback -> {
User user = users().getValue(uid);
if (user == null) {
runOnUiThread(() -> callback.onError(new RpcInternalException()));
return;
}
request(new RequestAddContact(uid, user.getAccessHash()), new RpcCallback<ResponseSeq>() {
@Override
public void onResult(ResponseSeq response) {
ArrayList<Integer> uids = new ArrayList<>();
uids.add(uid);
SeqUpdate update = new SeqUpdate(response.getSeq(), response.getState(), UpdateContactsAdded.HEADER, new UpdateContactsAdded(uids).toByteArray());
updates().onUpdateReceived(update);
runOnUiThread(() -> callback.onResult(true));
}
@Override
public void onError(RpcException e) {
runOnUiThread(() -> callback.onError(new RpcInternalException()));
}
});
};
}
use of im.actor.core.api.rpc.ResponseSeq in project actor-platform by actorapp.
the class MessageDeleteActor method performDelete.
public void performDelete(final Peer peer, final List<Long> rids) {
final ApiOutPeer outPeer = buidOutPeer(peer);
final ApiPeer apiPeer = buildApiPeer(peer);
request(new RequestDeleteMessage(outPeer, rids), new RpcCallback<ResponseSeq>() {
@Override
public void onResult(ResponseSeq response) {
if (deleteStorage.getPendingDeletions().containsKey(peer)) {
deleteStorage.getPendingDeletions().get(peer).getRids().removeAll(rids);
saveStorage();
}
updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateMessageDelete.HEADER, new UpdateMessageDelete(apiPeer, rids).toByteArray()));
}
@Override
public void onError(RpcException e) {
}
});
}
Aggregations