Search in sources :

Example 6 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class MediaOverviewActivity method initializeResources.

private void initializeResources() {
    Address address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
    this.viewPager = ViewUtil.findById(this, R.id.pager);
    this.toolbar = ViewUtil.findById(this, R.id.toolbar);
    this.tabLayout = ViewUtil.findById(this, R.id.tab_layout);
    this.recipient = Recipient.from(this, address, true);
}
Also used : Address(org.thoughtcrime.securesms.database.Address)

Example 7 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class AndroidAutoReplyReceiver method onReceive.

@SuppressLint("StaticFieldLeak")
@Override
public void onReceive(final Context context, Intent intent) {
    if (!REPLY_ACTION.equals(intent.getAction()))
        return;
    Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
    if (remoteInput == null)
        return;
    final Address address = intent.getParcelableExtra(ADDRESS_EXTRA);
    final long threadId = intent.getLongExtra(THREAD_ID_EXTRA, -1);
    final CharSequence responseText = getMessageText(intent);
    final Recipient recipient = Recipient.from(context, address, false);
    if (responseText != null) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                long replyThreadId;
                int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
                long expiresIn = recipient.getExpireMessages() * 1000L;
                if (recipient.isGroupRecipient()) {
                    Log.w("AndroidAutoReplyReceiver", "GroupRecipient, Sending media message");
                    OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient, responseText.toString(), new LinkedList<>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
                    replyThreadId = MessageSender.send(context, reply, threadId, false, null);
                } else {
                    Log.w("AndroidAutoReplyReceiver", "Sending regular message ");
                    OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
                    replyThreadId = MessageSender.send(context, reply, threadId, false, null);
                }
                List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId, true);
                MessageNotifier.updateNotification(context);
                MarkReadReceiver.process(context, messageIds);
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Address(org.thoughtcrime.securesms.database.Address) Bundle(android.os.Bundle) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) SuppressLint(android.annotation.SuppressLint)

Example 8 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class ProfilePreference method refresh.

public void refresh() {
    if (profileNumberView == null)
        return;
    final Address localAddress = Address.fromSerialized(TextSecurePreferences.getLocalNumber(getContext()));
    final String profileName = TextSecurePreferences.getProfileName(getContext());
    GlideApp.with(getContext().getApplicationContext()).load(new ProfileContactPhoto(localAddress, String.valueOf(TextSecurePreferences.getProfileAvatarId(getContext())))).error(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(getContext(), getContext().getResources().getColor(R.color.grey_400))).circleCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(avatarView);
    if (!TextUtils.isEmpty(profileName)) {
        profileNameView.setText(profileName);
    }
    profileNumberView.setText(localAddress.toPhoneString());
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) Address(org.thoughtcrime.securesms.database.Address)

Example 9 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class PushGroupSendJob method deliver.

private void deliver(OutgoingMediaMessage message, @Nullable Address filterAddress) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions, UndeliverableMessageException {
    String groupId = message.getRecipient().getAddress().toGroupString();
    Optional<byte[]> profileKey = getProfileKey(message.getRecipient());
    List<Address> recipients = getGroupMessageRecipients(groupId, messageId);
    MediaConstraints mediaConstraints = MediaConstraints.getPushMediaConstraints();
    List<Attachment> scaledAttachments = scaleAttachments(mediaConstraints, message.getAttachments());
    List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(scaledAttachments);
    List<SignalServiceAddress> addresses;
    if (filterAddress != null)
        addresses = getPushAddresses(filterAddress);
    else
        addresses = getPushAddresses(recipients);
    if (message.isGroup()) {
        OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
        GroupContext groupContext = groupMessage.getGroupContext();
        SignalServiceAttachment avatar = attachmentStreams.isEmpty() ? null : attachmentStreams.get(0);
        SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE;
        SignalServiceGroup group = new SignalServiceGroup(type, GroupUtil.getDecodedId(groupId), groupContext.getName(), groupContext.getMembersList(), avatar);
        SignalServiceDataMessage groupDataMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getSentTimeMillis()).asGroupMessage(group).build();
        messageSender.sendMessage(addresses, groupDataMessage);
    } else {
        SignalServiceGroup group = new SignalServiceGroup(GroupUtil.getDecodedId(groupId));
        SignalServiceDataMessage groupMessage = SignalServiceDataMessage.newBuilder().withTimestamp(message.getSentTimeMillis()).asGroupMessage(group).withAttachments(attachmentStreams).withBody(message.getBody()).withExpiration((int) (message.getExpiresIn() / 1000)).asExpirationUpdate(message.isExpirationUpdate()).withProfileKey(profileKey.orNull()).build();
        messageSender.sendMessage(addresses, groupMessage);
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) MediaConstraints(org.thoughtcrime.securesms.mms.MediaConstraints) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 10 with Address

use of org.thoughtcrime.securesms.database.Address in project Signal-Android by signalapp.

the class PushReceivedJob method handle.

public void handle(SignalServiceEnvelope envelope) {
    Address source = Address.fromExternal(context, envelope.getSource());
    Recipient recipient = Recipient.from(context, source, false);
    if (!isActiveNumber(recipient)) {
        DatabaseFactory.getRecipientDatabase(context).setRegistered(recipient, RecipientDatabase.RegisteredState.REGISTERED);
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context, recipient, false));
    }
    if (envelope.isReceipt()) {
        handleReceipt(envelope);
    } else if (envelope.isPreKeySignalMessage() || envelope.isSignalMessage()) {
        handleMessage(envelope, source);
    } else {
        Log.w(TAG, "Received envelope of unknown type: " + envelope.getType());
    }
}
Also used : Address(org.thoughtcrime.securesms.database.Address) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Aggregations

Address (org.thoughtcrime.securesms.database.Address)40 Recipient (org.thoughtcrime.securesms.recipients.Recipient)13 LinkedList (java.util.LinkedList)10 Uri (android.net.Uri)9 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)7 Cursor (android.database.Cursor)6 ByteString (com.google.protobuf.ByteString)6 IOException (java.io.IOException)6 File (java.io.File)5 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)5 NonNull (android.support.annotation.NonNull)4 Attachment (org.thoughtcrime.securesms.attachments.Attachment)4 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)4 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)4 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)4 SuppressLint (android.annotation.SuppressLint)3 Nullable (android.support.annotation.Nullable)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ContentValues (android.content.ContentValues)2