486 lines
21 KiB
Java
486 lines
21 KiB
Java
package com.discord.widgets.channels.invite;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import c.d.b.a.a;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.models.user.User;
|
|
import com.discord.stores.StoreChannels;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.stores.StoreUserRelationships;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.user.UserUtils;
|
|
import com.discord.widgets.channels.invite.GroupInviteFriendsSheetAdapter;
|
|
import d0.g0.w;
|
|
import d0.t.h0;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.concurrent.TimeUnit;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.subjects.BehaviorSubject;
|
|
import rx.subjects.PublishSubject;
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
public final class GroupInviteFriendsSheetViewModel extends AppViewModel<ViewState> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final int MAX_GROUP_MEMBERS = 10;
|
|
private static final int MAX_GROUP_MEMBERS_STAFF = 25;
|
|
private static final long SEARCH_DEBOUNCE_MILLIS = 150;
|
|
private final long channelId;
|
|
private final HashSet<User> checkedUsers;
|
|
private StoreState currentStoreState;
|
|
private final PublishSubject<Event> eventSubject;
|
|
private final int maxNumMembers;
|
|
private final BehaviorSubject<CharSequence> searchTextChangedPublisher;
|
|
private final StoreUser storeUser;
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.invite.GroupInviteFriendsSheetViewModel$1 reason: invalid class name */
|
|
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
|
|
public final /* synthetic */ GroupInviteFriendsSheetViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass1(GroupInviteFriendsSheetViewModel groupInviteFriendsSheetViewModel) {
|
|
super(1);
|
|
this.this$0 = groupInviteFriendsSheetViewModel;
|
|
}
|
|
|
|
/* 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, "storeState");
|
|
GroupInviteFriendsSheetViewModel.access$handleStoreState(this.this$0, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.invite.GroupInviteFriendsSheetViewModel$2 reason: invalid class name */
|
|
public static final class AnonymousClass2 extends o implements Function1<CharSequence, Unit> {
|
|
public final /* synthetic */ GroupInviteFriendsSheetViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass2(GroupInviteFriendsSheetViewModel groupInviteFriendsSheetViewModel) {
|
|
super(1);
|
|
this.this$0 = groupInviteFriendsSheetViewModel;
|
|
}
|
|
|
|
/* 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(CharSequence charSequence) {
|
|
invoke(charSequence);
|
|
return Unit.a;
|
|
}
|
|
|
|
public final void invoke(CharSequence charSequence) {
|
|
GroupInviteFriendsSheetViewModel groupInviteFriendsSheetViewModel = this.this$0;
|
|
m.checkNotNullExpressionValue(charSequence, "searchText");
|
|
GroupInviteFriendsSheetViewModel.access$onSearch(groupInviteFriendsSheetViewModel, charSequence);
|
|
}
|
|
}
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static final /* synthetic */ int access$getMaxNumMembers(Companion companion, StoreUser storeUser) {
|
|
return companion.getMaxNumMembers(storeUser);
|
|
}
|
|
|
|
public static final /* synthetic */ Observable access$observeStoreState(Companion companion, long j, StoreUserRelationships storeUserRelationships, StoreUser storeUser, StoreChannels storeChannels) {
|
|
return companion.observeStoreState(j, storeUserRelationships, storeUser, storeChannels);
|
|
}
|
|
|
|
private final int getMaxNumMembers(StoreUser storeUser) {
|
|
return UserUtils.INSTANCE.isStaff(storeUser.getMe()) ? 25 : 10;
|
|
}
|
|
|
|
private final Observable<Map<Long, User>> observeFriends(StoreUserRelationships storeUserRelationships, StoreUser storeUser) {
|
|
Observable<R> Y = storeUserRelationships.observeForType(1).Y(new GroupInviteFriendsSheetViewModel$Companion$observeFriends$1(storeUser));
|
|
m.checkNotNullExpressionValue(Y, "storeUserRelationships.o…ships.keys)\n }");
|
|
return Y;
|
|
}
|
|
|
|
private final Observable<StoreState> observeStoreState(long j, StoreUserRelationships storeUserRelationships, StoreUser storeUser, StoreChannels storeChannels) {
|
|
if (j == -1) {
|
|
Observable<R> F = observeFriends(storeUserRelationships, storeUser).F(GroupInviteFriendsSheetViewModel$Companion$observeStoreState$1.INSTANCE);
|
|
m.checkNotNullExpressionValue(F, "observeFriends(storeUser… )\n }");
|
|
return F;
|
|
}
|
|
Observable<StoreState> j2 = Observable.j(storeChannels.observeChannel(j), observeFriends(storeUserRelationships, storeUser), GroupInviteFriendsSheetViewModel$Companion$observeStoreState$2.INSTANCE);
|
|
m.checkNotNullExpressionValue(j2, "Observable\n … )\n }");
|
|
return j2;
|
|
}
|
|
}
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
public static final class ChannelFull extends Event {
|
|
public static final ChannelFull INSTANCE = new ChannelFull();
|
|
|
|
private ChannelFull() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
public static final class StoreState {
|
|
private final Channel channel;
|
|
private final Map<Long, User> friendUsersMap;
|
|
|
|
public StoreState() {
|
|
this(null, null, 3, null);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.util.Map<java.lang.Long, ? extends com.discord.models.user.User> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public StoreState(Map<Long, ? extends User> map, Channel channel) {
|
|
m.checkNotNullParameter(map, "friendUsersMap");
|
|
this.friendUsersMap = map;
|
|
this.channel = channel;
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ StoreState(Map map, Channel channel, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this((i & 1) != 0 ? h0.emptyMap() : map, (i & 2) != 0 ? null : channel);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.channels.invite.GroupInviteFriendsSheetViewModel$StoreState */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ StoreState copy$default(StoreState storeState, Map map, Channel channel, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
map = storeState.friendUsersMap;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
channel = storeState.channel;
|
|
}
|
|
return storeState.copy(map, channel);
|
|
}
|
|
|
|
public final Map<Long, User> component1() {
|
|
return this.friendUsersMap;
|
|
}
|
|
|
|
public final Channel component2() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final StoreState copy(Map<Long, ? extends User> map, Channel channel) {
|
|
m.checkNotNullParameter(map, "friendUsersMap");
|
|
return new StoreState(map, channel);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof StoreState)) {
|
|
return false;
|
|
}
|
|
StoreState storeState = (StoreState) obj;
|
|
return m.areEqual(this.friendUsersMap, storeState.friendUsersMap) && m.areEqual(this.channel, storeState.channel);
|
|
}
|
|
|
|
public final Channel getChannel() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final Map<Long, User> getFriendUsersMap() {
|
|
return this.friendUsersMap;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Map<Long, User> map = this.friendUsersMap;
|
|
int i = 0;
|
|
int hashCode = (map != null ? map.hashCode() : 0) * 31;
|
|
Channel channel = this.channel;
|
|
if (channel != null) {
|
|
i = channel.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("StoreState(friendUsersMap=");
|
|
L.append(this.friendUsersMap);
|
|
L.append(", channel=");
|
|
L.append(this.channel);
|
|
L.append(")");
|
|
return L.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: GroupInviteFriendsSheetViewModel.kt */
|
|
public static final class ViewState {
|
|
private final HashSet<User> checkedUsers;
|
|
private final List<GroupInviteFriendsSheetAdapter.FriendItem> friendItems;
|
|
private final boolean showSearchIcon;
|
|
|
|
public ViewState(HashSet<User> hashSet, List<GroupInviteFriendsSheetAdapter.FriendItem> list, boolean z2) {
|
|
m.checkNotNullParameter(hashSet, "checkedUsers");
|
|
m.checkNotNullParameter(list, "friendItems");
|
|
this.checkedUsers = hashSet;
|
|
this.friendItems = list;
|
|
this.showSearchIcon = z2;
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ ViewState(HashSet hashSet, List list, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(hashSet, list, (i & 4) != 0 ? true : z2);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.channels.invite.GroupInviteFriendsSheetViewModel$ViewState */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ ViewState copy$default(ViewState viewState, HashSet hashSet, List list, boolean z2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
hashSet = viewState.checkedUsers;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
list = viewState.friendItems;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z2 = viewState.showSearchIcon;
|
|
}
|
|
return viewState.copy(hashSet, list, z2);
|
|
}
|
|
|
|
public final HashSet<User> component1() {
|
|
return this.checkedUsers;
|
|
}
|
|
|
|
public final List<GroupInviteFriendsSheetAdapter.FriendItem> component2() {
|
|
return this.friendItems;
|
|
}
|
|
|
|
public final boolean component3() {
|
|
return this.showSearchIcon;
|
|
}
|
|
|
|
public final ViewState copy(HashSet<User> hashSet, List<GroupInviteFriendsSheetAdapter.FriendItem> list, boolean z2) {
|
|
m.checkNotNullParameter(hashSet, "checkedUsers");
|
|
m.checkNotNullParameter(list, "friendItems");
|
|
return new ViewState(hashSet, list, z2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof ViewState)) {
|
|
return false;
|
|
}
|
|
ViewState viewState = (ViewState) obj;
|
|
return m.areEqual(this.checkedUsers, viewState.checkedUsers) && m.areEqual(this.friendItems, viewState.friendItems) && this.showSearchIcon == viewState.showSearchIcon;
|
|
}
|
|
|
|
public final HashSet<User> getCheckedUsers() {
|
|
return this.checkedUsers;
|
|
}
|
|
|
|
public final List<GroupInviteFriendsSheetAdapter.FriendItem> getFriendItems() {
|
|
return this.friendItems;
|
|
}
|
|
|
|
public final boolean getShowSearchIcon() {
|
|
return this.showSearchIcon;
|
|
}
|
|
|
|
public int hashCode() {
|
|
HashSet<User> hashSet = this.checkedUsers;
|
|
int i = 0;
|
|
int hashCode = (hashSet != null ? hashSet.hashCode() : 0) * 31;
|
|
List<GroupInviteFriendsSheetAdapter.FriendItem> list = this.friendItems;
|
|
if (list != null) {
|
|
i = list.hashCode();
|
|
}
|
|
int i2 = (hashCode + i) * 31;
|
|
boolean z2 = this.showSearchIcon;
|
|
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 = a.L("ViewState(checkedUsers=");
|
|
L.append(this.checkedUsers);
|
|
L.append(", friendItems=");
|
|
L.append(this.friendItems);
|
|
L.append(", showSearchIcon=");
|
|
return a.G(L, this.showSearchIcon, ")");
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public GroupInviteFriendsSheetViewModel(long j, StoreUser storeUser, int i, Observable<StoreState> observable) {
|
|
super(null, 1, null);
|
|
m.checkNotNullParameter(storeUser, "storeUser");
|
|
m.checkNotNullParameter(observable, "storeStateObservable");
|
|
this.channelId = j;
|
|
this.storeUser = storeUser;
|
|
this.maxNumMembers = i;
|
|
this.eventSubject = PublishSubject.k0();
|
|
this.currentStoreState = new StoreState(null, null, 3, null);
|
|
this.checkedUsers = new HashSet<>();
|
|
BehaviorSubject<CharSequence> k0 = BehaviorSubject.k0();
|
|
this.searchTextChangedPublisher = k0;
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(observable, this, null, 2, null), GroupInviteFriendsSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
|
|
Observable<CharSequence> o = k0.o(150, TimeUnit.MILLISECONDS);
|
|
m.checkNotNullExpressionValue(o, "searchTextChangedPublish…S, TimeUnit.MILLISECONDS)");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(o, this, null, 2, null), GroupInviteFriendsSheetViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass2(this), 62, (Object) null);
|
|
}
|
|
|
|
/* JADX WARNING: Illegal instructions before constructor call */
|
|
public /* synthetic */ GroupInviteFriendsSheetViewModel(long j, StoreUser storeUser, int i, Observable observable, int i2, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(j, storeUser, i, observable);
|
|
storeUser = (i2 & 2) != 0 ? StoreStream.Companion.getUsers() : storeUser;
|
|
i = (i2 & 4) != 0 ? Companion.access$getMaxNumMembers(Companion, storeUser) : i;
|
|
if ((i2 & 8) != 0) {
|
|
Companion companion = Companion;
|
|
StoreStream.Companion companion2 = StoreStream.Companion;
|
|
observable = Companion.access$observeStoreState(companion, j, companion2.getUserRelationships(), storeUser, companion2.getChannels());
|
|
}
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(GroupInviteFriendsSheetViewModel groupInviteFriendsSheetViewModel, StoreState storeState) {
|
|
groupInviteFriendsSheetViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$onSearch(GroupInviteFriendsSheetViewModel groupInviteFriendsSheetViewModel, CharSequence charSequence) {
|
|
groupInviteFriendsSheetViewModel.onSearch(charSequence);
|
|
}
|
|
|
|
private final void emitChannelFullEvent() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
publishSubject.j.onNext(Event.ChannelFull.INSTANCE);
|
|
}
|
|
|
|
private final List<User> excludeUsersAlreadyInChannel(Map<Long, ? extends User> map, Channel channel) {
|
|
Set set;
|
|
List<com.discord.api.user.User> w;
|
|
if (channel == null || (w = channel.w()) == null) {
|
|
set = null;
|
|
} else {
|
|
ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(w, 10));
|
|
for (com.discord.api.user.User user : w) {
|
|
arrayList.add(Long.valueOf(user.i()));
|
|
}
|
|
set = u.toSet(arrayList);
|
|
}
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<Long, ? extends User> entry : map.entrySet()) {
|
|
boolean z2 = true;
|
|
if (set != null && set.contains(entry.getKey())) {
|
|
z2 = false;
|
|
}
|
|
if (z2) {
|
|
linkedHashMap.put(entry.getKey(), entry.getValue());
|
|
}
|
|
}
|
|
return u.toList(linkedHashMap.values());
|
|
}
|
|
|
|
@MainThread
|
|
private final void handleStoreState(StoreState storeState) {
|
|
this.currentStoreState = storeState;
|
|
List<User> excludeUsersAlreadyInChannel = excludeUsersAlreadyInChannel(storeState.getFriendUsersMap(), storeState.getChannel());
|
|
HashSet<User> hashSet = this.checkedUsers;
|
|
ArrayList<GroupInviteFriendsSheetAdapter.FriendItem> createItems = GroupInviteFriendsSheetAdapter.FriendItem.Companion.createItems(excludeUsersAlreadyInChannel, hashSet);
|
|
ViewState viewState = getViewState();
|
|
updateViewState(new ViewState(hashSet, createItems, viewState != null ? viewState.getShowSearchIcon() : true));
|
|
}
|
|
|
|
private final void onSearch(CharSequence charSequence) {
|
|
boolean z2;
|
|
Collection<User> values = this.currentStoreState.getFriendUsersMap().values();
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator<T> it = values.iterator();
|
|
while (true) {
|
|
z2 = true;
|
|
if (!it.hasNext()) {
|
|
break;
|
|
}
|
|
Object next = it.next();
|
|
if (w.contains((CharSequence) ((User) next).getUsername(), charSequence, true)) {
|
|
arrayList.add(next);
|
|
}
|
|
}
|
|
HashSet<User> hashSet = this.checkedUsers;
|
|
ArrayList<GroupInviteFriendsSheetAdapter.FriendItem> createItems = GroupInviteFriendsSheetAdapter.FriendItem.Companion.createItems(arrayList, hashSet);
|
|
if (!(charSequence.length() == 0) || !this.checkedUsers.isEmpty()) {
|
|
z2 = false;
|
|
}
|
|
updateViewState(new ViewState(hashSet, createItems, z2));
|
|
}
|
|
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
|
|
public final void onChangeUserChecked(User user, boolean z2) {
|
|
m.checkNotNullParameter(user, "user");
|
|
ViewState viewState = getViewState();
|
|
if (viewState != null) {
|
|
if (!z2) {
|
|
this.checkedUsers.remove(user);
|
|
} else if (this.checkedUsers.size() < this.maxNumMembers) {
|
|
this.checkedUsers.add(user);
|
|
} else {
|
|
emitChannelFullEvent();
|
|
}
|
|
List<GroupInviteFriendsSheetAdapter.FriendItem> friendItems = viewState.getFriendItems();
|
|
ArrayList arrayList = new ArrayList(d0.t.o.collectionSizeOrDefault(friendItems, 10));
|
|
for (GroupInviteFriendsSheetAdapter.FriendItem friendItem : friendItems) {
|
|
arrayList.add(friendItem.getUser());
|
|
}
|
|
HashSet<User> hashSet = this.checkedUsers;
|
|
updateViewState(ViewState.copy$default(viewState, hashSet, GroupInviteFriendsSheetAdapter.FriendItem.Companion.createItems(arrayList, hashSet), false, 4, null));
|
|
}
|
|
}
|
|
|
|
public final void onSearchTextChanged(CharSequence charSequence) {
|
|
m.checkNotNullParameter(charSequence, "searchText");
|
|
this.searchTextChangedPublisher.onNext(charSequence);
|
|
}
|
|
}
|