use of cx.ring.model.TrustRequest in project ring-client-android by savoirfairelinux.
the class MainPresenter method loadContactRequest.
public void loadContactRequest() {
mCompositeDisposable.add(Single.fromCallable(() -> {
List<TrustRequest> requests = mAccountService.getCurrentAccount().getRequests();
ArrayList<TVContactRequestViewModel> contactRequestViewModels = new ArrayList<>();
for (TrustRequest request : requests) {
byte[] photo;
if (request.getVCard().getPhotos().isEmpty()) {
photo = null;
} else {
photo = request.getVCard().getPhotos().get(0).getData();
}
TVContactRequestViewModel tvContactRequestVM = new TVContactRequestViewModel(request.getContactId(), request.getDisplayname(), request.getFullname(), photo, request.getMessage());
contactRequestViewModels.add(tvContactRequestVM);
}
return contactRequestViewModels;
}).subscribeOn(Schedulers.computation()).observeOn(mMainScheduler).subscribeWith(new ResourceSingleObserver<ArrayList<TVContactRequestViewModel>>() {
@Override
public void onSuccess(@NonNull ArrayList<TVContactRequestViewModel> contactRequestViewModels) {
mContactRequestViewModels = contactRequestViewModels;
if (mContactRequestViewModels.isEmpty()) {
getView().showContactRequestsRow(false);
} else {
getView().showContactRequestsRow(true);
getView().showContactRequests(mContactRequestViewModels);
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e(TAG, e.toString());
}
}));
}
use of cx.ring.model.TrustRequest in project ring-client-android by savoirfairelinux.
the class ConversationPresenter method onAcceptIncomingContactRequest.
public void onAcceptIncomingContactRequest() {
String currentAccountId = mAccountId == null ? mAccountService.getCurrentAccount().getAccountID() : mAccountId;
mAccountService.acceptTrustRequest(currentAccountId, mContactRingId.getHost());
mPreferencesService.removeRequestPreferences(mAccountId, mContactRingId.getHost());
for (Iterator<TrustRequest> it = mAccountService.getCurrentAccount().getRequests().iterator(); it.hasNext(); ) {
TrustRequest request = it.next();
if (mAccountId.equals(request.getAccountId()) && mAccountId.equals(request.getContactId())) {
VCard vCard = request.getVCard();
if (vCard != null) {
VCardUtils.savePeerProfileToDisk(vCard, mContactRingId.getHost() + ".vcf", mDeviceRuntimeService.provideFilesDir());
}
it.remove();
}
}
getView().switchToConversationView();
}
use of cx.ring.model.TrustRequest in project ring-client-android by savoirfairelinux.
the class ConversationPresenter method resume.
public void resume() {
if (mConversation == null) {
loadHistory();
}
mConversation.setVisible(true);
TrustRequest incomingTrustRequests = getIncomingTrustRequests();
if (incomingTrustRequests == null) {
getView().switchToConversationView();
} else {
getView().switchToIncomingTrustRequestView(incomingTrustRequests.getDisplayname());
}
}
use of cx.ring.model.TrustRequest in project ring-client-android by savoirfairelinux.
the class AccountService method refreshAccountsCacheFromDaemon.
private void refreshAccountsCacheFromDaemon() {
mAccountsLoaded.set(false);
mAccountList = new ArrayList<>();
List<String> accountIds = getAccountList();
for (String accountId : accountIds) {
Map<String, String> details = getAccountDetails(accountId);
List<Map<String, String>> credentials = getCredentials(accountId);
Map<String, String> volatileAccountDetails = getVolatileAccountDetails(accountId);
Account account = new Account(accountId, details, credentials, volatileAccountDetails);
mAccountList.add(account);
if (account.isSip()) {
mHasSipAccount = true;
} else if (account.isRing()) {
mHasRingAccount = true;
account.setDevices(getKnownRingDevices(accountId));
account.setContacts(getContacts(accountId));
List<Map<String, String>> requests = getTrustRequests(accountId);
for (Map<String, String> requestInfo : requests) {
TrustRequest request = new TrustRequest(accountId, requestInfo);
account.addRequest(request);
// If name is in cache this can be synchronous
lookupAddress(accountId, "", request.getContactId());
}
for (CallContact contact : account.getContacts().values()) {
lookupAddress(accountId, "", contact.getPhones().get(0).getNumber().getRawRingId());
}
}
}
mAccountsLoaded.set(true);
}
use of cx.ring.model.TrustRequest in project ring-client-android by savoirfairelinux.
the class NotificationServiceImpl method showIncomingTrustRequestNotification.
@Override
public void showIncomingTrustRequestNotification(Account account) {
int notificationId = getIncomingTrustNotificationId(account.getAccountID());
NotificationCompat.Builder messageNotificationBuilder = mNotificationBuilders.get(notificationId);
if (messageNotificationBuilder != null) {
notificationManager.cancel(notificationId);
} else {
messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_REQUEST);
}
Collection<TrustRequest> requests = account.getRequests();
if (requests.isEmpty()) {
return;
} else if (requests.size() == 1) {
TrustRequest request = requests.iterator().next();
messageNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIF_CHANNEL_REQUEST);
Bundle info = new Bundle();
info.putString(TRUST_REQUEST_NOTIFICATION_ACCOUNT_ID, account.getAccountID());
info.putString(TRUST_REQUEST_NOTIFICATION_FROM, request.getContactId());
messageNotificationBuilder.setContentText(request.getDisplayname()).addAction(R.drawable.ic_action_accept, mContext.getText(R.string.accept), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_TRUST_REQUEST_ACCEPT).setClass(mContext, DRingService.class).putExtras(info), PendingIntent.FLAG_ONE_SHOT)).addAction(R.drawable.ic_delete_white, mContext.getText(R.string.refuse), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_TRUST_REQUEST_REFUSE).setClass(mContext, DRingService.class).putExtras(info), PendingIntent.FLAG_ONE_SHOT)).addAction(R.drawable.ic_close_white, mContext.getText(R.string.block), PendingIntent.getService(mContext, random.nextInt(), new Intent(DRingService.ACTION_TRUST_REQUEST_BLOCK).setClass(mContext, DRingService.class).putExtras(info), PendingIntent.FLAG_ONE_SHOT));
VCard vCard = request.getVCard();
List<Photo> photos = vCard == null ? null : vCard.getPhotos();
byte[] data = null;
if (photos != null && !photos.isEmpty()) {
data = photos.get(0).getData();
}
setContactPicture(data, request.getDisplayname(), request.getContactId(), messageNotificationBuilder);
} else {
messageNotificationBuilder.setContentText(String.format(mContext.getString(R.string.contact_request_msg), Integer.toString(requests.size())));
messageNotificationBuilder.setLargeIcon(null);
messageNotificationBuilder.mActions.clear();
}
messageNotificationBuilder.setDefaults(NotificationCompat.DEFAULT_ALL).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setSmallIcon(R.drawable.ic_ring_logo_white).setCategory(NotificationCompat.CATEGORY_SOCIAL).setContentTitle(mContext.getString(R.string.contact_request_title));
Intent intentOpenTrustRequestFragment = new Intent(HomeActivity.ACTION_PRESENT_TRUST_REQUEST_FRAGMENT).setClass(mContext, HomeActivity.class).putExtra(ContactRequestsFragment.ACCOUNT_ID, account.getAccountID());
messageNotificationBuilder.setContentIntent(PendingIntent.getActivity(mContext, random.nextInt(), intentOpenTrustRequestFragment, PendingIntent.FLAG_ONE_SHOT));
messageNotificationBuilder.setColor(ResourcesCompat.getColor(mContext.getResources(), R.color.color_primary_dark, null));
mNotificationBuilders.put(notificationId, messageNotificationBuilder);
notificationManager.notify(notificationId, messageNotificationBuilder.build());
}
Aggregations