Skip to content

Commit

Permalink
Updated to v0.27-b4.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Feb 19, 2025
2 parents 7b63d60 + c07f3b0 commit fa37a72
Show file tree
Hide file tree
Showing 22 changed files with 453 additions and 51 deletions.
4 changes: 4 additions & 0 deletions src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ public void defineSettings() {
settings.addBoolean("rulesAutoShow", true);
settings.addList("rulesShown", new HashSet(), Setting.STRING);

// Shared Chat
settings.addLong("sharedBadges", 1);
settings.addLong("sharedLogoSize", 22);

//===============
// Other Features
//===============
Expand Down
31 changes: 30 additions & 1 deletion src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -1982,6 +1983,8 @@ else if (command.equals("bantest")) {
c.simulate(raw);
}
return;
} else if (parameter.startsWith("file ")) {
RawMessageTest.simulateFile(c, parameter.substring("file ".length()));
}
String raw = RawMessageTest.simulateIRC(channel, parameter, c.getUsername());
if (raw != null) {
Expand Down Expand Up @@ -2692,7 +2695,7 @@ else if (message.data instanceof LowTrustUserUpdateData) {
null));

User targetUser = c.getUser(channel, data.targetUsername);
targetUser.addInfo("", data.makeInfo());
targetUser.addInfo("", data.makeInfo(), false, null);
g.updateUserinfo(targetUser);
}
}
Expand Down Expand Up @@ -3086,6 +3089,32 @@ public void updateStreamChatLogos(Collection<String> joiningChannels) {
}
});
}

public void resolveSourceData(User user, MsgTags tags, Consumer<MsgTags> resultListener) {
if (!tags.isSharedMessage()) {
resultListener.accept(tags);
}
else {
String sourceRoomId = tags.get("source-room-id");
api.getCachedUserInfoById(Arrays.asList(new String[]{sourceRoomId}), requestResult -> {
UserInfo info = requestResult.get(sourceRoomId);
if (info != null) {
if (!StringUtil.isNullOrEmpty(info.profileImageUrl)) {
usericonManager.addChannelLogoUrl(Helper.toChannel(info.login), info.profileImageUrl);
}
resultListener.accept(MsgTags.addTag(tags, MsgTags.SHARED_MESSAGE_SOURCE_CHANNEL, Helper.toChannel(info.login)));
}
else {
/**
* In case of error just output message, in which case
* channel icon and name will be missing, but there will
* still be some indication that it's a shared message.
*/
resultListener.accept(tags);
}
});
}
}

private class MyStreamInfoListener implements StreamInfoListener {

Expand Down
4 changes: 4 additions & 0 deletions src/chatty/TwitchConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,10 @@ void onUsernotice(String channel, String message, MsgTags tags) {
if (!onChannel(channel)) {
return;
}
if (tags.isValue("msg-id", "sharedchatnotice")) {
// Overwrite msg-id with original msg-id, so it can be handled properly here
tags = MsgTags.addTag(tags, "msg-id", tags.get("source-msg-id"));
}
String login = tags.get("login");
String text = StringUtil.removeLinebreakCharacters(tags.get("system-msg"));
int months = tags.getInteger("msg-param-cumulative-months", -1);
Expand Down
91 changes: 84 additions & 7 deletions src/chatty/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public synchronized boolean maxLinesExceeded() {
}

public synchronized void addMessage(String line, boolean action, String id) {
addMessage(line, action, id, System.currentTimeMillis());
addMessage(line, action, id, null, null, System.currentTimeMillis());
}

/**
Expand All @@ -341,14 +341,21 @@ public synchronized void addMessage(String line, boolean action, String id) {
* @param line
* @param action
* @param id
* @param sourceId
* @param sourceChannel
* @param timestamp
*/
public synchronized void addMessage(String line, boolean action, String id, long timestamp) {
public synchronized void addMessage(String line, boolean action, String id, String sourceId, String sourceChannel, long timestamp) {
if (timestamp == -1) {
timestamp = System.currentTimeMillis();
}
setFirstSeen();
addLine(new TextMessage(timestamp, line, action, id, null));
if (sourceId != null && !sourceId.equals(id)) {
addLine(new SharedTextMessage(timestamp, line, action, id, sourceId, sourceChannel, null));
}
else {
addLine(new TextMessage(timestamp, line, action, id, null));
}
replayCachedLowTrust();
numberOfMessages++;
}
Expand Down Expand Up @@ -380,14 +387,24 @@ public synchronized void addMsgDeleted(String targetMsgId, String msg) {
replayCachedBanInfo();
}

public synchronized void addSub(String message, String text, String id) {
public synchronized void addSub(String message, String text, String id, String sourceId, String sourceChannel) {
setFirstSeen();
addLine(new SubMessage(System.currentTimeMillis(), message, text, id));
if (sourceId != null && !sourceId.equals(id)) {
addLine(new SharedSubMessage(System.currentTimeMillis(), message, text, id, sourceId, sourceChannel));
}
else {
addLine(new SubMessage(System.currentTimeMillis(), message, text, id));
}
}

public synchronized void addInfo(String message, String fullText) {
public synchronized void addInfo(String message, String fullText, boolean isShared, String sourceChannel) {
setFirstSeen();
addLine(new InfoMessage(System.currentTimeMillis(), message, fullText));
if (isShared) {
addLine(new SharedInfoMessage(System.currentTimeMillis(), message, fullText, sourceChannel));
}
else {
addLine(new InfoMessage(System.currentTimeMillis(), message, fullText));
}
}

public synchronized void addWarning(String reason, String by) {
Expand Down Expand Up @@ -1311,6 +1328,29 @@ public TextMessage addLowTrust(LowTrustUserMessageData data) {

}

public static class SharedTextMessage extends TextMessage implements SharedMessage {

public final String sourceId;
public final String sourceChannel;

public SharedTextMessage(long time, String message, boolean action, String id, String sourceId, String sourceChannel, LowTrustUserMessageData lowTrust) {
super(time, message, action, id, lowTrust);
this.sourceId = sourceId;
this.sourceChannel = sourceChannel;
}

@Override
public TextMessage addLowTrust(LowTrustUserMessageData data) {
return new SharedTextMessage(getTime(), text, action, id, sourceId, sourceChannel, data);
}

@Override
public String getSourceChannel() {
return sourceChannel;
}

}

public static class BanMessage extends Message {

public final long duration;
Expand Down Expand Up @@ -1394,6 +1434,24 @@ public SubMessage(long time, String message, String text, String id) {
}
}

public static class SharedSubMessage extends SubMessage implements SharedMessage {

public final String sourceId;
public final String sourceChannel;

public SharedSubMessage(long time, String message, String text, String id, String sourceId, String sourceChannel) {
super(time, message, text, id);
this.sourceId = sourceId;
this.sourceChannel = sourceChannel;
}

@Override
public String getSourceChannel() {
return sourceChannel;
}

}

public static class InfoMessage extends Message {

/**
Expand All @@ -1415,6 +1473,21 @@ public InfoMessage(long time, String message, String full_text) {
}
}

public static class SharedInfoMessage extends InfoMessage implements SharedMessage {

public final String sourceChannel;

public SharedInfoMessage(long time, String message, String full_text, String sourceChannel) {
super(time, message, full_text);
this.sourceChannel = sourceChannel;
}

@Override
public String getSourceChannel() {
return sourceChannel;
}
}

public static class ModAction extends Message {

/**
Expand Down Expand Up @@ -1464,6 +1537,10 @@ public AutoModMessage(String message, String id, String reason) {

}

public static interface SharedMessage {
public String getSourceChannel();
}

// public static final void main(String[] args) {
// ArrayList<User> list = new ArrayList<>();
// for (int i=0;i<100000;i++) {
Expand Down
11 changes: 11 additions & 0 deletions src/chatty/gui/Highlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,17 @@ else if (part.startsWith("afterban")) {
return msgs != -1 && msgs < matchNumber;
});
}
else if (part.startsWith("shared")) {
String[] split = part.split("\\|");
Set<String> sourceChans = new HashSet<>();
for (int i=1;i<split.length;i++) {
sourceChans.add(Helper.toChannel(split[i]));
}
addTagsItem("Shared Message", sourceChans, t -> {
return t.isSharedMessage()
&& (sourceChans.isEmpty() || sourceChans.contains(t.getSourceChannel()));
});
}
});
parseBadges(list);
parseTags(list);
Expand Down
Loading

0 comments on commit fa37a72

Please sign in to comment.