use of im.actor.core.js.entity.JsTyping in project actor-platform by actorapp.
the class JsBindingModule method getTyping.
public JsBindedValue<JsTyping> getTyping(final Peer peer) {
if (!typing.containsKey(peer)) {
if (peer.getPeerType() == PeerType.PRIVATE) {
UserTypingVM userTypingVM = context().getTypingModule().getTyping(peer.getPeerId());
final JsBindedValue<JsTyping> value = new JsBindedValue<>();
userTypingVM.getTyping().subscribe((val, valueModel) -> {
String typingValue = null;
if (val) {
typingValue = messenger.getFormatter().formatTyping("");
}
value.changeValue(JsTyping.create(typingValue));
});
typing.put(peer, value);
} else if (peer.getPeerType() == PeerType.GROUP) {
GroupTypingVM groupTypingVM = context().getTypingModule().getGroupTyping(peer.getPeerId());
final JsBindedValue<JsTyping> value = new JsBindedValue<>();
groupTypingVM.getActive().subscribe((val, valueModel) -> {
if (val.length > 0) {
ArrayList<String> names = new ArrayList<>();
for (int i : val) {
names.add(context().getUsersModule().getUsers().get(i).getName().get());
}
value.changeValue(JsTyping.create(messenger.getFormatter().formatTyping(names)));
} else {
value.changeValue(JsTyping.create(null));
}
});
typing.put(peer, value);
} else {
throw new RuntimeException();
}
}
return typing.get(peer);
}
Aggregations