use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.
the class WebRtcCallService method getRemoteRecipient.
///
@NonNull
private Recipient getRemoteRecipient(Intent intent) {
String remoteNumber = intent.getStringExtra(EXTRA_REMOTE_NUMBER);
if (TextUtils.isEmpty(remoteNumber))
throw new AssertionError("No recipient in intent!");
Recipients recipients = RecipientFactory.getRecipientsFromString(this, remoteNumber, true);
Recipient result = recipients.getPrimaryRecipient();
if (result == null)
throw new AssertionError("Recipient lookup failed!");
else
return result;
}
use of org.thoughtcrime.securesms.recipients.Recipients 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);
}
}
use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.
the class MessageSender method resendGroupMessage.
public static void resendGroupMessage(Context context, MasterSecret masterSecret, MessageRecord messageRecord, long filterRecipientId) {
if (!messageRecord.isMms())
throw new AssertionError("Not Group");
Recipients recipients = DatabaseFactory.getMmsAddressDatabase(context).getRecipientsForId(messageRecord.getId());
sendGroupPush(context, recipients, messageRecord.getId(), filterRecipientId);
}
use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.
the class MessageSender method resend.
public static void resend(Context context, MasterSecret masterSecret, MessageRecord messageRecord) {
try {
long messageId = messageRecord.getId();
boolean forceSms = messageRecord.isForcedSms();
boolean keyExchange = messageRecord.isKeyExchange();
long expiresIn = messageRecord.getExpiresIn();
if (messageRecord.isMms()) {
Recipients recipients = DatabaseFactory.getMmsAddressDatabase(context).getRecipientsForId(messageId);
sendMediaMessage(context, masterSecret, recipients, forceSms, messageId, expiresIn);
} else {
Recipients recipients = messageRecord.getRecipients();
sendTextMessage(context, recipients, forceSms, keyExchange, messageId, expiresIn);
}
} catch (MmsException e) {
Log.w(TAG, e);
}
}
use of org.thoughtcrime.securesms.recipients.Recipients in project Signal-Android by WhisperSystems.
the class PushDecryptJob method handleTextMessage.
private void handleTextMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
String body = message.getBody().isPresent() ? message.getBody().get() : "";
Recipients recipients = getMessageDestination(envelope, message);
if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
}
Long threadId;
if (smsMessageId.isPresent() && !message.getGroupInfo().isPresent()) {
threadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body).second;
} else {
IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo(), message.getExpiresInSeconds() * 1000);
textMessage = new IncomingEncryptedMessage(textMessage, body);
Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, textMessage);
if (insertResult.isPresent())
threadId = insertResult.get().getThreadId();
else
threadId = null;
if (smsMessageId.isPresent())
database.deleteMessage(smsMessageId.get());
}
if (threadId != null) {
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
}
}
Aggregations