use of im.actor.core.api.rpc.RequestRemoveGroupAvatar 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));
});
}
Aggregations