use of im.actor.core.entity.User in project actor-platform by actorapp.
the class ContactsSyncActor method updateEngineList.
private void updateEngineList() {
if (ENABLE_LOG) {
Log.d(TAG, "Saving contact EngineList");
}
ArrayList<User> userList = new ArrayList<>();
for (int u : contacts) {
userList.add(getUser(u));
}
Collections.sort(userList, (lhs, rhs) -> lhs.getName().compareTo(rhs.getName()));
List<Contact> registeredContacts = new ArrayList<>();
int index = -1;
for (User userModel : userList) {
Contact contact = new Contact(userModel.getUid(), (long) index--, userModel.getAvatar(), userModel.getName());
registeredContacts.add(contact);
}
context().getContactsModule().getContacts().replaceItems(registeredContacts);
Integer[] sorted = new Integer[contacts.size()];
int sindex = 0;
for (User userModel : userList) {
sorted[sindex++] = userModel.getUid();
}
context().getSearchModule().onContactsChanged(sorted);
notifyState();
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class UserRouter method checkIsInPhoneBook.
@Verified
protected Promise<Void> checkIsInPhoneBook(User user) {
if (!config().isEnableOnClientPrivacy()) {
return Promise.success(null);
}
Log.d("ON_CLIENT_PRIVACY", "checking " + user.getName() + " is in phone book");
return getPhoneBook().flatMap(new Function<List<PhoneBookContact>, Promise<Void>>() {
@Override
public Promise<Void> apply(List<PhoneBookContact> phoneBookContacts) {
return new Promise<Void>(resolver -> {
List<ContactRecord> userRecords = user.getRecords();
Log.d("ON_CLIENT_PRIVACY", "phonebook have " + phoneBookContacts.size() + " records");
Log.d("ON_CLIENT_PRIVACY", "user have " + userRecords.size() + " records");
outer: for (ContactRecord record : userRecords) {
for (PhoneBookContact phoneBookContact : phoneBookContacts) {
for (PhoneBookPhone phone1 : phoneBookContact.getPhones()) {
if (record.getRecordType() == ContactRecordType.PHONE) {
if (record.getRecordData().equals(phone1.getNumber() + "")) {
context().getContactsModule().markInPhoneBook(user.getUid());
getUserVM(user.getUid()).isInPhoneBook().change(true);
Log.d("ON_CLIENT_PRIVACY", "in record book!");
break outer;
}
}
}
for (PhoneBookEmail email : phoneBookContact.getEmails()) {
if (record.getRecordType() == ContactRecordType.EMAIL) {
if (record.getRecordData().equals(email.getEmail())) {
context().getContactsModule().markInPhoneBook(user.getUid());
getUserVM(user.getUid()).isInPhoneBook().change(true);
Log.d("ON_CLIENT_PRIVACY", "in record book!");
break outer;
}
}
}
}
}
Log.d("ON_CLIENT_PRIVACY", "finish check");
resolver.result(null);
});
}
});
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class SenderActor method doSendText.
// Sending text
public void doSendText(@NotNull Peer peer, @NotNull String text, @Nullable ArrayList<Integer> mentions, /*Ignored*/
@Nullable String markDownText, boolean autoDetect) {
text = text.trim();
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
if (autoDetect) {
mentions = new ArrayList<>();
if (peer.getPeerType() == PeerType.GROUP) {
Group group = getGroup(peer.getPeerId());
String lowText = text.toLowerCase();
if (group.getMembers() != null) {
for (GroupMember member : group.getMembers()) {
User user = getUser(member.getUid());
if (user.getNick() != null) {
String nick = "@" + user.getNick().toLowerCase();
// TODO: Better filtering
if (lowText.contains(nick + ":") || lowText.contains(nick + " ") || lowText.contains(" " + nick) || lowText.endsWith(nick) || lowText.equals(nick)) {
mentions.add(user.getUid());
}
}
}
}
}
}
TextContent content = TextContent.create(text, null, mentions);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
savePending();
performSendContent(peer, rid, content);
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class RouterActor method notifyActiveDialogsVM.
private void notifyActiveDialogsVM() {
int counter = 0;
ArrayList<DialogGroup> groups = new ArrayList<>();
for (ActiveDialogGroup i : activeDialogStorage.getGroups()) {
ArrayListDialogSmall dialogSmalls = new ArrayListDialogSmall();
for (Peer p : i.getPeers()) {
String title;
Avatar avatar;
if (p.getPeerType() == PeerType.GROUP) {
Group group = getGroup(p.getPeerId());
title = group.getTitle();
avatar = group.getAvatar();
} else if (p.getPeerType() == PeerType.PRIVATE) {
User user = getUser(p.getPeerId());
title = user.getName();
avatar = user.getAvatar();
} else {
continue;
}
int unreadCount = conversationStates.getValue(p.getUnuqueId()).getUnreadCount();
counter += unreadCount;
dialogSmalls.add(new DialogSmall(p, title, avatar, unreadCount));
}
groups.add(new DialogGroup(i.getTitle(), i.getKey(), dialogSmalls));
}
context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().change(groups);
context().getConductor().getGlobalStateVM().onGlobalCounterChanged(counter);
}
use of im.actor.core.entity.User in project actor-platform by actorapp.
the class PresenceActor method subscribe.
@Verified
private void subscribe(Peer peer) {
if (peer.getPeerType() == PeerType.PRIVATE) {
// Already subscribed
if (uids.contains(peer.getPeerId())) {
return;
}
User user = getUser(peer.getPeerId());
if (user == null) {
return;
}
// Subscribing to user online sates
uids.add(user.getUid());
} else if (peer.getPeerType() == PeerType.GROUP) {
// Already subscribed
if (gids.contains(peer.getPeerId())) {
return;
}
Group group = getGroup(peer.getPeerId());
if (group == null) {
return;
}
// Ignore subscription to channels
if (group.getGroupType() == GroupType.CHANNEL) {
return;
}
// Subscribing to group online sates
gids.add(peer.getPeerId());
} else {
return;
}
// Adding Pending Peer
if (pendingPeers.contains(peer)) {
return;
}
pendingPeers.add(peer);
onCheckQueue();
}
Aggregations