2014-12-15 21:25:55 +01:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2015-04-21 22:40:21 +02:00
|
|
|
import android.util.Log;
|
2014-12-15 21:25:55 +01:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2015-04-21 22:40:21 +02:00
|
|
|
import org.thoughtcrime.securesms.util.Rfc5724Uri;
|
|
|
|
|
|
|
|
import java.net.URISyntaxException;
|
2014-12-15 21:25:55 +01:00
|
|
|
|
|
|
|
public class SmsSendtoActivity extends Activity {
|
2015-04-21 22:40:21 +02:00
|
|
|
|
|
|
|
private static final String TAG = SmsSendtoActivity.class.getSimpleName();
|
|
|
|
|
2014-12-15 21:25:55 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
startActivity(getNextIntent(getIntent()));
|
|
|
|
finish();
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Intent getNextIntent(Intent original) {
|
2015-04-21 22:40:21 +02:00
|
|
|
String body = "";
|
|
|
|
String data = "";
|
|
|
|
|
|
|
|
if (original.getAction().equals(Intent.ACTION_SENDTO)) {
|
|
|
|
body = original.getStringExtra("sms_body");
|
|
|
|
data = original.getData().getSchemeSpecificPart();
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Rfc5724Uri smsUri = new Rfc5724Uri(original.getData().toString());
|
|
|
|
body = smsUri.getQueryParams().get("body");
|
|
|
|
data = smsUri.getPath();
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
Log.w(TAG, "unable to parse RFC5724 URI from intent", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 21:25:55 +01:00
|
|
|
Recipients recipients = RecipientFactory.getRecipientsFromString(this, data, false);
|
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(this).getThreadIdIfExistsFor(recipients);
|
|
|
|
|
|
|
|
final Intent nextIntent;
|
|
|
|
if (recipients == null || recipients.isEmpty()) {
|
|
|
|
nextIntent = new Intent(this, NewConversationActivity.class);
|
|
|
|
nextIntent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, body);
|
|
|
|
Toast.makeText(this, R.string.ConversationActivity_specify_recipient, Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
nextIntent = new Intent(this, ConversationActivity.class);
|
|
|
|
nextIntent.putExtra(ConversationActivity.DRAFT_TEXT_EXTRA, body);
|
|
|
|
nextIntent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
|
|
|
nextIntent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
|
|
|
}
|
|
|
|
return nextIntent;
|
|
|
|
}
|
|
|
|
}
|