use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class BookImportActor method performImportIfRequired.
private void performImportIfRequired() {
if (ENABLE_LOG) {
Log.d(TAG, "performImportIfRequired called");
}
if (isUploadingContacts) {
if (ENABLE_LOG) {
Log.d(TAG, "performImportIfRequired:exiting:already importing");
}
return;
}
if (importQueue.size() == 0) {
if (ENABLE_LOG) {
Log.d(TAG, "performImportIfRequired:exiting:nothing to import");
}
// Marking as everything is imported
context().getConductor().getConductor().onPhoneBookImported();
return;
}
//
// Performing import
//
isUploadingContacts = true;
final ArrayList<ApiPhoneToImport> phoneToImports = new ArrayList<>();
final ArrayList<ApiEmailToImport> emailToImports = new ArrayList<>();
for (int i = 0; i < MAX_IMPORT_SIZE && importQueue.size() > 0; i++) {
ImportQueueItem importQueueItem = importQueue.remove(0);
if (importQueueItem instanceof ImportEmailQueueItem) {
emailToImports.add(new ApiEmailToImport(((ImportEmailQueueItem) importQueueItem).getEmail(), ((ImportEmailQueueItem) importQueueItem).getName()));
} else if (importQueueItem instanceof ImportPhoneQueueItem) {
phoneToImports.add(new ApiPhoneToImport(((ImportPhoneQueueItem) importQueueItem).getPhoneNumber(), ((ImportPhoneQueueItem) importQueueItem).getName()));
} else {
throw new RuntimeException();
}
}
request(new RequestImportContacts(phoneToImports, emailToImports, ApiSupportConfiguration.OPTIMIZATIONS), new RpcCallback<ResponseImportContacts>() {
@Override
public void onResult(ResponseImportContacts response) {
for (ApiPhoneToImport phoneToImport : phoneToImports) {
storage.markAsImported(phoneToImport.getPhoneNumber());
importingPhones.remove(phoneToImport.getPhoneNumber());
}
for (ApiEmailToImport emailToImport : emailToImports) {
storage.markAsImported(emailToImport.getEmail());
importingEmails.remove(emailToImport.getEmail());
}
context().getContactsModule().getBookImportState().put(0, storage.toByteArray());
//
if (response.getUsers().size() != 0 || response.getUserPeers().size() != 0) {
if (ENABLE_LOG) {
Log.d(TAG, "Import success with " + (response.getUsers().size() + response.getUserPeers().size()) + " new contacts");
}
if (response.getUserPeers().size() != 0) {
// Optimized version
ArrayList<Integer> uids = new ArrayList<>();
for (ApiUserOutPeer u : response.getUserPeers()) {
uids.add(u.getUid());
}
updates().loadRequiredPeers(response.getUserPeers(), new ArrayList<>()).flatMap(v -> updates().applyUpdate(response.getSeq(), response.getState(), new UpdateContactsAdded(uids)));
} else {
// Old version
ArrayList<Integer> uids = new ArrayList<>();
for (ApiUser u : response.getUsers()) {
uids.add(u.getId());
}
updates().onUpdateReceived(new FatSeqUpdate(response.getSeq(), response.getState(), UpdateContactsAdded.HEADER, new UpdateContactsAdded(uids).toByteArray(), response.getUsers(), new ArrayList<>()));
}
} else {
if (ENABLE_LOG) {
Log.d(TAG, "Import success, but no new contacts found");
}
}
//
// Launching next iteration
//
isUploadingContacts = false;
performImportIfRequired();
}
@Override
public void onError(RpcException e) {
// TODO: Better error handling
if (ENABLE_LOG) {
Log.d(TAG, "Import failure");
}
e.printStackTrace();
//
// Launching next iteration
//
isUploadingContacts = false;
performImportIfRequired();
}
});
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class PeerConnectionActor method preStart.
@Override
public void preStart() {
isReady = false;
WebRTCIceServer[] rtcIceServers = ManagedList.of(iceServers).map(apiICEServer -> new WebRTCIceServer(apiICEServer.getUrl(), apiICEServer.getUsername(), apiICEServer.getCredential())).toArray(new WebRTCIceServer[0]);
WebRTCSettings settings = new WebRTCSettings(false, false, config().isVideoCallsEnabled());
WebRTC.createPeerConnection(rtcIceServers, settings).then(webRTCPeerConnection -> {
PeerConnectionActor.this.peerConnection = webRTCPeerConnection;
PeerConnectionActor.this.peerConnection.addOwnStream(userMedia);
PeerConnectionActor.this.peerConnection.addCallback(new WebRTCPeerConnectionCallback() {
@Override
public void onCandidate(int label, String id, String candidate) {
if (sessionId != -1) {
callback.onCandidate(sessionId, label, id, candidate);
}
}
@Override
public void onRenegotiationNeeded() {
// if (sessionId != -1) {
// callback.onNegotiationNeeded(sessionId);
// }
}
@Override
public void onStreamAdded(WebRTCMediaStream addedStream) {
// by parent actor
for (WebRTCMediaTrack track : addedStream.getAudioTracks()) {
track.setEnabled(false);
}
for (WebRTCMediaTrack track : addedStream.getVideoTracks()) {
track.setEnabled(false);
}
callback.onStreamAdded(addedStream);
}
@Override
public void onStreamRemoved(WebRTCMediaStream removedStream) {
callback.onStreamRemoved(removedStream);
}
@Override
public void onDisposed() {
}
});
state = PeerConnectionState.WAITING_HANDSHAKE;
onReady();
}).failure(e -> {
Log.d(TAG, "preStart:error");
e.printStackTrace();
onHandshakeFailure();
});
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class PeerConnectionActor method onOffer.
public void onOffer(final long sessionId, @NotNull String sdp) {
// Ignore if we are not waiting for handshake
if (state != PeerConnectionState.WAITING_HANDSHAKE) {
return;
}
// Ignore if we already have session id
if (this.sessionId != -1) {
return;
}
//
// Stages
// 1. Set Remote Description
// 2. Create Answer
// 3. Set Local Description
// 4. Send Answer
// 5. Enter READY mode
//
isReady = false;
peerConnection.setRemoteDescription(new WebRTCSessionDescription("offer", sdp)).flatMap(description -> {
return peerConnection.createAnswer();
}).flatMap(webRTCSessionDescription -> {
return peerConnection.setLocalDescription(SDPOptimizer.optimize(webRTCSessionDescription));
}).then(webRTCSessionDescription -> {
callback.onAnswer(sessionId, webRTCSessionDescription.getSdp());
PeerConnectionActor.this.sessionId = sessionId;
onHandShakeCompleted(sessionId);
onReady();
}).failure(e -> {
e.printStackTrace();
onHandshakeFailure();
});
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class SecuritySettingsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View res = inflater.inflate(R.layout.fr_settings_encryption, container, false);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
res.findViewById(R.id.big_divider).setBackgroundColor(ActorSDK.sharedActor().style.getBackyardBackgroundColor());
((TextView) res.findViewById(R.id.security_settings_title)).setTextColor(ActorSDK.sharedActor().style.getSettingsMainTitleColor());
loading = (TextView) res.findViewById(R.id.loading);
loading.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
loading.setVisibility(View.GONE);
loading.setOnClickListener(v -> performLoad());
authItems = (LinearLayout) res.findViewById(R.id.authItems);
((TextView) res.findViewById(R.id.settings_last_seen_title)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
((TextView) res.findViewById(R.id.settings_last_seen_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
res.findViewById(R.id.lastSeen).setOnClickListener(v -> {
String[] itemsValues = new String[] { "always", "contacts", "none" };
String[] items = new String[] { getString(R.string.security_last_seen_everybody), getString(R.string.security_last_seen_contacts), getString(R.string.security_last_seen_nobody) };
int currentLastSeen = Arrays.asList(itemsValues).indexOf(messenger().getPrivacy());
new AlertDialog.Builder(getActivity()).setTitle(R.string.security_last_seen_title).setSingleChoiceItems(items, currentLastSeen, (dialog, which) -> {
messenger().setPrivacy(itemsValues[which]);
dialog.dismiss();
}).setNegativeButton(R.string.dialog_cancel, null).setPositiveButton(R.string.dialog_ok, null).show();
});
res.findViewById(R.id.terminateSessions).setOnClickListener(v -> new AlertDialog.Builder(getActivity()).setMessage(R.string.security_terminate_message).setPositiveButton(R.string.dialog_yes, (dialog, which) -> execute(messenger().terminateAllSessions(), R.string.progress_common, new CommandCallback<Void>() {
@Override
public void onResult(Void res1) {
performLoad();
}
@Override
public void onError(Exception e) {
performLoad();
Toast.makeText(getActivity(), R.string.security_toast_unable_remove_auth, Toast.LENGTH_SHORT).show();
}
})).setNegativeButton(R.string.dialog_no, null).show().setCanceledOnTouchOutside(true));
((TextView) res.findViewById(R.id.settings_terminate_sessions_title)).setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
((TextView) res.findViewById(R.id.settings_terminate_sessions_hint)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
performLoad();
return res;
}
use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.
the class JsFacade method unfavoriteChat.
@UsedByApp
public JsPromise unfavoriteChat(final JsPeer peer) {
return JsPromise.create(new JsPromiseExecutor() {
@Override
public void execute() {
messenger.unfavoriteChat(peer.convert()).start(new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
Log.d(TAG, "unfavouriteChat:result");
resolve();
}
@Override
public void onError(Exception e) {
Log.d(TAG, "unfavouriteChat:error");
reject(e.getMessage());
}
});
}
});
}
Aggregations