Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion genmonke
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mv tv.twitch.android.util.EmoteUrlUtil.smali.patch emotes/.
mv tv.twitch.android.shared.ui.elements.span.GlideChatImageTarget.smali.patch emotes/.
mv tv.twitch.android.shared.ui.elements.span.GlideChatImageCustomTarget.smali.patch emotes/.
mv tv.twitch.android.shared.emotes.utils.AnimatedEmotesUrlUtil.smali.patch emotes/.
mv tv.twitch.android.sdk.ChatController.smali.patch emotes/.
mv tv.twitch.android.shared.chat.ChatController.smali.patch emotes/.
mv tv.twitch.android.shared.chomments.impl.ChommentsFetcherImpl.smali.patch emotes/.
mv tv.twitch.android.shared.chat.ChatMessageDelegate.smali.patch emotes/.
mv tv.twitch.android.shared.chat.messagefactory.* emotes/.
Expand Down
1 change: 1 addition & 0 deletions mod/app/src/main/java/bttv/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void setCurrentBroadcasterName(CharSequence name) {
Data.currentBroadcasterName = name.toString();
}

/** @noinspection unused */
public static void setCurrentBroadcasterId(ChannelModel channel) {
setCurrentBroadcasterId(channel.component1());
}
Expand Down
122 changes: 0 additions & 122 deletions mod/app/src/main/java/bttv/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
import tv.twitch.android.shared.chat.pub.model.messages.MessageToken.EmoticonToken;
import tv.twitch.android.shared.chat.pub.messages.ui.ChatMessageInterface;
import tv.twitch.android.shared.chat.ChatMessageDelegate;
import tv.twitch.chat.AutoModFlags;
import tv.twitch.chat.ChatEmoticonToken;
import tv.twitch.chat.ChatMessageToken;
import tv.twitch.chat.ChatMessageTokenType;
import tv.twitch.chat.ChatTextToken;
import tv.twitch.chat.library.model.ChatMessageInfo;

public class Tokenizer {
Expand Down Expand Up @@ -107,95 +102,6 @@ public static void retokenizeLiveChatMessage(ChatMessageInterface chatMessageInt
}
}

/** @noinspection unused */
public static void retokenizeLiveChatMessage(tv.twitch.chat.ChatMessageInfo info) {
try {
Context ctx = Data.ctx;
int channel = Data.currentBroadcasterId;

ArrayList<tv.twitch.chat.ChatMessageToken> newTokens = new ArrayList<>(info.tokens.length + 10);

boolean shouldHighlight = false;
boolean shouldBlock = false;

for (tv.twitch.chat.ChatMessageToken token : info.tokens) {
Log.d("LBTTV", "retokenizeLiveChatMessage: " + token);
if (!isTextTokenOld(token)) {
if (isEmoteTokenOld(token) && !newTokens.isEmpty()) {
tv.twitch.chat.ChatMessageToken prevToken = newTokens.get(newTokens.size() - 1);
if (prevToken != null && !endsWithSpaceOld(prevToken)) {
ChatTextToken spaceToken = new ChatTextToken();
spaceToken.text = " ";
spaceToken.autoModFlags = new AutoModFlags();
newTokens.add(spaceToken);
}
}
newTokens.add(token);
continue;
}

ChatTextToken textToken = (ChatTextToken) token;
String text = textToken.text;

if (text.equals(" ")) {
// " ".split(" ") will produce an empty array
// this is why we need to handle this edge-case
newTokens.add(textToken);
continue;
}
String[] tokens = text.split(" ");

StringBuilder currentText = new StringBuilder();
for (String word : tokens) {
if (Blacklist.shouldBlock(word)) {
shouldBlock = true;
}
if (Highlight.shouldHighlight(word)) {
shouldHighlight = true;
}
Emote emote = Emotes.getEmote(ctx, word, channel);
if (emote == null) {
currentText.append(word).append(" ");
continue;
}
// emote found
String before = currentText.toString();
if (!before.isEmpty()) {
ChatTextToken everythingBeforeEmote = new ChatTextToken();
everythingBeforeEmote.text = before;
everythingBeforeEmote.autoModFlags = textToken.autoModFlags;
newTokens.add(everythingBeforeEmote);
}
ChatEmoticonToken emoteToken = new ChatEmoticonToken();
emoteToken.emoticonText = word;
emoteToken.emoticonId = "BTTV-" + emote.id;
newTokens.add(emoteToken);

// prepare next TextToken
currentText.setLength(0);
currentText.append(' ');
}
String before = currentText.toString();
if (!before.trim().isEmpty()) {
ChatTextToken everything = new ChatTextToken();
everything.text = before;
everything.autoModFlags = textToken.autoModFlags;
newTokens.add(everything);
}
}

info.tokens = newTokens.toArray(new ChatMessageToken[0]);

if (shouldBlock) {
info.messageType = "bttv-blocked-message";
} else if (shouldHighlight) {
info.messageType = "bttv-highlighted-message";
}
} catch (Throwable throwable) {
Log.e("LBTTV", "retokenizeLiveChatMessage: " + throwable.getMessage());
}
}

public static void retokenizeLiveChatMessage(ChatMessageInfo info) {
Context ctx = Data.ctx;
int channel = Data.currentBroadcasterId;
Expand Down Expand Up @@ -290,45 +196,17 @@ private static boolean endsWithSpace(@NotNull tv.twitch.chat.library.model.Messa
return lastChar == ' ';
}

private static boolean endsWithSpaceOld(@NotNull tv.twitch.chat.ChatMessageToken token) {
if (token.type.getValue() != ChatMessageTokenType.Text.getValue()) {
return false;
}
ChatTextToken textToken = (ChatTextToken) token;
String text = textToken.text;
if (text.isEmpty()) {
return false;
}
char lastChar = text.charAt(text.length() - 1);
return lastChar == ' ';
}

private static boolean isTextToken(tv.twitch.chat.library.model.MessageToken token) {
if (token == null) {
return false;
}
return token instanceof tv.twitch.chat.library.model.MessageToken.TextToken;
}

private static boolean isTextTokenOld(tv.twitch.chat.ChatMessageToken token) {
if (token == null) {
return false;
}
return token.type.getValue() == ChatMessageTokenType.Text.getValue();
}


private static boolean isEmoteToken(tv.twitch.chat.library.model.MessageToken token) {
if (token == null) {
return false;
}
return token instanceof tv.twitch.chat.library.model.MessageToken.EmoteToken;
}

private static boolean isEmoteTokenOld(tv.twitch.chat.ChatMessageToken token) {
if (token == null) {
return false;
}
return token.type.getValue() == ChatMessageTokenType.Emoticon.getValue();
}
}
6 changes: 0 additions & 6 deletions mod/app/src/test/java/bttv/mod/RetokenizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
import bttv.Tokenizer;
import bttv.emote.Emote;
import bttv.emote.Emotes;
import tv.twitch.chat.ChatEmoticonToken;
import tv.twitch.chat.ChatMentionToken;
import tv.twitch.chat.library.model.ChatMessageInfo;
import tv.twitch.chat.ChatMessageToken;
import tv.twitch.chat.ChatMessageTokenType;
import tv.twitch.chat.ChatTextToken;
import tv.twitch.chat.ChatUrlToken;
import tv.twitch.chat.library.model.MessageToken;

import static org.junit.Assert.assertEquals;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions mod/twitch/src/main/java/tv/twitch/chat/AutoModFlags.java

This file was deleted.

10 changes: 0 additions & 10 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatEmoticonToken.java

This file was deleted.

7 changes: 0 additions & 7 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatMentionToken.java

This file was deleted.

6 changes: 0 additions & 6 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatMessageInfo.java

This file was deleted.

5 changes: 0 additions & 5 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatMessageToken.java

This file was deleted.

37 changes: 0 additions & 37 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatMessageTokenType.java

This file was deleted.

11 changes: 0 additions & 11 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatTextToken.java

This file was deleted.

7 changes: 0 additions & 7 deletions mod/twitch/src/main/java/tv/twitch/chat/ChatUrlToken.java

This file was deleted.

This file was deleted.

This file was deleted.

Loading