458 lines
18 KiB
Java
458 lines
18 KiB
Java
package com.discord.utilities.rest;
|
|
|
|
import a0.a.a.b;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import c.d.b.a.a;
|
|
import com.discord.restapi.RestAPIParams;
|
|
import com.discord.utilities.attachments.AttachmentUtilsKt;
|
|
import com.discord.utilities.error.Error;
|
|
import com.lytefast.flexinput.model.Attachment;
|
|
import d0.t.o;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import j0.l.a.q;
|
|
import j0.l.e.j;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlinx.coroutines.CoroutineDispatcher;
|
|
import okhttp3.MultipartBody;
|
|
import rx.Emitter;
|
|
import rx.Observable;
|
|
import s.a.a.n;
|
|
import s.a.j0;
|
|
import s.a.w0;
|
|
/* compiled from: SendUtils.kt */
|
|
public final class SendUtils {
|
|
public static final SendUtils INSTANCE = new SendUtils();
|
|
public static final int MAX_MESSAGE_CHARACTER_COUNT = 2000;
|
|
public static final int MAX_MESSAGE_CHARACTER_COUNT_PREMIUM = 4000;
|
|
|
|
/* compiled from: SendUtils.kt */
|
|
public static final class FileUpload {
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final long SIZE_UNKNOWN = -1;
|
|
private final Observable<Long> bytesWrittenObservable;
|
|
private final long contentLength;
|
|
private final String mimeType;
|
|
private final String name;
|
|
private final MultipartBody.Part part;
|
|
|
|
/* compiled from: SendUtils.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public FileUpload(String str, long j, MultipartBody.Part part, String str2, Observable<Long> observable) {
|
|
m.checkNotNullParameter(str, "name");
|
|
m.checkNotNullParameter(part, "part");
|
|
m.checkNotNullParameter(str2, "mimeType");
|
|
m.checkNotNullParameter(observable, "bytesWrittenObservable");
|
|
this.name = str;
|
|
this.contentLength = j;
|
|
this.part = part;
|
|
this.mimeType = str2;
|
|
this.bytesWrittenObservable = observable;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: com.discord.utilities.rest.SendUtils$FileUpload */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ FileUpload copy$default(FileUpload fileUpload, String str, long j, MultipartBody.Part part, String str2, Observable observable, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
str = fileUpload.name;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
j = fileUpload.contentLength;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
part = fileUpload.part;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
str2 = fileUpload.mimeType;
|
|
}
|
|
if ((i & 16) != 0) {
|
|
observable = fileUpload.bytesWrittenObservable;
|
|
}
|
|
return fileUpload.copy(str, j, part, str2, observable);
|
|
}
|
|
|
|
public final String component1() {
|
|
return this.name;
|
|
}
|
|
|
|
public final long component2() {
|
|
return this.contentLength;
|
|
}
|
|
|
|
public final MultipartBody.Part component3() {
|
|
return this.part;
|
|
}
|
|
|
|
public final String component4() {
|
|
return this.mimeType;
|
|
}
|
|
|
|
public final Observable<Long> component5() {
|
|
return this.bytesWrittenObservable;
|
|
}
|
|
|
|
public final FileUpload copy(String str, long j, MultipartBody.Part part, String str2, Observable<Long> observable) {
|
|
m.checkNotNullParameter(str, "name");
|
|
m.checkNotNullParameter(part, "part");
|
|
m.checkNotNullParameter(str2, "mimeType");
|
|
m.checkNotNullParameter(observable, "bytesWrittenObservable");
|
|
return new FileUpload(str, j, part, str2, observable);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof FileUpload)) {
|
|
return false;
|
|
}
|
|
FileUpload fileUpload = (FileUpload) obj;
|
|
return m.areEqual(this.name, fileUpload.name) && this.contentLength == fileUpload.contentLength && m.areEqual(this.part, fileUpload.part) && m.areEqual(this.mimeType, fileUpload.mimeType) && m.areEqual(this.bytesWrittenObservable, fileUpload.bytesWrittenObservable);
|
|
}
|
|
|
|
public final Observable<Long> getBytesWrittenObservable() {
|
|
return this.bytesWrittenObservable;
|
|
}
|
|
|
|
public final long getContentLength() {
|
|
return this.contentLength;
|
|
}
|
|
|
|
public final String getMimeType() {
|
|
return this.mimeType;
|
|
}
|
|
|
|
public final String getName() {
|
|
return this.name;
|
|
}
|
|
|
|
public final MultipartBody.Part getPart() {
|
|
return this.part;
|
|
}
|
|
|
|
public int hashCode() {
|
|
String str = this.name;
|
|
int i = 0;
|
|
int a = (b.a(this.contentLength) + ((str != null ? str.hashCode() : 0) * 31)) * 31;
|
|
MultipartBody.Part part = this.part;
|
|
int hashCode = (a + (part != null ? part.hashCode() : 0)) * 31;
|
|
String str2 = this.mimeType;
|
|
int hashCode2 = (hashCode + (str2 != null ? str2.hashCode() : 0)) * 31;
|
|
Observable<Long> observable = this.bytesWrittenObservable;
|
|
if (observable != null) {
|
|
i = observable.hashCode();
|
|
}
|
|
return hashCode2 + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("FileUpload(name=");
|
|
L.append(this.name);
|
|
L.append(", contentLength=");
|
|
L.append(this.contentLength);
|
|
L.append(", part=");
|
|
L.append(this.part);
|
|
L.append(", mimeType=");
|
|
L.append(this.mimeType);
|
|
L.append(", bytesWrittenObservable=");
|
|
L.append(this.bytesWrittenObservable);
|
|
L.append(")");
|
|
return L.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: SendUtils.kt */
|
|
public static abstract class SendPayload {
|
|
|
|
/* compiled from: SendUtils.kt */
|
|
public static final class Preprocessing extends SendPayload {
|
|
private final String mimeType;
|
|
private final String name;
|
|
private final int numFiles;
|
|
|
|
public Preprocessing(int i, String str, String str2) {
|
|
super(null);
|
|
this.numFiles = i;
|
|
this.name = str;
|
|
this.mimeType = str2;
|
|
}
|
|
|
|
public static /* synthetic */ Preprocessing copy$default(Preprocessing preprocessing, int i, String str, String str2, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
i = preprocessing.numFiles;
|
|
}
|
|
if ((i2 & 2) != 0) {
|
|
str = preprocessing.name;
|
|
}
|
|
if ((i2 & 4) != 0) {
|
|
str2 = preprocessing.mimeType;
|
|
}
|
|
return preprocessing.copy(i, str, str2);
|
|
}
|
|
|
|
public final int component1() {
|
|
return this.numFiles;
|
|
}
|
|
|
|
public final String component2() {
|
|
return this.name;
|
|
}
|
|
|
|
public final String component3() {
|
|
return this.mimeType;
|
|
}
|
|
|
|
public final Preprocessing copy(int i, String str, String str2) {
|
|
return new Preprocessing(i, str, str2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Preprocessing)) {
|
|
return false;
|
|
}
|
|
Preprocessing preprocessing = (Preprocessing) obj;
|
|
return this.numFiles == preprocessing.numFiles && m.areEqual(this.name, preprocessing.name) && m.areEqual(this.mimeType, preprocessing.mimeType);
|
|
}
|
|
|
|
public final String getMimeType() {
|
|
return this.mimeType;
|
|
}
|
|
|
|
public final String getName() {
|
|
return this.name;
|
|
}
|
|
|
|
public final int getNumFiles() {
|
|
return this.numFiles;
|
|
}
|
|
|
|
public int hashCode() {
|
|
int i = this.numFiles * 31;
|
|
String str = this.name;
|
|
int i2 = 0;
|
|
int hashCode = (i + (str != null ? str.hashCode() : 0)) * 31;
|
|
String str2 = this.mimeType;
|
|
if (str2 != null) {
|
|
i2 = str2.hashCode();
|
|
}
|
|
return hashCode + i2;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("Preprocessing(numFiles=");
|
|
L.append(this.numFiles);
|
|
L.append(", name=");
|
|
L.append(this.name);
|
|
L.append(", mimeType=");
|
|
return a.D(L, this.mimeType, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: SendUtils.kt */
|
|
public static final class ReadyToSend extends SendPayload {
|
|
private final RestAPIParams.Message message;
|
|
private final List<FileUpload> uploads;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public ReadyToSend(RestAPIParams.Message message, List<FileUpload> list) {
|
|
super(null);
|
|
m.checkNotNullParameter(message, "message");
|
|
m.checkNotNullParameter(list, "uploads");
|
|
this.message = message;
|
|
this.uploads = list;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.utilities.rest.SendUtils$SendPayload$ReadyToSend */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ ReadyToSend copy$default(ReadyToSend readyToSend, RestAPIParams.Message message, List list, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
message = readyToSend.message;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
list = readyToSend.uploads;
|
|
}
|
|
return readyToSend.copy(message, list);
|
|
}
|
|
|
|
public final RestAPIParams.Message component1() {
|
|
return this.message;
|
|
}
|
|
|
|
public final List<FileUpload> component2() {
|
|
return this.uploads;
|
|
}
|
|
|
|
public final ReadyToSend copy(RestAPIParams.Message message, List<FileUpload> list) {
|
|
m.checkNotNullParameter(message, "message");
|
|
m.checkNotNullParameter(list, "uploads");
|
|
return new ReadyToSend(message, list);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof ReadyToSend)) {
|
|
return false;
|
|
}
|
|
ReadyToSend readyToSend = (ReadyToSend) obj;
|
|
return m.areEqual(this.message, readyToSend.message) && m.areEqual(this.uploads, readyToSend.uploads);
|
|
}
|
|
|
|
public final RestAPIParams.Message getMessage() {
|
|
return this.message;
|
|
}
|
|
|
|
public final List<FileUpload> getUploads() {
|
|
return this.uploads;
|
|
}
|
|
|
|
public int hashCode() {
|
|
RestAPIParams.Message message = this.message;
|
|
int i = 0;
|
|
int hashCode = (message != null ? message.hashCode() : 0) * 31;
|
|
List<FileUpload> list = this.uploads;
|
|
if (list != null) {
|
|
i = list.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("ReadyToSend(message=");
|
|
L.append(this.message);
|
|
L.append(", uploads=");
|
|
return a.E(L, this.uploads, ")");
|
|
}
|
|
}
|
|
|
|
private SendPayload() {
|
|
}
|
|
|
|
public /* synthetic */ SendPayload(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
private SendUtils() {
|
|
}
|
|
|
|
private final Observable<FileUpload> getPart(Attachment<?> attachment, ContentResolver contentResolver, String str) {
|
|
return Observable.n(new SendUtils$getPart$1(attachment, str, contentResolver), Emitter.BackpressureMode.BUFFER);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: com.discord.utilities.rest.SendUtils */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ void handleSendError$default(SendUtils sendUtils, Error error, Context context, Function0 function0, Function0 function02, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
function0 = null;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
function02 = null;
|
|
}
|
|
sendUtils.handleSendError(error, context, function0, function02);
|
|
}
|
|
|
|
public final void compressImageAttachments(Context context, List<? extends Attachment<?>> list, Function1<? super List<? extends Attachment<?>>, Unit> function1) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(list, "attachments");
|
|
m.checkNotNullParameter(function1, "onCompressed");
|
|
w0 w0Var = w0.i;
|
|
CoroutineDispatcher coroutineDispatcher = j0.a;
|
|
c.q.a.k.a.G(w0Var, n.b, null, new SendUtils$compressImageAttachments$1(list, context, function1, null), 2, null);
|
|
}
|
|
|
|
public final Observable<SendPayload> getSendPayload(ContentResolver contentResolver, RestAPIParams.Message message, List<? extends Attachment<?>> list) {
|
|
SendPayload.Preprocessing preprocessing;
|
|
RestAPIParams.Message message2 = message;
|
|
m.checkNotNullParameter(contentResolver, "contentResolver");
|
|
m.checkNotNullParameter(message2, "apiParamMessage");
|
|
if (list == null) {
|
|
j jVar = new j(new SendPayload.ReadyToSend(message2, d0.t.n.emptyList()));
|
|
m.checkNotNullExpressionValue(jVar, "Observable.just(SendPayl…ramMessage, emptyList()))");
|
|
return jVar;
|
|
}
|
|
List<Attachment<?>> extractLinks = AttachmentUtilsKt.extractLinks(list, contentResolver);
|
|
String content = message.getContent();
|
|
if (content == null) {
|
|
content = "";
|
|
}
|
|
String appendLinks = AttachmentUtilsKt.appendLinks(content, extractLinks);
|
|
if (!m.areEqual(appendLinks, message.getContent())) {
|
|
message2 = RestAPIParams.Message.copy$default(message, appendLinks, null, null, null, null, null, null, 126, null);
|
|
}
|
|
List minus = u.minus((Iterable) list, (Iterable) extractLinks);
|
|
if (!minus.isEmpty()) {
|
|
if (minus.size() != 1) {
|
|
preprocessing = new SendPayload.Preprocessing(minus.size(), null, null);
|
|
} else {
|
|
Attachment attachment = (Attachment) u.first((List<? extends Object>) minus);
|
|
preprocessing = new SendPayload.Preprocessing(1, attachment.getDisplayName(), AttachmentUtilsKt.getMimeType(contentResolver, attachment.getUri(), attachment.getDisplayName()));
|
|
}
|
|
j jVar2 = new j(preprocessing);
|
|
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(minus, 10));
|
|
int i = 0;
|
|
for (Object obj : minus) {
|
|
int i2 = i + 1;
|
|
if (i < 0) {
|
|
d0.t.n.throwIndexOverflow();
|
|
}
|
|
arrayList.add(INSTANCE.getPart((Attachment) obj, contentResolver, a.k("file", i)));
|
|
i = i2;
|
|
}
|
|
Observable<SendPayload> m = Observable.m(jVar2, Observable.l(Observable.h0(new q(arrayList))).f0().F(new SendUtils$getSendPayload$2(message2)));
|
|
m.checkNotNullExpressionValue(m, "Observable.concat(\n …)\n }\n )");
|
|
return m;
|
|
}
|
|
j jVar3 = new j(new SendPayload.ReadyToSend(message2, d0.t.n.emptyList()));
|
|
m.checkNotNullExpressionValue(jVar3, "Observable.just(SendPayl…ramMessage, emptyList()))");
|
|
return jVar3;
|
|
}
|
|
|
|
@MainThread
|
|
public final void handleSendError(Error error, Context context, Function0<Unit> function0, Function0<Unit> function02) {
|
|
m.checkNotNullParameter(error, "error");
|
|
m.checkNotNullParameter(context, "context");
|
|
error.setShowErrorToasts(false);
|
|
Error.Response response = error.getResponse();
|
|
m.checkNotNullExpressionValue(response, "error.response");
|
|
Integer abortCodeMessageResId = RestAPIAbortMessages.getAbortCodeMessageResId(response.getCode());
|
|
if (abortCodeMessageResId != null) {
|
|
c.a.d.o.g(context, abortCodeMessageResId.intValue(), 0, null, 12);
|
|
} else if (error.getType() == Error.Type.REQUEST_TOO_LARGE) {
|
|
if (function0 != null) {
|
|
function0.mo1invoke();
|
|
}
|
|
} else if (error.getType() != Error.Type.FORBIDDEN_DISCORD) {
|
|
Error.Response response2 = error.getResponse();
|
|
m.checkNotNullExpressionValue(response2, "error.response");
|
|
if (response2.isKnownResponse() || error.getType() == Error.Type.NETWORK) {
|
|
error.setShowErrorToasts(true);
|
|
} else {
|
|
c.a.d.o.g(context, 2131891463, 0, null, 12);
|
|
}
|
|
} else if (function02 != null) {
|
|
function02.mo1invoke();
|
|
}
|
|
error.showToasts(context);
|
|
}
|
|
}
|