use of im.actor.core.entity.User in project actor-platform by actorapp.
the class SearchActor method onContactsUpdated.
private void onContactsUpdated(int[] contactsList) {
List<SearchEntity> updated = new ArrayList<>();
for (int i = 0; i < contactsList.length; i++) {
User user = users().getValue(contactsList[i]);
updated.add(new SearchEntity(Peer.user(user.getUid()), CONTACTS_PREFIX + i, user.getAvatar(), user.getName()));
}
listEngine.addOrUpdateItems(updated);
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class BlockedAdapter method setBlockedList.
public void setBlockedList(List<User> newBlockedList) {
List<User> blockedSearch = new ArrayList<User>(blockedList);
for (int i = blockedSearch.size() - 1; i >= 0; i--) {
User ou = blockedSearch.get(i);
boolean contains = false;
for (User u : newBlockedList) {
if (u.getUid() == ou.getUid()) {
contains = true;
break;
}
}
if (!contains) {
blockedList.remove(ou);
notifyItemRemoved(i);
}
}
blockedSearch = new ArrayList<User>(blockedList);
for (User u : newBlockedList) {
boolean contains = false;
for (User uo : blockedSearch) {
if (u.getUid() == uo.getUid()) {
contains = true;
break;
}
}
if (!contains) {
blockedList.add(u);
notifyItemInserted(getItemCount());
}
}
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class RouterActor method onPeersChanged.
//
// Peer Changed
//
private Promise<Void> onPeersChanged(List<User> users, List<Group> groups) {
Promise<Void> res = Promise.success(null);
boolean isActiveNeedUpdate = false;
for (User u : users) {
if (!isActiveNeedUpdate) {
for (ActiveDialogGroup g : activeDialogStorage.getGroups()) {
if (g.getPeers().contains(u.peer())) {
isActiveNeedUpdate = true;
break;
}
}
}
res = res.chain(v -> getDialogsRouter().onUserChanged(u));
}
for (Group group : groups) {
if (!isActiveNeedUpdate) {
for (ActiveDialogGroup g : activeDialogStorage.getGroups()) {
if (g.getPeers().contains(group.peer())) {
isActiveNeedUpdate = true;
break;
}
}
}
res = res.chain(v -> getDialogsRouter().onGroupChanged(group));
}
if (isActiveNeedUpdate) {
notifyActiveDialogsVM();
}
return res;
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class MentionsModule method findMentions.
public List<MentionFilterResult> findMentions(int gid, String query) {
query = query.trim().toLowerCase();
ArrayList<MentionFilterResult> results = new ArrayList<MentionFilterResult>();
final Group group = groups().getValue(gid);
GroupMember[] members = group.getMembers().toArray(new GroupMember[group.getMembers().size()]);
Arrays.sort(members, (a, b) -> {
User ua = users().getValue(a.getUid());
User ub = users().getValue(b.getUid());
return ua.getName().compareToIgnoreCase(ub.getName());
});
for (GroupMember member : members) {
if (member.getUid() == myUid()) {
continue;
}
User user = users().getValue(member.getUid());
boolean isNick = user.getNick() != null;
String mention;
String secondName;
if (isNick) {
mention = user.getNick();
secondName = user.getName();
} else {
if (user.getLocalName() != null) {
mention = user.getServerName();
secondName = user.getLocalName();
} else {
mention = user.getName();
secondName = null;
}
}
if (query.length() == 0) {
results.add(new MentionFilterResult(user.getUid(), user.getAvatar(), isNick ? "@" + mention : mention, new ArrayList<>(), secondName, new ArrayList<>(), isNick));
} else {
List<StringMatch> mentionMatches = StringMatcher.findMatches(mention, query);
if (secondName != null) {
List<StringMatch> secondNameMatches = StringMatcher.findMatches(secondName, query);
if (mentionMatches.size() > 0 || secondNameMatches.size() > 0) {
if (isNick) {
List<StringMatch> nickMatches = new ArrayList<>();
for (StringMatch m : mentionMatches) {
nickMatches.add(new StringMatch(m.getStart() + 1, m.getLength()));
}
mentionMatches = nickMatches;
}
results.add(new MentionFilterResult(user.getUid(), user.getAvatar(), isNick ? "@" + mention : mention, mentionMatches, secondName, secondNameMatches, isNick));
}
} else {
if (mentionMatches.size() > 0) {
results.add(new MentionFilterResult(user.getUid(), user.getAvatar(), mention, mentionMatches, null, null, false));
}
}
}
}
if (results.size() > SEARCH_LIMIT) {
results.clear();
}
return results;
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class Authentication method restoreBackup.
public void restoreBackup(AuthenticationBackupData authenticationBackupData) {
//
// Restore UID
//
myUid = authenticationBackupData.getAuthenticatedUid();
modules.getPreferences().putInt(KEY_AUTH_UID, myUid);
modules.getPreferences().putBool(KEY_AUTH, true);
//
try {
modules.getUsersModule().getUsersStorage().addOrUpdateItem(new User(authenticationBackupData.getOwnUserData()));
} catch (IOException e) {
// Should not happen
throw new RuntimeException(e);
}
}
Aggregations