Search in sources :

Example 1 with RecipientsPreferences

use of org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences in project Signal-Android by WhisperSystems.

the class RecipientProvider method getIndividualRecipientDetails.

@NonNull
private RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, @NonNull String number) {
    Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[] { recipientId });
    MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null);
    try {
        if (cursor != null && cursor.moveToFirst()) {
            final String resultNumber = cursor.getString(3);
            if (resultNumber != null) {
                Uri contactUri = Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
                String name = resultNumber.equals(cursor.getString(0)) ? null : cursor.getString(0);
                ContactPhoto contactPhoto = ContactPhotoFactory.getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""), name);
                return new RecipientDetails(cursor.getString(0), resultNumber, contactUri, contactPhoto, color);
            } else {
                Log.w(TAG, "resultNumber is null");
            }
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    if (STATIC_DETAILS.containsKey(number))
        return STATIC_DETAILS.get(number);
    else
        return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
}
Also used : MaterialColor(org.thoughtcrime.securesms.color.MaterialColor) RecipientsPreferences(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences) Cursor(android.database.Cursor) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Example 2 with RecipientsPreferences

use of org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences in project Signal-Android by WhisperSystems.

the class QuickResponseService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret) {
    if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
        Log.w(TAG, "Received unknown intent: " + intent.getAction());
        return;
    }
    if (masterSecret == null) {
        Log.w(TAG, "Got quick response request when locked...");
        Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
        return;
    }
    try {
        Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
        String content = intent.getStringExtra(Intent.EXTRA_TEXT);
        String numbers = uri.getPath();
        if (numbers.contains("%")) {
            numbers = URLDecoder.decode(numbers);
        }
        Recipients recipients = RecipientFactory.getRecipientsFromString(this, numbers, false);
        Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(this).getRecipientsPreferences(recipients.getIds());
        int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
        long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
        if (!TextUtils.isEmpty(content)) {
            if (recipients.isSingleRecipient()) {
                MessageSender.send(this, masterSecret, new OutgoingTextMessage(recipients, content, expiresIn, subscriptionId), -1, false);
            } else {
                MessageSender.send(this, masterSecret, new OutgoingMediaMessage(recipients, new SlideDeck(), content, System.currentTimeMillis(), subscriptionId, expiresIn, ThreadDatabase.DistributionTypes.DEFAULT), -1, false);
            }
        }
    } catch (URISyntaxException e) {
        Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
        Log.w(TAG, e);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Rfc5724Uri(org.thoughtcrime.securesms.util.Rfc5724Uri) Recipients(org.thoughtcrime.securesms.recipients.Recipients) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) RecipientsPreferences(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) URISyntaxException(java.net.URISyntaxException)

Aggregations

RecipientsPreferences (org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences)2 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1 URISyntaxException (java.net.URISyntaxException)1 MaterialColor (org.thoughtcrime.securesms.color.MaterialColor)1 ContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ContactPhoto)1 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)1 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)1 Rfc5724Uri (org.thoughtcrime.securesms.util.Rfc5724Uri)1