discord-jadx/app/src/main/java/com/discord/widgets/chat/input/AppFlexInputViewModel.java

588 lines
26 KiB
Java

package com.discord.widgets.chat.input;
import android.content.Context;
import android.view.View;
import androidx.annotation.MainThread;
import c.b.a.h.a;
import c.i.a.f.e.o.c;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.R;
import com.discord.api.channel.Channel;
import com.discord.api.permission.Permission;
import com.discord.api.sticker.Sticker;
import com.discord.app.AppPermissionsRequests;
import com.discord.app.AppViewModel;
import com.discord.panels.PanelState;
import com.discord.stores.StoreAnalytics;
import com.discord.stores.StoreExpressionSuggestions;
import com.discord.stores.StoreNotices;
import com.discord.stores.StoreStickers;
import com.discord.stores.StoreStream;
import com.discord.utilities.analytics.ChatInputComponentTypes;
import com.discord.utilities.channel.ChannelSelector;
import com.discord.utilities.font.FontUtils;
import com.discord.utilities.permissions.PermissionUtils;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.widgets.home.WidgetHome;
import com.lytefast.flexinput.FlexInputListener;
import com.lytefast.flexinput.model.Attachment;
import com.lytefast.flexinput.viewmodel.FlexInputState;
import com.lytefast.flexinput.viewmodel.FlexInputViewModel;
import d0.t.n;
import d0.t.n0;
import d0.t.u;
import d0.z.d.a0;
import d0.z.d.k;
import d0.z.d.m;
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 rx.Observable;
import rx.subjects.PublishSubject;
/* compiled from: AppFlexInputViewModel.kt */
public final class AppFlexInputViewModel extends AppViewModel<FlexInputState> implements FlexInputViewModel {
private static final String CHAT_GIFTING_NOTICE = "CHAT_GIFTING_NOTICE";
public static final Companion Companion = new Companion(null);
private PublishSubject<a> eventSubject;
private final AppPermissionsRequests permissionRequests;
private final StoreAnalytics storeAnalytics;
private final StoreExpressionSuggestions storeExpressionSuggestions;
private final StoreStickers storeStickers;
/* compiled from: AppFlexInputViewModel.kt */
/* renamed from: com.discord.widgets.chat.input.AppFlexInputViewModel$1 reason: invalid class name */
public static final /* synthetic */ class AnonymousClass1 extends k implements Function1<StoreState, Unit> {
public AnonymousClass1(AppFlexInputViewModel appFlexInputViewModel) {
super(1, appFlexInputViewModel, AppFlexInputViewModel.class, "handleStoreState", "handleStoreState(Lcom/discord/widgets/chat/input/AppFlexInputViewModel$StoreState;)V", 0);
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(StoreState storeState) {
invoke(storeState);
return Unit.a;
}
public final void invoke(StoreState storeState) {
m.checkNotNullParameter(storeState, "p1");
AppFlexInputViewModel.access$handleStoreState((AppFlexInputViewModel) this.receiver, storeState);
}
}
/* compiled from: AppFlexInputViewModel.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Observable access$observeStores(Companion companion) {
return companion.observeStores();
}
private final Observable<StoreState> observeStores() {
Observable<R> X = StoreStream.Companion.getChannelsSelected().observeResolvedSelectedChannel().X(AppFlexInputViewModel$Companion$observeStores$1.INSTANCE);
m.checkNotNullExpressionValue(X, "StoreStream\n .g… }\n }");
return X;
}
}
/* compiled from: AppFlexInputViewModel.kt */
public static final class StoreState {
private final Long channelPermission;
private final boolean isThreadCreation;
private final PanelState leftPanelState;
private final StoreNotices.Notice notice;
private final PanelState rightPanelState;
private final Channel selectedChannel;
private final boolean stickerSuggestionsEnabled;
public StoreState(PanelState panelState, PanelState panelState2, Channel channel, Long l, StoreNotices.Notice notice, boolean z2, boolean z3) {
m.checkNotNullParameter(panelState, "leftPanelState");
m.checkNotNullParameter(panelState2, "rightPanelState");
this.leftPanelState = panelState;
this.rightPanelState = panelState2;
this.selectedChannel = channel;
this.channelPermission = l;
this.notice = notice;
this.stickerSuggestionsEnabled = z2;
this.isThreadCreation = z3;
}
public static /* synthetic */ StoreState copy$default(StoreState storeState, PanelState panelState, PanelState panelState2, Channel channel, Long l, StoreNotices.Notice notice, boolean z2, boolean z3, int i, Object obj) {
if ((i & 1) != 0) {
panelState = storeState.leftPanelState;
}
if ((i & 2) != 0) {
panelState2 = storeState.rightPanelState;
}
if ((i & 4) != 0) {
channel = storeState.selectedChannel;
}
if ((i & 8) != 0) {
l = storeState.channelPermission;
}
if ((i & 16) != 0) {
notice = storeState.notice;
}
if ((i & 32) != 0) {
z2 = storeState.stickerSuggestionsEnabled;
}
if ((i & 64) != 0) {
z3 = storeState.isThreadCreation;
}
return storeState.copy(panelState, panelState2, channel, l, notice, z2, z3);
}
public final PanelState component1() {
return this.leftPanelState;
}
public final PanelState component2() {
return this.rightPanelState;
}
public final Channel component3() {
return this.selectedChannel;
}
public final Long component4() {
return this.channelPermission;
}
public final StoreNotices.Notice component5() {
return this.notice;
}
public final boolean component6() {
return this.stickerSuggestionsEnabled;
}
public final boolean component7() {
return this.isThreadCreation;
}
public final StoreState copy(PanelState panelState, PanelState panelState2, Channel channel, Long l, StoreNotices.Notice notice, boolean z2, boolean z3) {
m.checkNotNullParameter(panelState, "leftPanelState");
m.checkNotNullParameter(panelState2, "rightPanelState");
return new StoreState(panelState, panelState2, channel, l, notice, z2, z3);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StoreState)) {
return false;
}
StoreState storeState = (StoreState) obj;
return m.areEqual(this.leftPanelState, storeState.leftPanelState) && m.areEqual(this.rightPanelState, storeState.rightPanelState) && m.areEqual(this.selectedChannel, storeState.selectedChannel) && m.areEqual(this.channelPermission, storeState.channelPermission) && m.areEqual(this.notice, storeState.notice) && this.stickerSuggestionsEnabled == storeState.stickerSuggestionsEnabled && this.isThreadCreation == storeState.isThreadCreation;
}
public final Long getChannelPermission() {
return this.channelPermission;
}
public final PanelState getLeftPanelState() {
return this.leftPanelState;
}
public final StoreNotices.Notice getNotice() {
return this.notice;
}
public final PanelState getRightPanelState() {
return this.rightPanelState;
}
public final Channel getSelectedChannel() {
return this.selectedChannel;
}
public final boolean getStickerSuggestionsEnabled() {
return this.stickerSuggestionsEnabled;
}
public int hashCode() {
PanelState panelState = this.leftPanelState;
int i = 0;
int hashCode = (panelState != null ? panelState.hashCode() : 0) * 31;
PanelState panelState2 = this.rightPanelState;
int hashCode2 = (hashCode + (panelState2 != null ? panelState2.hashCode() : 0)) * 31;
Channel channel = this.selectedChannel;
int hashCode3 = (hashCode2 + (channel != null ? channel.hashCode() : 0)) * 31;
Long l = this.channelPermission;
int hashCode4 = (hashCode3 + (l != null ? l.hashCode() : 0)) * 31;
StoreNotices.Notice notice = this.notice;
if (notice != null) {
i = notice.hashCode();
}
int i2 = (hashCode4 + i) * 31;
boolean z2 = this.stickerSuggestionsEnabled;
int i3 = 1;
if (z2) {
z2 = true;
}
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
int i6 = z2 ? 1 : 0;
int i7 = (i2 + i4) * 31;
boolean z3 = this.isThreadCreation;
if (!z3) {
i3 = z3 ? 1 : 0;
}
return i7 + i3;
}
public final boolean isThreadCreation() {
return this.isThreadCreation;
}
public String toString() {
StringBuilder P = c.d.b.a.a.P("StoreState(leftPanelState=");
P.append(this.leftPanelState);
P.append(", rightPanelState=");
P.append(this.rightPanelState);
P.append(", selectedChannel=");
P.append(this.selectedChannel);
P.append(", channelPermission=");
P.append(this.channelPermission);
P.append(", notice=");
P.append(this.notice);
P.append(", stickerSuggestionsEnabled=");
P.append(this.stickerSuggestionsEnabled);
P.append(", isThreadCreation=");
return c.d.b.a.a.L(P, this.isThreadCreation, ")");
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public AppFlexInputViewModel(AppPermissionsRequests appPermissionsRequests, FlexInputState flexInputState, Observable<StoreState> observable, StoreStickers storeStickers, StoreAnalytics storeAnalytics, StoreExpressionSuggestions storeExpressionSuggestions) {
super(flexInputState);
m.checkNotNullParameter(appPermissionsRequests, "permissionRequests");
m.checkNotNullParameter(flexInputState, "initialViewState");
m.checkNotNullParameter(observable, "storeObservable");
m.checkNotNullParameter(storeStickers, "storeStickers");
m.checkNotNullParameter(storeAnalytics, "storeAnalytics");
m.checkNotNullParameter(storeExpressionSuggestions, "storeExpressionSuggestions");
this.permissionRequests = appPermissionsRequests;
this.storeStickers = storeStickers;
this.storeAnalytics = storeAnalytics;
this.storeExpressionSuggestions = storeExpressionSuggestions;
this.eventSubject = PublishSubject.j0();
Observable r = ObservableExtensionsKt.computationLatest(observable).r();
m.checkNotNullExpressionValue(r, "storeObservable\n … .distinctUntilChanged()");
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(r, this, null, 2, null), AppFlexInputViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ AppFlexInputViewModel(AppPermissionsRequests appPermissionsRequests, FlexInputState flexInputState, Observable observable, StoreStickers storeStickers, StoreAnalytics storeAnalytics, StoreExpressionSuggestions storeExpressionSuggestions, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(appPermissionsRequests, (i & 2) != 0 ? new FlexInputState(null, false, null, null, false, false, false, false, false, null, null, 2047) : flexInputState, (i & 4) != 0 ? Companion.access$observeStores(Companion) : observable, (i & 8) != 0 ? StoreStream.Companion.getStickers() : storeStickers, (i & 16) != 0 ? StoreStream.Companion.getAnalytics() : storeAnalytics, (i & 32) != 0 ? StoreStream.Companion.getExpressionSuggestions() : storeExpressionSuggestions);
}
public static final /* synthetic */ void access$handleStoreState(AppFlexInputViewModel appFlexInputViewModel, StoreState storeState) {
appFlexInputViewModel.handleStoreState(storeState);
}
public static /* synthetic */ void clean$default(AppFlexInputViewModel appFlexInputViewModel, boolean z2, int i, Object obj) {
if ((i & 1) != 0) {
z2 = true;
}
appFlexInputViewModel.clean(z2);
}
private final void handleStoreState(StoreState storeState) {
boolean z2;
FlexInputState requireViewState = requireViewState();
Channel selectedChannel = storeState.getSelectedChannel();
Long channelPermission = storeState.getChannelPermission();
PanelState leftPanelState = storeState.getLeftPanelState();
PanelState.a aVar = PanelState.a.a;
boolean z3 = (m.areEqual(leftPanelState, aVar) ^ true) || (m.areEqual(storeState.getRightPanelState(), aVar) ^ true);
boolean z4 = storeState.getNotice() != null && !storeState.getNotice().isInAppNotification() && !storeState.getNotice().isPopup();
boolean can = selectedChannel == null ? false : storeState.isThreadCreation() ? PermissionUtils.can(Permission.SEND_MESSAGES_IN_THREADS, channelPermission) : PermissionUtils.INSTANCE.hasAccessWrite(selectedChannel, channelPermission);
boolean z5 = selectedChannel != null && (AnimatableValueParser.t1(selectedChannel) || PermissionUtils.can(Permission.ATTACH_FILES, channelPermission));
boolean z6 = requireViewState.g;
if (z4 || z3) {
hideKeyboard();
z2 = false;
} else {
z2 = z6;
}
updateViewState(FlexInputState.a(requireViewState, null, false, null, null, can, z5, z2, false, storeState.getStickerSuggestionsEnabled(), selectedChannel != null ? Long.valueOf(selectedChannel.h()) : null, selectedChannel != null ? Long.valueOf(selectedChannel.f()) : null, 143));
}
private final void showKeyboard() {
PublishSubject<a> publishSubject = this.eventSubject;
publishSubject.j.onNext(a.c.a);
}
@MainThread
public final void clean(boolean z2) {
FlexInputState viewState = getViewState();
if (viewState != null) {
updateViewState(FlexInputState.a(viewState, z2 ? "" : viewState.a, true, n.emptyList(), null, false, false, false, false, false, null, null, 2032));
}
}
public final void focus() {
PublishSubject<a> publishSubject = this.eventSubject;
publishSubject.j.onNext(a.C0052a.a);
}
public final List<Sticker> getMatchingStickers(String str) {
m.checkNotNullParameter(str, "inputText");
AppFlexInputViewModel$getMatchingStickers$1 appFlexInputViewModel$getMatchingStickers$1 = AppFlexInputViewModel$getMatchingStickers$1.INSTANCE;
int length = str.length();
return u.toList(3 <= length && 50 >= length ? appFlexInputViewModel$getMatchingStickers$1.invoke(str) : n0.emptySet());
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
public boolean hasMediaPermissions() {
return this.permissionRequests.hasMedia();
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public boolean hideExpressionTray() {
FlexInputState viewState = getViewState();
if (viewState == null || !viewState.g) {
return false;
}
updateViewState(FlexInputState.a(viewState, null, false, null, null, false, false, false, false, false, null, null, 1983));
return true;
}
public final void hideKeyboard() {
PublishSubject<a> publishSubject = this.eventSubject;
publishSubject.j.onNext(a.b.a);
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public Observable<a> observeEvents() {
PublishSubject<a> publishSubject = this.eventSubject;
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
return publishSubject;
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public Observable<FlexInputState> observeState() {
return observeViewState();
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onAttachmentsUpdated(List<? extends Attachment<? extends Object>> list) {
m.checkNotNullParameter(list, "attachments");
updateViewState(FlexInputState.a(requireViewState(), null, false, new ArrayList(list), null, false, false, false, false, false, null, null, 2043));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onContentDialogDismissed(boolean z2) {
if (z2) {
showKeyboard();
}
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, false, false, null, null, 2039));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onContentDialogPageChanged(int i) {
updateViewState(FlexInputState.a(requireViewState(), null, false, null, Integer.valueOf(i), false, false, false, false, false, null, null, 2039));
if (i == 0) {
this.storeAnalytics.trackChatInputComponentViewed(ChatInputComponentTypes.MEDIA_PICKER);
} else if (i == 1) {
this.storeAnalytics.trackChatInputComponentViewed(ChatInputComponentTypes.FILES);
} else if (i == 2) {
this.storeAnalytics.trackChatInputComponentViewed(ChatInputComponentTypes.CAMERA);
}
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
public void onCreateThreadSelected() {
Long l = requireViewState().j;
Long l2 = requireViewState().k;
if (l != null) {
l.longValue();
if (l2 != null) {
l2.longValue();
ChannelSelector.openCreateThread$default(ChannelSelector.Companion.getInstance(), l2.longValue(), l.longValue(), null, "Plus Button", 4, null);
onContentDialogDismissed(false);
}
}
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onExpandButtonClicked() {
updateViewState(FlexInputState.a(requireViewState(), null, true, null, null, false, false, false, false, false, null, null, 2045));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onExpressionTrayButtonClicked() {
FlexInputState requireViewState = requireViewState();
if (requireViewState.g) {
showKeyboard();
} else {
hideKeyboard();
}
updateViewState(FlexInputState.a(requireViewState, null, false, null, null, false, false, !requireViewState.g, false, false, null, null, 1983));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onFlexInputFragmentPause() {
hideKeyboard();
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onGalleryButtonClicked() {
FlexInputState requireViewState = requireViewState();
if (!requireViewState.f) {
PublishSubject<a> publishSubject = this.eventSubject;
publishSubject.j.onNext(new a.e(R.string.cannot_attach_files));
return;
}
hideKeyboard();
updateViewState(FlexInputState.a(requireViewState, null, false, null, 0, false, false, false, false, false, null, null, 1975));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onGiftButtonClicked() {
hideKeyboard();
StoreStream.Companion.getNotices().requestToShow(new StoreNotices.Notice(CHAT_GIFTING_NOTICE, null, 0, 0, false, d0.t.m.listOf(a0.getOrCreateKotlinClass(WidgetHome.class)), 0, false, 0, AppFlexInputViewModel$onGiftButtonClicked$1.INSTANCE, FontUtils.MAX_FONT_SCALING, null));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onInputTextAppended(String str) {
m.checkNotNullParameter(str, "appendText");
c.d0(this, c.d.b.a.a.H(new StringBuilder(), requireViewState().a, str), null, 2, null);
}
/* JADX WARNING: Removed duplicated region for block: B:21:0x0051 */
/* JADX WARNING: Removed duplicated region for block: B:22:0x0053 */
/* JADX WARNING: Removed duplicated region for block: B:24:0x0056 */
/* JADX WARNING: Removed duplicated region for block: B:27:0x0061 */
/* JADX WARNING: Removed duplicated region for block: B:29:0x0064 */
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onInputTextChanged(String str, Boolean bool) {
boolean z2;
m.checkNotNullParameter(str, "inputText");
FlexInputState requireViewState = requireViewState();
if (!m.areEqual(str, requireViewState.a) && requireViewState.e) {
if (m.areEqual(bool, Boolean.TRUE)) {
showKeyboard();
} else if (m.areEqual(bool, Boolean.FALSE)) {
hideKeyboard();
}
boolean z3 = false;
if (requireViewState.b) {
if (str.length() > 0) {
z2 = false;
if (str.length() <= 0) {
this.storeStickers.fetchEnabledStickerDirectory();
}
if (str.length() == 0) {
z3 = true;
}
if (z3) {
this.storeExpressionSuggestions.setExpressionSuggestionsEnabled(true);
}
updateViewState(FlexInputState.a(requireViewState, str, z2, null, null, false, false, false, false, false, null, null, 2044));
}
}
z2 = requireViewState.b;
if (str.length() <= 0) {
}
if (str.length() == 0) {
}
if (z3) {
}
updateViewState(FlexInputState.a(requireViewState, str, z2, null, null, false, false, false, false, false, null, null, 2044));
}
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public boolean onInputTextClicked() {
showKeyboard();
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, false, false, null, null, 1983));
return false;
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onSendButtonClicked(FlexInputListener flexInputListener) {
FlexInputState viewState = getViewState();
if (viewState != null && flexInputListener != null) {
flexInputListener.onSend(viewState.a, viewState.f2479c, new AppFlexInputViewModel$onSendButtonClicked$1(this));
}
}
@MainThread
public void onShowDialog() {
hideKeyboard();
}
@MainThread
public final void onStickerSuggestionSent(boolean z2) {
FlexInputState viewState = getViewState();
if (viewState != null) {
updateViewState(FlexInputState.a(viewState, z2 ? "" : viewState.a, true, n.emptyList(), null, false, false, false, false, false, null, null, 2032));
if (z2) {
hideKeyboard();
} else {
this.storeExpressionSuggestions.setExpressionSuggestionsEnabled(false);
}
}
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public boolean onToolTipButtonLongPressed(View view) {
m.checkNotNullParameter(view, "button");
PublishSubject<a> publishSubject = this.eventSubject;
publishSubject.j.onNext(new a.d(view.getContentDescription().toString()));
return true;
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
public void requestMediaPermissions(Function0<Unit> function0) {
m.checkNotNullParameter(function0, "onSuccess");
this.permissionRequests.requestMedia(function0);
}
public void setShowExpressionTrayButtonBadge(boolean z2) {
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, z2, false, null, null, 1919));
}
@MainThread
public boolean showExpressionTray() {
FlexInputState viewState = getViewState();
if (viewState == null || viewState.g) {
return false;
}
updateViewState(FlexInputState.a(viewState, null, false, null, null, false, false, true, false, false, null, null, 1983));
return true;
}
public final void showKeyboardAndHideExpressionTray() {
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, false, false, null, null, 1983));
showKeyboard();
}
}