use of im.actor.core.api.ApiGroupOutPeer 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.ApiGroupOutPeer in project actor-platform by actorapp.
the class SearchModule method findPublicGroupById.
public Promise<Peer> findPublicGroupById(int gid) {
ArrayList<ApiGroupOutPeer> groups = new ArrayList<>();
groups.add(new ApiGroupOutPeer(gid, 0));
return updates().loadRequiredPeers(new ArrayList<>(), groups).map(aVoid -> Peer.group(gid));
}
use of im.actor.core.api.ApiGroupOutPeer in project actor-platform by actorapp.
the class GroupsModule method loadMembers.
public Promise<GroupMembersSlice> loadMembers(int gid, int limit, byte[] next) {
return getGroups().getValueAsync(gid).flatMap(group -> api(new RequestLoadMembers(new ApiGroupOutPeer(group.getGroupId(), group.getAccessHash()), limit, next))).chain(r -> updates().loadRequiredPeers(r.getUsers(), new ArrayList<>())).map(r -> {
ArrayList<GroupMember> members = new ArrayList<>();
for (ApiMember p : r.getMembers()) {
boolean isAdmin = p.isAdmin() != null ? p.isAdmin() : false;
members.add(new GroupMember(p.getUid(), p.getInviterUid(), p.getInviterUid(), isAdmin));
}
return new GroupMembersSlice(members, r.getNext());
});
}
use of im.actor.core.api.ApiGroupOutPeer in project actor-platform by actorapp.
the class GroupRouter method onRequestLoadFullGroup.
private void onRequestLoadFullGroup(int gid) {
if (requestedFullGroups.contains(gid)) {
return;
}
requestedFullGroups.add(gid);
freeze();
groups().getValueAsync(gid).flatMap(new Function<Group, Promise<Group>>() {
@Override
public Promise<Group> apply(Group group) {
if (!group.isHaveExtension()) {
ArrayList<ApiGroupOutPeer> groups = new ArrayList<>();
groups.add(new ApiGroupOutPeer(gid, group.getAccessHash()));
return api(new RequestLoadFullGroups(groups)).map(r -> group.updateExt(r.getGroups().get(0)));
} else {
return Promise.failure(new RuntimeException("Already loaded"));
}
}
}).then(r -> groups().addOrUpdateItem(r)).after((r, e) -> unfreeze());
}
use of im.actor.core.api.ApiGroupOutPeer in project actor-platform by actorapp.
the class PresenceActor method onCheckQueue.
private void onCheckQueue() {
if (isRequesting) {
return;
}
if (pendingPeers.size() == 0) {
return;
}
ArrayList<Peer> destPeers = new ArrayList<>(pendingPeers);
pendingPeers.clear();
ArrayList<ApiUserOutPeer> outUserPeers = new ArrayList<>();
ArrayList<ApiGroupOutPeer> outGroupPeers = new ArrayList<>();
for (Peer p : destPeers) {
if (p.getPeerType() == PeerType.GROUP) {
Group g = getGroup(p.getPeerId());
if (g != null) {
outGroupPeers.add(new ApiGroupOutPeer(p.getPeerId(), g.getAccessHash()));
}
} else if (p.getPeerType() == PeerType.PRIVATE) {
User u = getUser(p.getPeerId());
if (u != null) {
outUserPeers.add(new ApiUserOutPeer(p.getPeerId(), u.getAccessHash()));
}
}
}
ArrayList<Promise<ResponseVoid>> requests = new ArrayList<>();
if (outUserPeers.size() > 0) {
requests.add(api(new RequestSubscribeToOnline(outUserPeers)));
}
if (outGroupPeers.size() > 0) {
requests.add(api(new RequestSubscribeToGroupOnline(outGroupPeers)));
}
if (requests.size() > 0) {
isRequesting = true;
PromisesArray.ofPromises(requests).zip().then(responseVoids -> {
isRequesting = false;
onCheckQueue();
}).failure(e -> {
isRequesting = false;
onCheckQueue();
});
}
}
Aggregations