use of im.actor.core.api.ApiDialogGroup 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.ApiDialogGroup in project actor-platform by actorapp.
the class GetDiffCombiner method buildDiff.
public static CombinedDifference buildDiff(List<Update> updates) {
CombinedDifference res = new CombinedDifference();
UpdateChatGroupsChanged chatGroupsChanged = null;
for (Update u : updates) {
if (u instanceof UpdateMessage) {
res.putMessage((UpdateMessage) u);
} else if (u instanceof UpdateMessageRead) {
UpdateMessageRead read = (UpdateMessageRead) u;
res.putRead(convert(read.getPeer()), read.getStartDate());
} else if (u instanceof UpdateMessageReceived) {
UpdateMessageReceived received = (UpdateMessageReceived) u;
res.putReceived(convert(received.getPeer()), received.getStartDate());
} else if (u instanceof UpdateMessageReadByMe) {
UpdateMessageReadByMe readByMe = (UpdateMessageReadByMe) u;
int counter = 0;
if (readByMe.getUnreadCounter() != null) {
counter = readByMe.getUnreadCounter();
}
res.putReadByMe(convert(readByMe.getPeer()), readByMe.getStartDate(), counter);
} else if (u instanceof UpdateCountersChanged) {
// Ignore
} else if (u instanceof UpdateChatGroupsChanged) {
chatGroupsChanged = (UpdateChatGroupsChanged) u;
} else {
res.getOtherUpdates().add(u);
}
}
// Handling reordering of updates
if (chatGroupsChanged != null) {
ArrayList<ApiDialogGroup> dialogs = new ArrayList<>();
for (ApiDialogGroup dg : chatGroupsChanged.getDialogs()) {
ArrayList<ApiDialogShort> dialogShorts = new ArrayList<>();
for (ApiDialogShort ds : dg.getDialogs()) {
CombinedDifference.ReadByMeValue val = res.getReadByMe().get(convert(ds.getPeer()));
if (val != null) {
dialogShorts.add(new ApiDialogShort(ds.getPeer(), val.getCounter(), ds.getDate()));
} else {
dialogShorts.add(ds);
}
}
dialogs.add(new ApiDialogGroup(dg.getTitle(), dg.getKey(), dialogShorts));
}
res.getOtherUpdates().add(new UpdateChatGroupsChanged(dialogs));
}
return res;
}
use of im.actor.core.api.ApiDialogGroup in project actor-platform by actorapp.
the class RouterActor method onActiveDialogsChanged.
//
// Active Dialogs
//
private void onActiveDialogsChanged(List<ApiDialogGroup> dialogs, boolean showArchived, boolean showInvite) {
//
// Updating Counters
//
ArrayList<ConversationState> convStates = new ArrayList<>();
for (ApiDialogGroup g : dialogs) {
for (ApiDialogShort s : g.getDialogs()) {
Peer peer = convert(s.getPeer());
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
if (state.getUnreadCount() != s.getCounter() && !isConversationVisible(peer)) {
state = state.changeCounter(s.getCounter());
isChanged = true;
}
if (state.getInMaxMessageDate() < s.getDate()) {
state = state.changeInMaxDate(s.getDate());
isChanged = true;
}
if (isChanged) {
convStates.add(state);
}
}
}
conversationStates.addOrUpdateItems(convStates);
//
// Updating storage
//
activeDialogStorage.setHaveArchived(showArchived);
activeDialogStorage.setShowInvite(showInvite);
activeDialogStorage.setLoaded(true);
activeDialogStorage.getGroups().clear();
for (ApiDialogGroup g : dialogs) {
ArrayList<Peer> peers = new ArrayList<>();
for (ApiDialogShort s : g.getDialogs()) {
Peer peer = convert(s.getPeer());
peers.add(peer);
}
activeDialogStorage.getGroups().add(new ActiveDialogGroup(g.getKey(), g.getTitle(), peers));
}
context().getStorageModule().getBlobStorage().addOrUpdateItem(AbsModule.BLOB_DIALOGS_ACTIVE, activeDialogStorage.toByteArray());
//
// Notify VM
//
notifyActiveDialogsVM();
//
// Unstash all messages after initial loading
//
unstashAll();
}
Aggregations