Search in sources :

Example 1 with UserPresence

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();
    }
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) UserPresence(im.actor.core.viewmodel.UserPresence)

Example 2 with UserPresence

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());
}
Also used : ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) UserPhone(im.actor.core.viewmodel.UserPhone) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) UserPresence(im.actor.core.viewmodel.UserPresence) UserEmail(im.actor.core.viewmodel.UserEmail) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) Avatar(im.actor.core.entity.Avatar)

Example 3 with UserPresence

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);
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) JsOnlineUser(im.actor.core.js.entity.JsOnlineUser) UserPresence(im.actor.core.viewmodel.UserPresence)

Example 4 with UserPresence

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();
    }
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) UserPresence(im.actor.core.viewmodel.UserPresence) Verified(im.actor.runtime.annotations.Verified)

Example 5 with UserPresence

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();
    }
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) UserPresence(im.actor.core.viewmodel.UserPresence) Verified(im.actor.runtime.annotations.Verified)

Aggregations

UserPresence (im.actor.core.viewmodel.UserPresence)6 UserVM (im.actor.core.viewmodel.UserVM)5 Verified (im.actor.runtime.annotations.Verified)3 Avatar (im.actor.core.entity.Avatar)1 JsOnlineUser (im.actor.core.js.entity.JsOnlineUser)1 UserEmail (im.actor.core.viewmodel.UserEmail)1 UserPhone (im.actor.core.viewmodel.UserPhone)1 ArrayListUserEmail (im.actor.core.viewmodel.generics.ArrayListUserEmail)1 ArrayListUserPhone (im.actor.core.viewmodel.generics.ArrayListUserPhone)1