Search in sources :

Example 1 with JsOnlineUser

use of im.actor.core.js.entity.JsOnlineUser 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)

Aggregations

JsOnlineUser (im.actor.core.js.entity.JsOnlineUser)1 UserPresence (im.actor.core.viewmodel.UserPresence)1 UserVM (im.actor.core.viewmodel.UserVM)1