discord-jadx/app/src/main/java/com/discord/widgets/user/search/WidgetGlobalSearchModel$Com...

111 lines
5.8 KiB
Java

package com.discord.widgets.user.search;
import android.annotation.SuppressLint;
import c.d.b.a.a;
import com.discord.api.channel.Channel;
import com.discord.models.member.GuildMember;
import com.discord.models.presence.Presence;
import com.discord.models.user.User;
import com.discord.utilities.user.UserUtils;
import com.discord.widgets.user.search.WidgetGlobalSearchModel;
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.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.jvm.functions.Function3;
/* compiled from: WidgetGlobalSearchModel.kt */
public final class WidgetGlobalSearchModel$Companion$create$2 extends o implements Function3<User, String, Channel, WidgetGlobalSearchModel.ItemUser> {
public final /* synthetic */ WidgetGlobalSearchModel.ChannelContext $channelContext;
public final /* synthetic */ WidgetGlobalSearchModel.SearchContext $searchContext;
public final /* synthetic */ WidgetGlobalSearchModel.UsersContext $usersContext;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public WidgetGlobalSearchModel$Companion$create$2(WidgetGlobalSearchModel.UsersContext usersContext, WidgetGlobalSearchModel.SearchContext searchContext, WidgetGlobalSearchModel.ChannelContext channelContext) {
super(3);
this.$usersContext = usersContext;
this.$searchContext = searchContext;
this.$channelContext = channelContext;
}
public static /* synthetic */ WidgetGlobalSearchModel.ItemUser invoke$default(WidgetGlobalSearchModel$Companion$create$2 widgetGlobalSearchModel$Companion$create$2, User user, String str, Channel channel, int i, Object obj) {
if ((i & 2) != 0) {
channel = null;
}
return widgetGlobalSearchModel$Companion$create$2.invoke(user, str, channel);
}
@SuppressLint({"DefaultLocale"})
public final WidgetGlobalSearchModel.ItemUser invoke(User user, String str, Channel channel) {
Integer num;
m.checkNotNullParameter(user, "$this$toItemUser");
m.checkNotNullParameter(str, "userFilter");
Collection<Map<Long, GuildMember>> values = this.$usersContext.getMembers().values();
ArrayList arrayList = new ArrayList();
Iterator<T> it = values.iterator();
while (true) {
String str2 = null;
if (!it.hasNext()) {
break;
}
GuildMember guildMember = (GuildMember) a.d(user, (Map) it.next());
if (guildMember != null) {
str2 = guildMember.getNick();
}
if (str2 != null) {
arrayList.add(str2);
}
}
List<String> distinct = u.distinct(arrayList);
ArrayList<WidgetGlobalSearchModel.MatchedResult> arrayList2 = new ArrayList();
for (String str3 : distinct) {
WidgetGlobalSearchModel.MatchedResult matchedResult = WidgetGlobalSearchModel.Companion.toMatchedResult(str3, str);
if (matchedResult != null) {
arrayList2.add(matchedResult);
}
}
ArrayList<WidgetGlobalSearchModel.MatchedResult> arrayList3 = new ArrayList();
for (String str4 : distinct) {
WidgetGlobalSearchModel.MatchedResult fuzzyMatchedResult = WidgetGlobalSearchModel.Companion.toFuzzyMatchedResult(str4, str);
if (fuzzyMatchedResult != null) {
arrayList3.add(fuzzyMatchedResult);
}
}
String username = this.$searchContext.getHasDiscriminator() ? user.getUsername() + UserUtils.INSTANCE.getDiscriminatorWithPadding(user) : user.getUsername();
WidgetGlobalSearchModel.Companion companion = WidgetGlobalSearchModel.Companion;
WidgetGlobalSearchModel.MatchedResult matchedResult2 = companion.toMatchedResult(username, str);
WidgetGlobalSearchModel.MatchedResult fuzzyMatchedResult2 = companion.toFuzzyMatchedResult(username, str);
if (matchedResult2 == null) {
if (!arrayList2.isEmpty()) {
fuzzyMatchedResult2 = (WidgetGlobalSearchModel.MatchedResult) u.first((List<? extends Object>) arrayList2);
} else if (fuzzyMatchedResult2 == null) {
if (!arrayList3.isEmpty()) {
fuzzyMatchedResult2 = (WidgetGlobalSearchModel.MatchedResult) u.first((List<? extends Object>) arrayList3);
} else {
matchedResult2 = null;
}
}
matchedResult2 = fuzzyMatchedResult2;
}
if (matchedResult2 == null) {
return null;
}
Integer num2 = (Integer) a.d(user, this.$usersContext.getRelationships());
boolean z2 = num2 != null && num2.intValue() == 1;
List listOf = d0.t.m.listOf(user.getUsername() + UserUtils.INSTANCE.getDiscriminatorWithPadding(user));
ArrayList arrayList4 = new ArrayList(d0.t.o.collectionSizeOrDefault(arrayList2, 10));
for (WidgetGlobalSearchModel.MatchedResult matchedResult3 : arrayList2) {
arrayList4.add(matchedResult3.getValue());
}
List plus = u.plus((Collection) listOf, (Iterable) arrayList4);
ArrayList arrayList5 = new ArrayList(d0.t.o.collectionSizeOrDefault(arrayList3, 10));
for (WidgetGlobalSearchModel.MatchedResult matchedResult4 : arrayList3) {
arrayList5.add(matchedResult4.getValue());
}
return new WidgetGlobalSearchModel.ItemUser(matchedResult2, user, u.distinct(u.plus((Collection) plus, (Iterable) arrayList5)), z2, (Presence) a.d(user, this.$usersContext.getPresences()), channel, (channel == null || (num = (Integer) a.c(channel, this.$searchContext.getMentionCounts())) == null) ? 0 : num.intValue(), channel != null ? this.$channelContext.getUnreadChannelIds().contains(Long.valueOf(channel.h())) : false);
}
}