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

564 lines
25 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.api.channel.Channel;
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.StoreGuildSelected;
import com.discord.stores.StoreGuildStickers;
import com.discord.stores.StoreGuilds;
import com.discord.stores.StoreNotices;
import com.discord.stores.StoreStickers;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreUser;
import com.discord.utilities.permissions.PermissionUtils;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.widgets.chat.input.sticker.StickerPickerFeatureFlag;
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 StoreGuildSelected storeGuildSelected;
private final StoreGuildStickers storeGuildStickers;
private final StoreGuilds storeGuilds;
private final StoreStickers storeStickers;
private final StoreUser storeUser;
/* 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> Y = StoreStream.Companion.getChannelsSelected().observeResolvedSelectedChannel().Y(AppFlexInputViewModel$Companion$observeStores$1.INSTANCE);
m.checkNotNullExpressionValue(Y, "StoreStream\n .g… }\n }");
return Y;
}
}
/* compiled from: AppFlexInputViewModel.kt */
public static final class StoreState {
private final Long channelPermission;
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) {
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;
}
public static /* synthetic */ StoreState copy$default(StoreState storeState, PanelState panelState, PanelState panelState2, Channel channel, Long l, StoreNotices.Notice notice, boolean z2, 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;
}
return storeState.copy(panelState, panelState2, channel, l, notice, z2);
}
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 StoreState copy(PanelState panelState, PanelState panelState2, Channel channel, Long l, StoreNotices.Notice notice, boolean z2) {
m.checkNotNullParameter(panelState, "leftPanelState");
m.checkNotNullParameter(panelState2, "rightPanelState");
return new StoreState(panelState, panelState2, channel, l, notice, z2);
}
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;
}
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;
if (z2) {
z2 = true;
}
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
return i2 + i3;
}
public String toString() {
StringBuilder L = c.d.b.a.a.L("StoreState(leftPanelState=");
L.append(this.leftPanelState);
L.append(", rightPanelState=");
L.append(this.rightPanelState);
L.append(", selectedChannel=");
L.append(this.selectedChannel);
L.append(", channelPermission=");
L.append(this.channelPermission);
L.append(", notice=");
L.append(this.notice);
L.append(", stickerSuggestionsEnabled=");
return c.d.b.a.a.G(L, this.stickerSuggestionsEnabled, ")");
}
}
/* 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, StoreUser storeUser, StoreGuildStickers storeGuildStickers, StoreGuilds storeGuilds, StoreGuildSelected storeGuildSelected) {
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");
m.checkNotNullParameter(storeUser, "storeUser");
m.checkNotNullParameter(storeGuildStickers, "storeGuildStickers");
m.checkNotNullParameter(storeGuilds, "storeGuilds");
m.checkNotNullParameter(storeGuildSelected, "storeGuildSelected");
this.permissionRequests = appPermissionsRequests;
this.storeStickers = storeStickers;
this.storeAnalytics = storeAnalytics;
this.storeExpressionSuggestions = storeExpressionSuggestions;
this.storeUser = storeUser;
this.storeGuildStickers = storeGuildStickers;
this.storeGuilds = storeGuilds;
this.storeGuildSelected = storeGuildSelected;
this.eventSubject = PublishSubject.k0();
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, StoreUser storeUser, StoreGuildStickers storeGuildStickers, StoreGuilds storeGuilds, StoreGuildSelected storeGuildSelected, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(appPermissionsRequests, (i & 2) != 0 ? new FlexInputState(null, false, null, null, false, false, false, false, false, 511) : 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, (i & 64) != 0 ? StoreStream.Companion.getUsers() : storeUser, (i & 128) != 0 ? StoreStream.Companion.getGuildStickers() : storeGuildStickers, (i & 256) != 0 ? StoreStream.Companion.getGuilds() : storeGuilds, (i & 512) != 0 ? StoreStream.Companion.getGuildSelected() : storeGuildSelected);
}
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 hasAccessWrite = selectedChannel != null ? PermissionUtils.INSTANCE.hasAccessWrite(selectedChannel, channelPermission) : false;
boolean z5 = selectedChannel != null && (AnimatableValueParser.s1(selectedChannel) || PermissionUtils.can(32768, channelPermission));
boolean z6 = requireViewState.g;
if (z4 || z3) {
hideKeyboard();
z2 = false;
} else {
z2 = z6;
}
updateViewState(FlexInputState.a(requireViewState, null, false, null, null, hasAccessWrite, z5, z2, false, storeState.getStickerSuggestionsEnabled(), 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, 496));
}
}
public final void focus() {
PublishSubject<a> publishSubject = this.eventSubject;
publishSubject.j.onNext(a.C0048a.a);
}
public final List<Sticker> getMatchingStickers(String str) {
m.checkNotNullParameter(str, "inputText");
AppFlexInputViewModel$getMatchingStickers$1 appFlexInputViewModel$getMatchingStickers$1 = AppFlexInputViewModel$getMatchingStickers$1.INSTANCE;
boolean isEnabled = StickerPickerFeatureFlag.Companion.getINSTANCE().isEnabled();
int length = str.length();
return u.toList((!isEnabled || !(3 <= length && 50 >= length)) ? n0.emptySet() : appFlexInputViewModel$getMatchingStickers$1.invoke(str));
}
@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, 447));
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, 507));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onContentDialogDismissed() {
showKeyboard();
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, false, false, 503));
}
@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, 503));
if (i == 0) {
this.storeAnalytics.trackChatInputComponentViewed("media picker");
} else if (i == 1) {
this.storeAnalytics.trackChatInputComponentViewed("files");
} else if (i == 2) {
this.storeAnalytics.trackChatInputComponentViewed("camera");
}
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onExpandButtonClicked() {
updateViewState(FlexInputState.a(requireViewState(), null, true, null, null, false, false, false, false, false, 509));
}
@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, 447));
}
@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(2131887180));
return;
}
hideKeyboard();
updateViewState(FlexInputState.a(requireViewState, null, false, null, 0, false, false, false, false, false, 439));
}
@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, 0, AppFlexInputViewModel$onGiftButtonClicked$1.INSTANCE, 22, null));
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public void onInputTextAppended(String str) {
m.checkNotNullParameter(str, "appendText");
c.c0(this, c.d.b.a.a.D(new StringBuilder(), requireViewState().a, str), null, 2, null);
}
/* JADX WARNING: Removed duplicated region for block: B:21:0x0053 */
/* JADX WARNING: Removed duplicated region for block: B:29:0x0069 */
/* JADX WARNING: Removed duplicated region for block: B:31:0x006c */
@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 (StickerPickerFeatureFlag.Companion.getINSTANCE().isEnabled()) {
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, 508));
}
}
z2 = requireViewState.b;
if (StickerPickerFeatureFlag.Companion.getINSTANCE().isEnabled()) {
}
if (str.length() == 0) {
}
if (z3) {
}
updateViewState(FlexInputState.a(requireViewState, str, z2, null, null, false, false, false, false, false, 508));
}
}
@Override // com.lytefast.flexinput.viewmodel.FlexInputViewModel
@MainThread
public boolean onInputTextClicked() {
showKeyboard();
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, false, false, 447));
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.f2390c, 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, 496));
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, 383));
}
@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, 447));
return true;
}
public final void showKeyboardAndHideExpressionTray() {
updateViewState(FlexInputState.a(requireViewState(), null, false, null, null, false, false, false, false, false, 447));
showKeyboard();
}
}