use of im.actor.core.viewmodel.UserPresence 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.UserPresence in project actor-platform by actorapp.
the class JsUser method fromUserVM.
public static JsUser fromUserVM(UserVM userVM, JsMessenger messenger) {
UserPresence presence = userVM.getPresence().get();
String presenceString = messenger.getFormatter().formatPresence(presence, userVM.getSex());
boolean isOnline = presence != null && presence.getState() == UserPresence.State.ONLINE;
if (userVM.isBot()) {
isOnline = true;
presenceString = "bot";
}
String fileUrl = null;
String bigFileUrl = null;
Avatar avatar = userVM.getAvatar().get();
if (avatar != null) {
if (avatar.getSmallImage() != null) {
fileUrl = messenger.getFileUrl(avatar.getSmallImage().getFileReference());
}
if (avatar.getLargeImage() != null) {
bigFileUrl = messenger.getFileUrl(avatar.getLargeImage().getFileReference());
}
}
JsArray<JsPhone> convertedPhones = JsArray.createArray().cast();
ArrayListUserPhone phones = userVM.getPhones().get();
for (UserPhone p : phones) {
convertedPhones.push(JsPhone.create(p.getPhone() + "", p.getTitle()));
}
JsArray<JsEmail> convertedEmails = JsArray.createArray().cast();
ArrayListUserEmail emails = userVM.getEmails().get();
for (UserEmail p : emails) {
convertedEmails.push(JsEmail.create(p.getEmail(), p.getTitle()));
}
return create(userVM.getId(), userVM.getName().get(), userVM.getNick().get(), userVM.getAbout().get(), fileUrl, bigFileUrl, Placeholders.getPlaceholder(userVM.getId()), userVM.isContact().get(), userVM.isBot(), presenceString, isOnline, userVM.getIsBlocked().get(), convertedPhones, convertedEmails, userVM.getTimeZone().get(), userVM.getIsVerified().get());
}
use of im.actor.core.viewmodel.UserPresence in project actor-platform by actorapp.
the class JsBindingModule method getUserOnline.
public JsBindedValue<JsOnlineUser> getUserOnline(int uid) {
if (!usersOnlines.containsKey(uid)) {
final JsBindedValue<JsOnlineUser> value = new JsBindedValue<>();
final UserVM userVM = context().getUsersModule().getUsers().get(uid);
userVM.getPresence().subscribe(new ValueChangedListener<UserPresence>() {
@Override
public void onChanged(UserPresence val, Value<UserPresence> valueModel) {
if (val.getState() == UserPresence.State.UNKNOWN) {
value.changeValue(null);
} else {
String presenceString = messenger.getFormatter().formatPresence(val, userVM.getSex());
if (userVM.isBot()) {
presenceString = "bot";
}
value.changeValue(JsOnlineUser.create(presenceString, val.getState() == UserPresence.State.ONLINE));
}
}
});
usersOnlines.put(uid, value);
}
return usersOnlines.get(uid);
}
use of im.actor.core.viewmodel.UserPresence in project actor-platform by actorapp.
the class PresenceActor method onUserLastSeen.
@Verified
private void onUserLastSeen(int uid, int date, long updateDate) {
// Log.d(TAG, "onUserLastSeen #" + uid + " at " + date + " at " + updateDate);
if (lastUidState.containsKey(uid) && lastUidState.get(uid) >= updateDate) {
// Log.d(TAG, "onUserLastSeen:ignored - too old");
return;
}
lastUidState.put(uid, updateDate);
// Log.d(TAG, "onUserLastSeen: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.UserPresence in project actor-platform by actorapp.
the class PresenceActor method onUserOffline.
@Verified
private void onUserOffline(int uid, long updateDate) {
// Log.d(TAG, "onUserOffline #" + uid + " at " + updateDate);
if (lastUidState.containsKey(uid) && lastUidState.get(uid) >= updateDate) {
// Log.d(TAG, "onUserOffline:ignored - too old");
return;
}
lastUidState.put(uid, updateDate);
// Log.d(TAG, "onUserOffline:updated");
UserVM vm = getUserVM(uid);
if (vm != null) {
vm.getPresence().change(new UserPresence(UserPresence.State.OFFLINE));
}
// Cancel timeout
if (uidCancellables.containsKey(uid)) {
uidCancellables.remove(uid).cancel();
}
}
Aggregations