That fuck shit the fascists are using
1package org.tm.archive;
2
3import android.app.Activity;
4import android.content.Intent;
5import android.database.Cursor;
6import android.os.Bundle;
7import android.provider.ContactsContract;
8import android.text.TextUtils;
9import android.widget.Toast;
10
11import androidx.annotation.NonNull;
12
13import org.signal.core.util.logging.Log;
14import org.tm.archive.conversation.ConversationIntents;
15import org.tm.archive.database.SignalDatabase;
16import org.tm.archive.recipients.Recipient;
17import org.tm.archive.util.Rfc5724Uri;
18
19import java.net.URISyntaxException;
20
21public class SmsSendtoActivity extends Activity {
22
23 private static final String TAG = Log.tag(SmsSendtoActivity.class);
24
25 @Override
26 protected void onCreate(Bundle savedInstanceState) {
27 startActivity(getNextIntent(getIntent()));
28 finish();
29 super.onCreate(savedInstanceState);
30 }
31
32 private Intent getNextIntent(Intent original) {
33 DestinationAndBody destination;
34
35 if (original.getAction().equals(Intent.ACTION_SENDTO)) {
36 destination = getDestinationForSendTo(original);
37 } else if (original.getData() != null && "content".equals(original.getData().getScheme())) {
38 destination = getDestinationForSyncAdapter(original);
39 } else {
40 destination = getDestinationForView(original);
41 }
42
43 final Intent nextIntent;
44
45 if (TextUtils.isEmpty(destination.destination)) {
46 nextIntent = new Intent(this, NewConversationActivity.class);
47 nextIntent.putExtra(Intent.EXTRA_TEXT, destination.getBody());
48 Toast.makeText(this, R.string.ConversationActivity_specify_recipient, Toast.LENGTH_LONG).show();
49 } else {
50 Recipient recipient = Recipient.external(this, destination.getDestination());
51 long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
52
53 nextIntent = ConversationIntents.createBuilderSync(this, recipient.getId(), threadId)
54 .withDraftText(destination.getBody())
55 .build();
56 }
57 return nextIntent;
58 }
59
60 private @NonNull DestinationAndBody getDestinationForSendTo(Intent intent) {
61 return new DestinationAndBody(intent.getData().getSchemeSpecificPart(),
62 intent.getStringExtra("sms_body"));
63 }
64
65 private @NonNull DestinationAndBody getDestinationForView(Intent intent) {
66 try {
67 Rfc5724Uri smsUri = new Rfc5724Uri(intent.getData().toString());
68 return new DestinationAndBody(smsUri.getPath(), smsUri.getQueryParams().get("body"));
69 } catch (URISyntaxException e) {
70 Log.w(TAG, "unable to parse RFC5724 URI from intent", e);
71 return new DestinationAndBody("", "");
72 }
73 }
74
75 private @NonNull DestinationAndBody getDestinationForSyncAdapter(Intent intent) {
76 Cursor cursor = null;
77
78 try {
79 cursor = getContentResolver().query(intent.getData(), null, null, null, null);
80
81 if (cursor != null && cursor.moveToNext()) {
82 return new DestinationAndBody(cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.RawContacts.Data.DATA1)), "");
83 }
84
85 return new DestinationAndBody("", "");
86 } finally {
87 if (cursor != null) cursor.close();
88 }
89 }
90
91 private static class DestinationAndBody {
92 private final String destination;
93 private final String body;
94
95 private DestinationAndBody(String destination, String body) {
96 this.destination = destination;
97 this.body = body;
98 }
99
100 public String getDestination() {
101 return destination;
102 }
103
104 public String getBody() {
105 return body;
106 }
107 }
108}