134 lines
7.1 KiB
Java
134 lines
7.1 KiB
Java
package com.discord.workers;
|
|
|
|
import android.content.Context;
|
|
import androidx.work.Data;
|
|
import androidx.work.ListenableWorker;
|
|
import androidx.work.Worker;
|
|
import androidx.work.WorkerParameters;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.models.domain.ModelMuteConfig;
|
|
import com.discord.models.domain.ModelNotificationSettings;
|
|
import com.discord.restapi.RestAPIParams;
|
|
import com.discord.stores.StoreAnalytics;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.fcm.NotificationClient;
|
|
import com.discord.utilities.io.NetworkUtils;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.time.Clock;
|
|
import com.discord.utilities.time.ClockFactory;
|
|
import com.discord.utilities.time.TimeUtils;
|
|
import d0.z.d.m;
|
|
import j0.m.b;
|
|
import java.util.Objects;
|
|
import rx.Observable;
|
|
/* compiled from: TimedMuteWorker.kt */
|
|
public final class TimedMuteWorker extends Worker {
|
|
public Clock a = ClockFactory.get();
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public TimedMuteWorker(Context context, WorkerParameters workerParameters) {
|
|
super(context, workerParameters);
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(workerParameters, "params");
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:32:0x01a6 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:33:0x01ab */
|
|
@Override // androidx.work.Worker
|
|
public ListenableWorker.Result doWork() {
|
|
long j;
|
|
String str;
|
|
long j2;
|
|
Throwable th;
|
|
AppLog appLog = AppLog.g;
|
|
String simpleName = TimedMuteWorker.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName, "javaClass.simpleName");
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Starting for [");
|
|
Data inputData = getInputData();
|
|
m.checkNotNullExpressionValue(inputData, "inputData");
|
|
sb.append(inputData.getKeyValueMap());
|
|
sb.append(']');
|
|
Logger.i$default(appLog, simpleName, sb.toString(), null, 4, null);
|
|
NotificationClient notificationClient = NotificationClient.INSTANCE;
|
|
if (!notificationClient.isAuthed()) {
|
|
String simpleName2 = TimedMuteWorker.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName2, "javaClass.simpleName");
|
|
Logger.d$default(appLog, simpleName2, "Not authenticated. Aborting job request.", null, 4, null);
|
|
ListenableWorker.Result failure = ListenableWorker.Result.failure();
|
|
m.checkNotNullExpressionValue(failure, "Result.failure()");
|
|
return failure;
|
|
}
|
|
NetworkUtils networkUtils = NetworkUtils.INSTANCE;
|
|
Context applicationContext = getApplicationContext();
|
|
m.checkNotNullExpressionValue(applicationContext, "applicationContext");
|
|
if (!NetworkUtils.isDeviceConnected$default(networkUtils, applicationContext, null, null, 6, null)) {
|
|
ListenableWorker.Result retry = ListenableWorker.Result.retry();
|
|
m.checkNotNullExpressionValue(retry, "Result.retry()");
|
|
return retry;
|
|
}
|
|
long j3 = getInputData().getLong("com.discord.intent.extra.EXTRA_GUILD_ID", -1);
|
|
long j4 = getInputData().getLong("com.discord.intent.extra.EXTRA_CHANNEL_ID", -1);
|
|
long j5 = getInputData().getLong("com.discord.intent.extra.EXTRA_UNTIL_TIMESTAMP_MS", 0);
|
|
if (j3 == -1 || j4 == -1) {
|
|
ListenableWorker.Result failure2 = ListenableWorker.Result.failure();
|
|
m.checkNotNullExpressionValue(failure2, "Result.failure()");
|
|
return failure2;
|
|
} else if (this.a.currentTimeMillis() > j5) {
|
|
ListenableWorker.Result success = ListenableWorker.Result.success();
|
|
m.checkNotNullExpressionValue(success, "Result.success()");
|
|
return success;
|
|
} else {
|
|
String uTCDateTime$default = TimeUtils.toUTCDateTime$default(Long.valueOf(j5), null, 2, null);
|
|
try {
|
|
Observable<ModelNotificationSettings> updateUserGuildSettings = RestAPI.Companion.getApi().updateUserGuildSettings(j3, new RestAPIParams.UserGuildSettings(j4, new RestAPIParams.UserGuildSettings.ChannelOverride(Boolean.TRUE, new ModelMuteConfig(uTCDateTime$default), null, 4, null)));
|
|
Objects.requireNonNull(updateUserGuildSettings);
|
|
ModelNotificationSettings modelNotificationSettings = (ModelNotificationSettings) new b(updateUserGuildSettings).a();
|
|
String simpleName3 = getClass().getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName3, "javaClass.simpleName");
|
|
str = uTCDateTime$default;
|
|
try {
|
|
Logger.d$default(appLog, simpleName3, "Muted: " + j3 + '-' + j4 + " until " + uTCDateTime$default, null, 4, null);
|
|
j2 = j4;
|
|
j = j3;
|
|
try {
|
|
NotificationClient.clear$default(notificationClient, j2, getApplicationContext(), false, 4, null);
|
|
StoreAnalytics analytics = StoreStream.Companion.getAnalytics();
|
|
m.checkNotNullExpressionValue(modelNotificationSettings, "notifSettings");
|
|
analytics.onNotificationSettingsUpdated(modelNotificationSettings, Long.valueOf(j2));
|
|
ListenableWorker.Result success2 = ListenableWorker.Result.success();
|
|
m.checkNotNullExpressionValue(success2, "Result.success()");
|
|
return success2;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
}
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
j2 = j4;
|
|
j = j3;
|
|
AppLog appLog2 = AppLog.g;
|
|
String simpleName4 = TimedMuteWorker.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName4, "javaClass.simpleName");
|
|
appLog2.w(simpleName4, "Mute failure: " + j + '-' + j2 + " until " + str, th);
|
|
ListenableWorker.Result retry2 = getRunAttemptCount() >= 3 ? ListenableWorker.Result.retry() : ListenableWorker.Result.failure();
|
|
m.checkNotNullExpressionValue(retry2, "if (runAttemptCount < MA…y() else Result.failure()");
|
|
return retry2;
|
|
}
|
|
} catch (Throwable th4) {
|
|
th = th4;
|
|
str = uTCDateTime$default;
|
|
j2 = j4;
|
|
j = j3;
|
|
AppLog appLog2 = AppLog.g;
|
|
String simpleName4 = TimedMuteWorker.class.getSimpleName();
|
|
m.checkNotNullExpressionValue(simpleName4, "javaClass.simpleName");
|
|
appLog2.w(simpleName4, "Mute failure: " + j + '-' + j2 + " until " + str, th);
|
|
if (getRunAttemptCount() >= 3) {
|
|
}
|
|
m.checkNotNullExpressionValue(retry2, "if (runAttemptCount < MA…y() else Result.failure()");
|
|
return retry2;
|
|
}
|
|
}
|
|
}
|
|
}
|