use of org.thoughtcrime.securesms.sms.OutgoingTextMessage in project Signal-Android by WhisperSystems.
the class AndroidAutoReplyReceiver method onReceive.
@Override
protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) {
if (!REPLY_ACTION.equals(intent.getAction()))
return;
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput == null)
return;
final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
final long threadId = intent.getLongExtra(THREAD_ID_EXTRA, -1);
final CharSequence responseText = getMessageText(intent);
final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
if (responseText != null) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
long replyThreadId;
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(recipientIds);
int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
if (recipients.isGroupRecipient()) {
Log.i("AndroidAutoReplyReceiver", "GroupRecipient, Sending media message");
OutgoingMediaMessage reply = new OutgoingMediaMessage(recipients, responseText.toString(), new LinkedList<Attachment>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
replyThreadId = MessageSender.send(context, masterSecret, reply, threadId, false);
} else {
Log.i("AndroidAutoReplyReceiver", "Sending regular message ");
OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString(), expiresIn, subscriptionId);
replyThreadId = MessageSender.send(context, masterSecret, reply, threadId, false);
}
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(replyThreadId, true);
MessageNotifier.updateNotification(context, masterSecret);
MarkReadReceiver.process(context, messageIds);
return null;
}
}.execute();
}
}
use of org.thoughtcrime.securesms.sms.OutgoingTextMessage in project Signal-Android by WhisperSystems.
the class RemoteReplyReceiver method onReceive.
@Override
protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret) {
if (!REPLY_ACTION.equals(intent.getAction()))
return;
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput == null)
return;
final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);
if (masterSecret != null && responseText != null) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
long threadId;
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(recipientIds);
int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
if (recipients.isGroupRecipient()) {
OutgoingMediaMessage reply = new OutgoingMediaMessage(recipients, responseText.toString(), new LinkedList<Attachment>(), System.currentTimeMillis(), subscriptionId, expiresIn, 0);
threadId = MessageSender.send(context, masterSecret, reply, -1, false);
} else {
OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString(), expiresIn, subscriptionId);
threadId = MessageSender.send(context, masterSecret, reply, -1, false);
}
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
MessageNotifier.updateNotification(context, masterSecret);
MarkReadReceiver.process(context, messageIds);
return null;
}
}.execute();
}
}
use of org.thoughtcrime.securesms.sms.OutgoingTextMessage 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.sms.OutgoingTextMessage in project Signal-Android by WhisperSystems.
the class ConversationActivity method sendTextMessage.
private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId) throws InvalidMessageException {
final Context context = getApplicationContext();
OutgoingTextMessage message;
if (isSecureText && !forceSms) {
message = new OutgoingEncryptedMessage(recipients, getMessage(), expiresIn);
} else {
message = new OutgoingTextMessage(recipients, getMessage(), expiresIn, subscriptionId);
}
this.composeText.setText("");
new AsyncTask<OutgoingTextMessage, Void, Long>() {
@Override
protected Long doInBackground(OutgoingTextMessage... messages) {
return MessageSender.send(context, masterSecret, messages[0], threadId, forceSms);
}
@Override
protected void onPostExecute(Long result) {
sendComplete(result);
}
}.execute(message);
}
use of org.thoughtcrime.securesms.sms.OutgoingTextMessage 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);
}
}
Aggregations