649 lines
28 KiB
Java
649 lines
28 KiB
Java
package com.discord.utilities.rest;
|
|
|
|
import a0.a.a.b;
|
|
import android.content.ContentResolver;
|
|
import android.content.Context;
|
|
import android.net.Uri;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import b.d.b.a.a;
|
|
import b.i.a.f.e.o.f;
|
|
import com.discord.R;
|
|
import com.discord.api.commands.ApplicationCommandType;
|
|
import com.discord.models.commands.ApplicationCommandLocalSendData;
|
|
import com.discord.models.domain.ModelAuditLogEntry;
|
|
import com.discord.restapi.RestAPIParams;
|
|
import com.discord.utilities.attachments.AttachmentUtilsKt;
|
|
import com.discord.utilities.captcha.CaptchaErrorBody;
|
|
import com.discord.utilities.error.Error;
|
|
import com.discord.utilities.messagesend.MessageResult;
|
|
import com.discord.widgets.captcha.WidgetCaptchaBottomSheet;
|
|
import com.discord.widgets.chat.input.models.ApplicationCommandValue;
|
|
import com.lytefast.flexinput.model.Attachment;
|
|
import d0.f0.l;
|
|
import d0.g0.w;
|
|
import d0.o;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import j0.l.a.q;
|
|
import j0.l.e.k;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.NoSuchElementException;
|
|
import java.util.Objects;
|
|
import kotlin.Pair;
|
|
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.k0;
|
|
import s.a.x0;
|
|
/* 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, ModelAuditLogEntry.CHANGE_KEY_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, ModelAuditLogEntry.CHANGE_KEY_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 R = a.R("FileUpload(name=");
|
|
R.append(this.name);
|
|
R.append(", contentLength=");
|
|
R.append(this.contentLength);
|
|
R.append(", part=");
|
|
R.append(this.part);
|
|
R.append(", mimeType=");
|
|
R.append(this.mimeType);
|
|
R.append(", bytesWrittenObservable=");
|
|
R.append(this.bytesWrittenObservable);
|
|
R.append(")");
|
|
return R.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 R = a.R("Preprocessing(numFiles=");
|
|
R.append(this.numFiles);
|
|
R.append(", name=");
|
|
R.append(this.name);
|
|
R.append(", mimeType=");
|
|
return a.H(R, 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 R = a.R("ReadyToSend(message=");
|
|
R.append(this.message);
|
|
R.append(", uploads=");
|
|
return a.K(R, this.uploads, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: SendUtils.kt */
|
|
public static final class ReadyToSendCommand extends SendPayload {
|
|
private final ApplicationCommandLocalSendData command;
|
|
private final List<FileUpload> uploads;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public ReadyToSendCommand(ApplicationCommandLocalSendData applicationCommandLocalSendData, List<FileUpload> list) {
|
|
super(null);
|
|
m.checkNotNullParameter(applicationCommandLocalSendData, "command");
|
|
m.checkNotNullParameter(list, "uploads");
|
|
this.command = applicationCommandLocalSendData;
|
|
this.uploads = list;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.utilities.rest.SendUtils$SendPayload$ReadyToSendCommand */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ ReadyToSendCommand copy$default(ReadyToSendCommand readyToSendCommand, ApplicationCommandLocalSendData applicationCommandLocalSendData, List list, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
applicationCommandLocalSendData = readyToSendCommand.command;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
list = readyToSendCommand.uploads;
|
|
}
|
|
return readyToSendCommand.copy(applicationCommandLocalSendData, list);
|
|
}
|
|
|
|
public final ApplicationCommandLocalSendData component1() {
|
|
return this.command;
|
|
}
|
|
|
|
public final List<FileUpload> component2() {
|
|
return this.uploads;
|
|
}
|
|
|
|
public final ReadyToSendCommand copy(ApplicationCommandLocalSendData applicationCommandLocalSendData, List<FileUpload> list) {
|
|
m.checkNotNullParameter(applicationCommandLocalSendData, "command");
|
|
m.checkNotNullParameter(list, "uploads");
|
|
return new ReadyToSendCommand(applicationCommandLocalSendData, list);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof ReadyToSendCommand)) {
|
|
return false;
|
|
}
|
|
ReadyToSendCommand readyToSendCommand = (ReadyToSendCommand) obj;
|
|
return m.areEqual(this.command, readyToSendCommand.command) && m.areEqual(this.uploads, readyToSendCommand.uploads);
|
|
}
|
|
|
|
public final ApplicationCommandLocalSendData getCommand() {
|
|
return this.command;
|
|
}
|
|
|
|
public final List<FileUpload> getUploads() {
|
|
return this.uploads;
|
|
}
|
|
|
|
public int hashCode() {
|
|
ApplicationCommandLocalSendData applicationCommandLocalSendData = this.command;
|
|
int i = 0;
|
|
int hashCode = (applicationCommandLocalSendData != null ? applicationCommandLocalSendData.hashCode() : 0) * 31;
|
|
List<FileUpload> list = this.uploads;
|
|
if (list != null) {
|
|
i = list.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder R = a.R("ReadyToSendCommand(command=");
|
|
R.append(this.command);
|
|
R.append(", uploads=");
|
|
return a.K(R, 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);
|
|
}
|
|
|
|
private final SendPayload.Preprocessing getPreprocessingFromAttachments(ContentResolver contentResolver, List<? extends Attachment<?>> list) {
|
|
if (list.size() != 1) {
|
|
return new SendPayload.Preprocessing(list.size(), null, null);
|
|
}
|
|
Attachment<?> attachment = (Attachment) u.first((List<? extends Object>) list);
|
|
return new SendPayload.Preprocessing(1, Attachment.Companion.a(attachment), AttachmentUtilsKt.getMimeType(contentResolver, attachment.getUri(), attachment.getDisplayName()));
|
|
}
|
|
|
|
/* 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);
|
|
}
|
|
|
|
private final Pair<String, String> splitFileExtension(String str) {
|
|
int lastIndexOf$default = w.lastIndexOf$default((CharSequence) str, '.', 0, false, 6, (Object) null);
|
|
if (lastIndexOf$default == -1) {
|
|
return o.to(str, null);
|
|
}
|
|
Objects.requireNonNull(str, "null cannot be cast to non-null type java.lang.String");
|
|
String substring = str.substring(0, lastIndexOf$default);
|
|
m.checkNotNullExpressionValue(substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
|
|
String substring2 = str.substring(lastIndexOf$default + 1);
|
|
m.checkNotNullExpressionValue(substring2, "(this as java.lang.String).substring(startIndex)");
|
|
return o.to(substring, substring2);
|
|
}
|
|
|
|
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");
|
|
x0 x0Var = x0.j;
|
|
CoroutineDispatcher coroutineDispatcher = k0.a;
|
|
f.H0(x0Var, n.f3802b, null, new SendUtils$compressImageAttachments$1(list, context, function1, null), 2, null);
|
|
}
|
|
|
|
public final Observable<SendPayload> getSendCommandPayload(ContentResolver contentResolver, ApplicationCommandLocalSendData applicationCommandLocalSendData, List<? extends Attachment<?>> list) {
|
|
m.checkNotNullParameter(contentResolver, "contentResolver");
|
|
m.checkNotNullParameter(applicationCommandLocalSendData, "apiParamMessage");
|
|
if (list != null) {
|
|
List<Attachment<?>> uniqueifyNames = uniqueifyNames(list);
|
|
List<ApplicationCommandValue> applicationCommandsValues = applicationCommandLocalSendData.getApplicationCommandsValues();
|
|
ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(applicationCommandsValues, 10));
|
|
for (ApplicationCommandValue applicationCommandValue : applicationCommandsValues) {
|
|
if (applicationCommandValue.getType() == ApplicationCommandType.ATTACHMENT.getType()) {
|
|
Iterator<T> it = uniqueifyNames.iterator();
|
|
while (it.hasNext()) {
|
|
Attachment attachment = (Attachment) it.next();
|
|
if (m.areEqual(attachment.getUri().toString(), applicationCommandValue.getValue())) {
|
|
applicationCommandValue = ApplicationCommandValue.copy$default(applicationCommandValue, null, attachment.getDisplayName(), 0, null, null, 29, null);
|
|
}
|
|
}
|
|
throw new NoSuchElementException("Collection contains no element matching the predicate.");
|
|
}
|
|
arrayList.add(applicationCommandValue);
|
|
}
|
|
ApplicationCommandLocalSendData copy$default = ApplicationCommandLocalSendData.copy$default(applicationCommandLocalSendData, 0, 0, null, null, null, null, null, null, arrayList, null, null, 1791, null);
|
|
if (!uniqueifyNames.isEmpty()) {
|
|
k kVar = new k(getPreprocessingFromAttachments(contentResolver, uniqueifyNames));
|
|
ArrayList arrayList2 = new ArrayList(d0.t.o.collectionSizeOrDefault(uniqueifyNames, 10));
|
|
int i = 0;
|
|
for (Object obj : uniqueifyNames) {
|
|
int i2 = i + 1;
|
|
if (i < 0) {
|
|
d0.t.n.throwIndexOverflow();
|
|
}
|
|
SendUtils sendUtils = INSTANCE;
|
|
arrayList2.add(sendUtils.getPart((Attachment) obj, contentResolver, "files[" + i + ']'));
|
|
i = i2;
|
|
}
|
|
Observable<SendPayload> m = Observable.m(kVar, Observable.l(Observable.h0(new q(arrayList2))).f0().F(new SendUtils$getSendCommandPayload$2(copy$default)));
|
|
m.checkNotNullExpressionValue(m, "Observable.concat(\n …)\n }\n )");
|
|
return m;
|
|
}
|
|
k kVar2 = new k(new SendPayload.ReadyToSendCommand(copy$default, d0.t.n.emptyList()));
|
|
m.checkNotNullExpressionValue(kVar2, "Observable.just(SendPayl…tedMessage, emptyList()))");
|
|
return kVar2;
|
|
}
|
|
k kVar3 = new k(new SendPayload.ReadyToSendCommand(applicationCommandLocalSendData, d0.t.n.emptyList()));
|
|
m.checkNotNullExpressionValue(kVar3, "Observable.just(SendPayl…ramMessage, emptyList()))");
|
|
return kVar3;
|
|
}
|
|
|
|
public final Observable<SendPayload> getSendPayload(ContentResolver contentResolver, RestAPIParams.Message message, List<? extends Attachment<?>> list) {
|
|
String str;
|
|
List<Attachment<?>> list2;
|
|
RestAPIParams.Message message2 = message;
|
|
m.checkNotNullParameter(contentResolver, "contentResolver");
|
|
m.checkNotNullParameter(message2, "apiParamMessage");
|
|
if (list == null) {
|
|
k kVar = new k(new SendPayload.ReadyToSend(message2, d0.t.n.emptyList()));
|
|
m.checkNotNullExpressionValue(kVar, "Observable.just(SendPayl…ramMessage, emptyList()))");
|
|
return kVar;
|
|
}
|
|
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())) {
|
|
str = "Observable.just(SendPayl…ramMessage, emptyList()))";
|
|
list2 = extractLinks;
|
|
message2 = RestAPIParams.Message.copy$default(message, appendLinks, null, null, null, null, null, null, null, null, 510, null);
|
|
} else {
|
|
str = "Observable.just(SendPayl…ramMessage, emptyList()))";
|
|
list2 = extractLinks;
|
|
}
|
|
List<Attachment<?>> uniqueifyNames = uniqueifyNames(u.minus((Iterable) list, (Iterable) list2));
|
|
if (!uniqueifyNames.isEmpty()) {
|
|
k kVar2 = new k(getPreprocessingFromAttachments(contentResolver, uniqueifyNames));
|
|
ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(uniqueifyNames, 10));
|
|
int i = 0;
|
|
for (Object obj : uniqueifyNames) {
|
|
int i2 = i + 1;
|
|
if (i < 0) {
|
|
d0.t.n.throwIndexOverflow();
|
|
}
|
|
arrayList.add(INSTANCE.getPart((Attachment) obj, contentResolver, a.p("file", i)));
|
|
i = i2;
|
|
}
|
|
Observable<SendPayload> m = Observable.m(kVar2, Observable.l(Observable.h0(new q(arrayList))).f0().F(new SendUtils$getSendPayload$2(message2)));
|
|
m.checkNotNullExpressionValue(m, "Observable.concat(\n …)\n }\n )");
|
|
return m;
|
|
}
|
|
k kVar3 = new k(new SendPayload.ReadyToSend(message2, d0.t.n.emptyList()));
|
|
m.checkNotNullExpressionValue(kVar3, str);
|
|
return kVar3;
|
|
}
|
|
|
|
public final void handleCaptchaRequired(MessageResult.CaptchaRequired captchaRequired) {
|
|
m.checkNotNullParameter(captchaRequired, "messageResult");
|
|
WidgetCaptchaBottomSheet.Companion.enqueue("Message Captcha", new SendUtils$handleCaptchaRequired$1(captchaRequired), new SendUtils$handleCaptchaRequired$2(captchaRequired), CaptchaErrorBody.Companion.createFromError(captchaRequired.getError()));
|
|
}
|
|
|
|
@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) {
|
|
b.a.d.m.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 {
|
|
b.a.d.m.g(context, R.string.network_error_bad_request, 0, null, 12);
|
|
}
|
|
} else if (function02 != null) {
|
|
function02.mo1invoke();
|
|
}
|
|
error.showToasts(context);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public final <T> Attachment<T> renamedWithDuplicateCount(Attachment<? extends T> attachment, int i) {
|
|
String str;
|
|
m.checkNotNullParameter(attachment, "$this$renamedWithDuplicateCount");
|
|
long id2 = attachment.getId();
|
|
Uri uri = attachment.getUri();
|
|
Pair<String, String> splitFileExtension = splitFileExtension(attachment.getDisplayName());
|
|
String component1 = splitFileExtension.component1();
|
|
String component2 = splitFileExtension.component2();
|
|
if (component2 != null) {
|
|
str = component1 + '-' + i + '.' + component2;
|
|
} else {
|
|
str = component1 + '-' + i;
|
|
}
|
|
return new Attachment<>(id2, uri, str, attachment.getData(), false, 16, null);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public final List<Attachment<?>> uniqueifyNames(List<? extends Attachment<?>> list) {
|
|
m.checkNotNullParameter(list, "attachmentParts");
|
|
return d0.f0.q.toList(l.sequence(new SendUtils$uniqueifyNames$1(list, null)));
|
|
}
|
|
}
|