Search in sources :

Example 1 with TrustRequest

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());
        }
    }));
}
Also used : TVContactRequestViewModel(cx.ring.tv.model.TVContactRequestViewModel) ResourceSingleObserver(io.reactivex.observers.ResourceSingleObserver) TrustRequest(cx.ring.model.TrustRequest) NonNull(io.reactivex.annotations.NonNull) ArrayList(java.util.ArrayList)

Example 2 with TrustRequest

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();
}
Also used : TrustRequest(cx.ring.model.TrustRequest) VCard(ezvcard.VCard)

Example 3 with TrustRequest

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());
    }
}
Also used : TrustRequest(cx.ring.model.TrustRequest)

Example 4 with TrustRequest

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);
}
Also used : Account(cx.ring.model.Account) TrustRequest(cx.ring.model.TrustRequest) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) StringMap(cx.ring.daemon.StringMap) CallContact(cx.ring.model.CallContact)

Example 5 with TrustRequest

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());
}
Also used : HomeActivity(cx.ring.client.HomeActivity) Bundle(android.os.Bundle) TrustRequest(cx.ring.model.TrustRequest) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) List(java.util.List) ArrayList(java.util.ArrayList) DRingService(cx.ring.service.DRingService) VCard(ezvcard.VCard)

Aggregations

TrustRequest (cx.ring.model.TrustRequest)9 Account (cx.ring.model.Account)4 VCard (ezvcard.VCard)3 ArrayList (java.util.ArrayList)3 CallContact (cx.ring.model.CallContact)2 List (java.util.List)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 HomeActivity (cx.ring.client.HomeActivity)1 StringMap (cx.ring.daemon.StringMap)1 ServiceEvent (cx.ring.model.ServiceEvent)1 DRingService (cx.ring.service.DRingService)1 TVContactRequestViewModel (cx.ring.tv.model.TVContactRequestViewModel)1 NonNull (io.reactivex.annotations.NonNull)1 ResourceSingleObserver (io.reactivex.observers.ResourceSingleObserver)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1