Search in sources :

Example 6 with Recipient

use of org.thoughtcrime.securesms.recipients.Recipient in project Signal-Android by WhisperSystems.

the class TextSecureSessionStore method getSessionName.

private String getSessionName(SignalProtocolAddress axolotlAddress) {
    Recipient recipient = RecipientFactory.getRecipientsFromString(context, axolotlAddress.getName(), true).getPrimaryRecipient();
    long recipientId = recipient.getRecipientId();
    int deviceId = axolotlAddress.getDeviceId();
    return recipientId + (deviceId == SignalServiceAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId);
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 7 with Recipient

use of org.thoughtcrime.securesms.recipients.Recipient in project Signal-Android by WhisperSystems.

the class ThreadDatabase method getRecipientIds.

private long[] getRecipientIds(Recipients recipients) {
    Set<Long> recipientSet = new HashSet<>();
    List<Recipient> recipientList = recipients.getRecipientsList();
    for (Recipient recipient : recipientList) {
        recipientSet.add(recipient.getRecipientId());
    }
    long[] recipientArray = new long[recipientSet.size()];
    int i = 0;
    for (Long recipientId : recipientSet) {
        recipientArray[i++] = recipientId;
    }
    Arrays.sort(recipientArray);
    return recipientArray;
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) HashSet(java.util.HashSet)

Example 8 with Recipient

use of org.thoughtcrime.securesms.recipients.Recipient in project Signal-Android by WhisperSystems.

the class MultiDeviceContactUpdateJob method generateSingleContactUpdate.

private void generateSingleContactUpdate(long recipientId) throws IOException, UntrustedIdentityException, NetworkException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    File contactDataFile = createTempFile("multidevice-contact-update");
    try {
        DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
        Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, false);
        out.write(new DeviceContact(Util.canonicalizeNumber(context, recipient.getNumber()), Optional.fromNullable(recipient.getName()), getAvatar(recipient.getContactUri()), Optional.fromNullable(recipient.getColor().serialize())));
        out.close();
        sendUpdate(messageSender, contactDataFile);
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    } finally {
        if (contactDataFile != null)
            contactDataFile.delete();
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileOutputStream(java.io.FileOutputStream) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) Recipient(org.thoughtcrime.securesms.recipients.Recipient) File(java.io.File)

Example 9 with Recipient

use of org.thoughtcrime.securesms.recipients.Recipient in project Signal-Android by WhisperSystems.

the class IdentityUpdateJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws Exception {
    Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, true);
    Recipients recipients = RecipientFactory.getRecipientsFor(context, recipient, true);
    String number = recipient.getNumber();
    long time = System.currentTimeMillis();
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.Reader reader = groupDatabase.getGroups();
    GroupDatabase.GroupRecord groupRecord;
    while ((groupRecord = reader.getNext()) != null) {
        if (groupRecord.getMembers().contains(number) && groupRecord.isActive()) {
            SignalServiceGroup group = new SignalServiceGroup(groupRecord.getId());
            IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.of(group), 0);
            IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
            smsDatabase.insertMessageInbox(groupUpdate);
        }
    }
    if (threadDatabase.getThreadIdIfExistsFor(recipients) != -1) {
        IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.<SignalServiceGroup>absent(), 0);
        IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
        smsDatabase.insertMessageInbox(individualUpdate);
    }
}
Also used : IncomingIdentityUpdateMessage(org.thoughtcrime.securesms.sms.IncomingIdentityUpdateMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup)

Example 10 with Recipient

use of org.thoughtcrime.securesms.recipients.Recipient in project Signal-Android by WhisperSystems.

the class MessageNotifier method constructNotificationState.

private static NotificationState constructNotificationState(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull Cursor cursor) {
    NotificationState notificationState = new NotificationState();
    MessageRecord record;
    MmsSmsDatabase.Reader reader;
    if (masterSecret == null)
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    else
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);
    while ((record = reader.getNext()) != null) {
        long id = record.getId();
        boolean mms = record.isMms() || record.isMmsNotification();
        Recipient recipient = record.getIndividualRecipient();
        Recipients recipients = record.getRecipients();
        long threadId = record.getThreadId();
        CharSequence body = record.getDisplayBody();
        Recipients threadRecipients = null;
        SlideDeck slideDeck = null;
        long timestamp = record.getTimestamp();
        if (threadId != -1) {
            threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
        }
        if (SmsDatabase.Types.isDecryptInProgressType(record.getType()) || !record.getBody().isPlaintext()) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
        } else if (record.isMms() && TextUtils.isEmpty(body)) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        } else if (record.isMms() && !record.isMmsNotification()) {
            String message = context.getString(R.string.MessageNotifier_media_message_with_text, body);
            int italicLength = message.length() - body.length();
            body = SpanUtil.italic(message, italicLength);
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        }
        if (threadRecipients == null || !threadRecipients.isMuted()) {
            notificationState.addNotification(new NotificationItem(id, mms, recipient, recipients, threadRecipients, threadId, body, timestamp, slideDeck));
        }
    }
    reader.close();
    return notificationState;
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)

Aggregations

Recipient (org.thoughtcrime.securesms.recipients.Recipient)26 View (android.view.View)5 Recipients (org.thoughtcrime.securesms.recipients.Recipients)5 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)5 RecipientFormattingException (org.thoughtcrime.securesms.recipients.RecipientFormattingException)3 Intent (android.content.Intent)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 File (java.io.File)2 RecipientsAdapter (org.thoughtcrime.securesms.contacts.RecipientsAdapter)2 IdentityKey (org.whispersystems.libsignal.IdentityKey)2 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)2 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 UiThread (android.support.annotation.UiThread)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1