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);
}
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);
}
}
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());
}
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);
}
}
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());
}
}
Aggregations