use of im.actor.core.viewmodel.AvatarUploadState 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.viewmodel.AvatarUploadState in project actor-platform by actorapp.
the class GroupAvatarChangeActor method uploadCompleted.
public void uploadCompleted(final long rid, FileReference fileReference) {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid = tasksMap.get(rid);
long accessHash = getGroup(gid).getAccessHash();
if (currentTasks.get(gid) != rid) {
return;
}
api(new RequestEditGroupAvatar(new ApiGroupOutPeer(gid, accessHash), rid, new ApiFileLocation(fileReference.getFileId(), fileReference.getAccessHash()), ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseEditGroupAvatar -> updates().applyUpdate(responseEditGroupAvatar.getSeq(), responseEditGroupAvatar.getState(), new UpdateGroupAvatarChanged(gid, responseEditGroupAvatar.getAvatar()))).then(v -> avatarChanged(gid, rid)).failure(e -> {
if (!tasksMap.containsKey(rid)) {
return;
}
final int gid2 = tasksMap.get(rid);
if (currentTasks.get(gid2) != rid) {
return;
}
currentTasks.remove(gid2);
tasksMap.remove(rid);
context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
});
}
use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.
the class OwnAvatarChangeActor method avatarChanged.
public void avatarChanged(long rid) {
if (rid != currentChangeTask) {
return;
}
currentChangeTask = 0;
context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, false));
}
use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.
the class OwnAvatarChangeActor method changeAvatar.
public void changeAvatar(String descriptor) {
if (currentChangeTask != 0) {
context().getFilesModule().cancelUpload(currentChangeTask);
currentChangeTask = 0;
}
currentChangeTask = RandomUtils.nextRid();
context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(descriptor, true));
context().getFilesModule().requestUpload(currentChangeTask, descriptor, "avatar.jpg", self());
}
Aggregations