discord-jadx/app/src/main/java/com/discord/utilities/textprocessing/TagsBuilder.java

106 lines
3.5 KiB
Java

package com.discord.utilities.textprocessing;
import c.a.t.b.c.a;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.simpleast.core.node.Node;
import com.discord.utilities.textprocessing.node.ChannelMentionNode;
import com.discord.utilities.textprocessing.node.RoleMentionNode;
import com.discord.utilities.textprocessing.node.UserMentionNode;
import d0.z.d.m;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: TagsBuilder.kt */
public final class TagsBuilder implements a {
public static final Companion Companion = new Companion(null);
private Set<Long> taggedChannelIds;
private Set<Long> taggedRoleIds;
private Set<Long> taggedUserIds;
/* compiled from: TagsBuilder.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final Tags extractTags(Collection<? extends Node<?>> collection) {
m.checkNotNullParameter(collection, "ast");
TagsBuilder tagsBuilder = new TagsBuilder();
tagsBuilder.processAst(collection);
return tagsBuilder.build();
}
}
private final void addChannel(long j) {
Set<Long> set = this.taggedChannelIds;
if (set == null) {
set = new HashSet<>(4);
}
set.add(Long.valueOf(j));
this.taggedChannelIds = set;
}
private final void addRole(long j) {
Set<Long> set = this.taggedRoleIds;
if (set == null) {
set = new HashSet<>(4);
}
set.add(Long.valueOf(j));
this.taggedRoleIds = set;
}
private final void addUser(long j) {
Set<Long> set = this.taggedUserIds;
if (set == null) {
set = new HashSet<>(4);
}
set.add(Long.valueOf(j));
this.taggedUserIds = set;
}
public final Tags build() {
Set<Long> set = this.taggedUserIds;
if (set == null) {
set = Collections.emptySet();
m.checkNotNullExpressionValue(set, "Collections.emptySet()");
}
Set<Long> set2 = this.taggedChannelIds;
if (set2 == null) {
set2 = Collections.emptySet();
m.checkNotNullExpressionValue(set2, "Collections.emptySet()");
}
Set<Long> set3 = this.taggedRoleIds;
if (set3 == null) {
set3 = Collections.emptySet();
m.checkNotNullExpressionValue(set3, "Collections.emptySet()");
}
return new Tags(set, set2, set3);
}
public final void processAst(Collection<? extends Node<?>> collection) {
m.checkNotNullParameter(collection, "ast");
AnimatableValueParser.K2(collection, this);
}
@Override // c.a.t.b.c.a
public void processNode(Node<?> node) {
if (node instanceof UserMentionNode) {
UserMentionNode userMentionNode = (UserMentionNode) node;
if (userMentionNode.getType() == UserMentionNode.Type.USER) {
addUser(userMentionNode.getUserId());
return;
}
}
if (node instanceof RoleMentionNode) {
addRole(((RoleMentionNode) node).getRoleId());
} else if (node instanceof ChannelMentionNode) {
addChannel(((ChannelMentionNode) node).getChannelId());
}
}
}