That fuck shit the fascists are using
1package org.tm.archive.migrations;
2
3import android.app.Notification;
4import android.app.PendingIntent;
5import android.content.Intent;
6
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import androidx.core.app.NotificationCompat;
10import androidx.core.app.NotificationManagerCompat;
11import androidx.core.app.TaskStackBuilder;
12
13import org.signal.core.util.logging.Log;
14import org.tm.archive.MainActivity;
15import org.tm.archive.NewConversationActivity;
16import org.tm.archive.R;
17import org.tm.archive.conversationlist.model.ConversationFilter;
18import org.tm.archive.database.SignalDatabase;
19import org.tm.archive.database.ThreadTable;
20import org.tm.archive.jobmanager.Job;
21import org.tm.archive.keyvalue.SignalStore;
22import org.tm.archive.notifications.NotificationChannels;
23import org.tm.archive.notifications.NotificationIds;
24import org.tm.archive.recipients.RecipientId;
25import org.signal.core.util.SetUtil;
26import org.tm.archive.util.TextSecurePreferences;
27
28import java.util.List;
29import java.util.Set;
30
31/**
32 * Show a user that contacts are newly available. Only for users that recently installed.
33 */
34public class UserNotificationMigrationJob extends MigrationJob {
35
36 private static final String TAG = Log.tag(UserNotificationMigrationJob.class);
37
38 public static final String KEY = "UserNotificationMigration";
39
40 UserNotificationMigrationJob() {
41 this(new Parameters.Builder().build());
42 }
43
44 private UserNotificationMigrationJob(Parameters parameters) {
45 super(parameters);
46 }
47
48 @Override
49 public @NonNull String getFactoryKey() {
50 return KEY;
51 }
52
53 @Override
54 boolean isUiBlocking() {
55 return false;
56 }
57
58 @Override
59 void performMigration() {
60 if (!SignalStore.account().isRegistered() ||
61 SignalStore.account().getE164() == null ||
62 SignalStore.account().getAci() == null)
63 {
64 Log.w(TAG, "Not registered! Skipping.");
65 return;
66 }
67
68 if (!SignalStore.settings().isNotifyWhenContactJoinsSignal()) {
69 Log.w(TAG, "New contact notifications disabled! Skipping.");
70 return;
71 }
72
73 if (TextSecurePreferences.getFirstInstallVersion(context) < 759) {
74 Log.w(TAG, "Install is older than v5.0.8. Skipping.");
75 return;
76 }
77
78 ThreadTable threadTable = SignalDatabase.threads();
79
80 int threadCount = threadTable.getUnarchivedConversationListCount(ConversationFilter.OFF) +
81 threadTable.getArchivedConversationListCount(ConversationFilter.OFF);
82
83 if (threadCount >= 3) {
84 Log.w(TAG, "Already have 3 or more threads. Skipping.");
85 return;
86 }
87
88 Set<RecipientId> registered = SignalDatabase.recipients().getRegistered();
89 List<RecipientId> systemContacts = SignalDatabase.recipients().getSystemContacts();
90 Set<RecipientId> registeredSystemContacts = SetUtil.intersection(registered, systemContacts);
91 Set<RecipientId> threadRecipients = threadTable.getAllThreadRecipients();
92
93 if (threadRecipients.containsAll(registeredSystemContacts)) {
94 Log.w(TAG, "Threads already exist for all relevant contacts. Skipping.");
95 return;
96 }
97
98 String message = context.getResources().getQuantityString(R.plurals.UserNotificationMigrationJob_d_contacts_are_on_signal,
99 registeredSystemContacts.size(),
100 registeredSystemContacts.size());
101
102 Intent mainActivityIntent = new Intent(context, MainActivity.class);
103 Intent newConversationIntent = new Intent(context, NewConversationActivity.class);
104 PendingIntent pendingIntent = TaskStackBuilder.create(context)
105 .addNextIntent(mainActivityIntent)
106 .addNextIntent(newConversationIntent)
107 .getPendingIntent(0, 0);
108
109 Notification notification = new NotificationCompat.Builder(context, NotificationChannels.getInstance().getMessagesChannel())
110 .setSmallIcon(R.drawable.ic_notification)
111 .setContentText(message)
112 .setContentIntent(pendingIntent)
113 .build();
114
115 try {
116 NotificationManagerCompat.from(context)
117 .notify(NotificationIds.USER_NOTIFICATION_MIGRATION, notification);
118 } catch (Throwable t) {
119 Log.w(TAG, "Failed to notify!", t);
120 }
121 }
122
123 @Override
124 boolean shouldRetry(@NonNull Exception e) {
125 return false;
126 }
127
128 public static final class Factory implements Job.Factory<UserNotificationMigrationJob> {
129
130 @Override
131 public @NonNull UserNotificationMigrationJob create(@NonNull Parameters parameters, @Nullable byte[] serializedData) {
132 return new UserNotificationMigrationJob(parameters);
133 }
134 }
135}