use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.
the class JsFacade method findUsers.
@UsedByApp
public JsPromise findUsers(final String query) {
return JsPromise.create(new JsPromiseExecutor() {
@Override
public void execute() {
messenger.findUsers(query).start(new CommandCallback<UserVM[]>() {
@Override
public void onResult(UserVM[] users) {
Log.d(TAG, "findUsers:result");
JsArray<JsUser> jsUsers = JsArray.createArray().cast();
for (UserVM user : users) {
jsUsers.push(messenger.getJsUser(user.getId()).get());
}
resolve(jsUsers);
}
@Override
public void onError(Exception e) {
Log.d(TAG, "findUsers:error");
reject(e.getMessage());
}
});
}
});
}
use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.
the class GlobalSearchSource method loadGlobalResults.
private void loadGlobalResults(String query, ArrayList<SearchResult> localResults, Consumer<List<SearchResult>> callback) {
context().getSearchModule().findPeers(query).then(r -> {
ArrayList<SearchResult> results = new ArrayList<>();
outer: for (PeerSearchEntity peerSearch : r) {
for (SearchResult l : localResults) {
if (peerSearch.getPeer().equals(l.getPeer())) {
continue outer;
}
}
if (peerSearch.getPeer().getPeerType() == PeerType.GROUP) {
Group group = context().getGroupsModule().getGroups().getValue(peerSearch.getPeer().getPeerId());
results.add(new SearchResult(peerSearch.getPeer(), group.getAvatar(), group.getTitle(), peerSearch.getOptMatchString()));
} else if (peerSearch.getPeer().getPeerType() == PeerType.PRIVATE) {
UserVM user = context().getUsersModule().getUsers().get(peerSearch.getPeer().getPeerId());
results.add(new SearchResult(peerSearch.getPeer(), user.getAvatar().get(), user.getName().get(), peerSearch.getOptMatchString()));
}
}
if (results.size() > 0) {
ArrayList<SearchResult> combined = new ArrayList<>();
combined.addAll(localResults);
combined.addAll(results);
callback.apply(combined);
}
});
}
use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.
the class PresenceActor method onUserGoesOffline.
private void onUserGoesOffline(int uid, int date, long updateDate) {
// Log.d(TAG, "onUserGoesOffline #" + uid + " at " + date + " at " + updateDate);
if (lastUidState.containsKey(uid) && lastUidState.get(uid) >= updateDate) {
// Log.d(TAG, "onUserGoesOffline:ignored - too old");
return;
}
lastUidState.put(uid, updateDate);
// Log.d(TAG, "onUserGoesOffline:updated");
UserVM vm = getUserVM(uid);
if (vm != null) {
vm.getPresence().change(new UserPresence(UserPresence.State.OFFLINE, date));
}
// Cancel timeout
if (uidCancellables.containsKey(uid)) {
uidCancellables.remove(uid).cancel();
}
}
use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.
the class ChatFragment method onResume.
@Override
public void onResume() {
super.onResume();
findInputBar().setText(messenger().loadDraft(peer), true);
if (peer.getPeerType() == PeerType.PRIVATE) {
UserVM userVM = users().get(peer.getPeerId());
if (userVM.isBot()) {
ConversationVM conversationVM = messenger().getConversationVM(peer);
bind(conversationVM.getIsEmpty(), conversationVM.getIsLoaded(), (isEmpty, valueModel, isLoaded, valueModel2) -> {
if (isEmpty) {
inputOverlayText.setText(R.string.chat_empty_bot);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else {
goneView(inputOverlayContainer, false);
showView(inputContainer, false);
}
if (isEmpty && isLoaded) {
showView(emptyContainer, false);
} else {
hideView(emptyContainer, false);
}
});
bind(userVM.getAbout(), (val, valueModel) -> {
if (val == null) {
findEmptyPlaceholder().setText(getString(R.string.chat_empty_bot_about));
} else {
findEmptyPlaceholder().setText(val);
}
});
} else {
bind(userVM.getIsBlocked(), (val, valueModel) -> {
if (val) {
inputOverlayText.setText(R.string.blocked_unblock);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else {
goneView(inputOverlayContainer, false);
showView(inputContainer, false);
}
});
}
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupVM groupVM = groups().get(peer.getPeerId());
bind(groupVM.isMember(), groupVM.getIsCanWriteMessage(), (isMember, valueModel, canWriteMessage, valueModel2) -> {
if (canWriteMessage) {
goneView(inputOverlayContainer, false);
showView(inputContainer, false);
} else if (isMember) {
if (messenger().isNotificationsEnabled(peer)) {
inputOverlayText.setText(getString(R.string.chat_mute));
} else {
inputOverlayText.setText(getString(R.string.chat_unmute));
}
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
inputOverlayText.setEnabled(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else if (groupVM.getIsCanJoin().get()) {
inputOverlayText.setText(getString(R.string.join));
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(true);
inputOverlayText.setEnabled(true);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else if (groupVM.getIsDeleted().get()) {
inputOverlayText.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_deleted : R.string.group_deleted);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(false);
inputOverlayText.setEnabled(false);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
} else {
inputOverlayText.setText(R.string.chat_not_member);
inputOverlayText.setTextColor(style.getListActionColor());
inputOverlayText.setClickable(false);
inputOverlayText.setEnabled(false);
showView(inputOverlayContainer, false);
goneView(inputContainer, false);
}
});
}
}
use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.
the class ChatToolbarFragment method onResume.
@Override
public void onResume() {
super.onResume();
if (peer.getPeerType() == PeerType.PRIVATE) {
// Loading user
UserVM user = users().get(peer.getPeerId());
// Binding User Avatar to Toolbar
bind(barAvatar, user.getId(), user.getAvatar(), user.getName());
// Binding User name to Toolbar
bind(barTitle, user.getName());
bind(user.getIsVerified(), (val, valueModel) -> {
barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, val ? new TintDrawable(getResources().getDrawable(R.drawable.ic_verified_user_black_18dp), ActorSDK.sharedActor().style.getVerifiedColor()) : null, null);
});
// Binding User presence to Toolbar
bind(barSubtitle, user);
// Binding User typing to Toolbar
bindPrivateTyping(barTyping, barTypingContainer, barSubtitle, messenger().getTyping(user.getId()));
// Refresh menu on contact state change
bind(user.isContact(), (val, valueModel) -> {
getActivity().invalidateOptionsMenu();
});
} else if (peer.getPeerType() == PeerType.GROUP) {
// Loading group
GroupVM group = groups().get(peer.getPeerId());
// Binding Group avatar to Toolbar
bind(barAvatar, group.getId(), group.getAvatar(), group.getName());
// Binding Group title to Toolbar
bind(barTitle, group.getName());
if (group.getGroupType() == GroupType.CHANNEL) {
barTitle.setCompoundDrawablesWithIntrinsicBounds(new TintDrawable(getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), Color.WHITE), null, null, null);
} else {
barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
// Subtitle is always visible for Groups
barSubtitleContainer.setVisibility(View.VISIBLE);
// Binding group members
bind(barSubtitle, barSubtitleContainer, group);
// Binding group typing
if (group.getGroupType() == GroupType.GROUP) {
bindGroupTyping(barTyping, barTypingContainer, barSubtitle, messenger().getGroupTyping(group.getId()));
}
}
// Global Counter
bind(messenger().getGlobalState().getGlobalCounter(), (val, valueModel) -> {
if (val != null && val > 0) {
counter.setText(Integer.toString(val));
showView(counter);
} else {
hideView(counter);
}
});
}
Aggregations