use of im.actor.core.api.updates.UpdateContactsRemoved in project actor-platform by actorapp.
the class UpdateValidator method isCausesInvalidation.
public boolean isCausesInvalidation(Update update) {
HashSet<Integer> users = new HashSet<>();
HashSet<Integer> groups = new HashSet<>();
if (update instanceof UpdateMessage) {
UpdateMessage updateMessage = (UpdateMessage) update;
users.add(updateMessage.getSenderUid());
if (updateMessage.getPeer().getType() == ApiPeerType.GROUP) {
groups.add(updateMessage.getPeer().getId());
}
if (updateMessage.getPeer().getType() == ApiPeerType.PRIVATE) {
users.add(updateMessage.getPeer().getId());
}
} else if (update instanceof UpdateContactRegistered) {
UpdateContactRegistered contactRegistered = (UpdateContactRegistered) update;
users.add(contactRegistered.getUid());
} else if (update instanceof UpdateContactsAdded) {
users.addAll(((UpdateContactsAdded) update).getUids());
} else if (update instanceof UpdateContactsRemoved) {
users.addAll(((UpdateContactsRemoved) update).getUids());
} else if (update instanceof UpdateUserLocalNameChanged) {
UpdateUserLocalNameChanged localNameChanged = (UpdateUserLocalNameChanged) update;
users.add(localNameChanged.getUid());
} else if (update instanceof UpdateChatGroupsChanged) {
UpdateChatGroupsChanged changed = (UpdateChatGroupsChanged) update;
for (ApiDialogGroup group : changed.getDialogs()) {
for (ApiDialogShort dialog : group.getDialogs()) {
if (dialog.getPeer().getType() == ApiPeerType.PRIVATE) {
users.add(dialog.getPeer().getId());
} else if (dialog.getPeer().getType() == ApiPeerType.GROUP) {
groups.add(dialog.getPeer().getId());
}
}
}
} else if (update instanceof UpdateGroupMemberChanged) {
UpdateGroupMemberChanged memberChanged = (UpdateGroupMemberChanged) update;
groups.add(memberChanged.getGroupId());
} else if (update instanceof UpdateGroupMemberDiff) {
UpdateGroupMemberDiff diff = (UpdateGroupMemberDiff) update;
groups.add(diff.getGroupId());
for (Integer u : diff.getRemovedUsers()) {
users.add(u);
}
for (ApiMember m : diff.getAddedMembers()) {
users.add(m.getInviterUid());
users.add(m.getUid());
}
} else if (update instanceof UpdateGroupMembersUpdated) {
UpdateGroupMembersUpdated u = (UpdateGroupMembersUpdated) update;
groups.add(u.getGroupId());
for (ApiMember m : u.getMembers()) {
users.add(m.getInviterUid());
users.add(m.getUid());
}
} else if (update instanceof UpdateGroupMemberAdminChanged) {
UpdateGroupMemberAdminChanged u = (UpdateGroupMemberAdminChanged) update;
users.add(u.getUserId());
groups.add(u.getGroupId());
} else if (update instanceof UpdateGroupMembersCountChanged) {
UpdateGroupMembersCountChanged countChanged = (UpdateGroupMembersCountChanged) update;
groups.add(countChanged.getGroupId());
} else if (update instanceof UpdateGroupOwnerChanged) {
UpdateGroupOwnerChanged ownerChanged = (UpdateGroupOwnerChanged) update;
groups.add(ownerChanged.getGroupId());
users.add(ownerChanged.getUserId());
} else if (update instanceof UpdateGroupFullExtChanged) {
UpdateGroupFullExtChanged fullExtChanged = (UpdateGroupFullExtChanged) update;
groups.add(fullExtChanged.getGroupId());
} else if (update instanceof UpdateGroupExtChanged) {
UpdateGroupExtChanged extChanged = (UpdateGroupExtChanged) update;
groups.add(extChanged.getGroupId());
}
if (!hasUsers(users)) {
return true;
}
if (!hasGroups(groups)) {
return true;
}
return false;
}
use of im.actor.core.api.updates.UpdateContactsRemoved 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.updates.UpdateContactsRemoved in project actor-platform by actorapp.
the class ContactsProcessor method process.
@Override
public Promise<Void> process(Update update) {
if (update instanceof UpdateContactsAdded) {
UpdateContactsAdded contactsAdded = (UpdateContactsAdded) update;
int[] uids = new int[contactsAdded.getUids().size()];
for (int i = 0; i < uids.length; i++) {
uids[i] = contactsAdded.getUids().get(i);
}
context.getContactsModule().getContactSyncActor().send(new ContactsSyncActor.ContactsAdded(uids));
return Promise.success(null);
} else if (update instanceof UpdateContactsRemoved) {
UpdateContactsRemoved contactsRemoved = (UpdateContactsRemoved) update;
int[] uids = new int[contactsRemoved.getUids().size()];
for (int i = 0; i < uids.length; i++) {
uids[i] = contactsRemoved.getUids().get(i);
}
context.getContactsModule().getContactSyncActor().send(new ContactsSyncActor.ContactsRemoved(uids));
return Promise.success(null);
}
return null;
}
Aggregations