use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.
the class JsFileInput method read.
@Override
public Promise<FilePart> read(int fileOffset, int len) {
return new Promise<>(resolver -> {
JsFileReader fileReader = JsFileReader.create();
fileReader.setOnLoaded(message -> {
Uint8Array array = TypedArrays.createUint8Array(message);
byte[] data = new byte[len];
for (int i = 0; i < len; i++) {
data[i] = (byte) (array.get(i));
}
resolver.result(new FilePart(fileOffset, len, data));
});
fileReader.readAsArrayBuffer(jsFile.slice(fileOffset, fileOffset + len));
});
}
use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.
the class AskcableActor method onReceive.
@Override
public void onReceive(Object message) {
if (message instanceof AskIntRequest) {
AskIntRequest askRequest = (AskIntRequest) message;
try {
Promise p = onAsk(askRequest.getMessage());
if (p == null) {
// Just ignore. We assume that message is stashed
return;
}
p.pipeTo(askRequest.getFuture());
} catch (Exception e) {
e.printStackTrace();
askRequest.getFuture().tryError(e);
}
} else {
super.onReceive(message);
}
}
use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.
the class BaseActivity method execute.
public <T> void execute(Promise<T> promise, int title) {
final ProgressDialog dialog = ProgressDialog.show(this, "", getString(title), true, false);
promise.then(t -> dismissDialog(dialog)).failure(e -> dismissDialog(dialog));
}
use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.
the class GroupUsersFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.done) {
if (isChannel) {
if (getSelectedCount() > 0) {
Promise invites = null;
for (int uid : getSelected()) {
if (invites == null) {
invites = messenger().inviteMemberPromise(gid, uid);
} else {
invites.chain(o -> messenger().inviteMemberPromise(gid, uid));
}
}
execute(invites.then(o -> openChannel()), R.string.progress_common);
} else {
openChannel();
}
} else {
if (getSelectedCount() > 0) {
execute(messenger().createGroup(title, avatarPath, BoxUtil.unbox(getSelected())).then(gid -> {
getActivity().startActivity(Intents.openGroupDialog(gid, true, getActivity()));
getActivity().finish();
}).failure(e -> {
Toast.makeText(getActivity(), getString(R.string.toast_unable_create_group), Toast.LENGTH_LONG).show();
}));
}
}
return true;
}
return super.onOptionsItemSelected(item);
}
use of im.actor.runtime.promise.Promise in project actor-platform by actorapp.
the class MessagesModule method updateMessage.
public Promise<Void> updateMessage(final Peer peer, final String message, final long rid) {
context().getTypingModule().onMessageSent(peer);
ArrayList<Integer> mentions = new ArrayList<>();
TextContent content = TextContent.create(message, null, mentions);
if (peer.getPeerType() == PeerType.GROUP) {
Group group = groups().getValue(peer.getPeerId());
String lowText = message.toLowerCase();
for (GroupMember member : group.getMembers()) {
User user = users().getValue(member.getUid());
if (user.getNick() != null) {
String nick = "@" + user.getNick().toLowerCase();
// TODO: Better filtering
if (lowText.contains(nick + ":") || lowText.contains(nick + " ") || lowText.contains(" " + nick) || lowText.endsWith(nick) || lowText.equals(nick)) {
mentions.add(user.getUid());
}
}
}
}
ApiMessage editMessage = new ApiTextMessage(message, content.getMentions(), content.getTextMessageEx());
return buildOutPeer(peer).flatMap(apiOutPeer -> api(new RequestUpdateMessage(apiOutPeer, rid, editMessage))).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateMessageContentChanged(new ApiPeer(peer.getPeerType().toApi(), peer.getPeerId()), rid, editMessage)));
}
Aggregations