Skip to content

Commit

Permalink
Updated to v0.13-b3.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Aug 28, 2020
2 parents 92c01f6 + e3a3b1c commit 7d5f5fb
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 46 deletions.
22 changes: 20 additions & 2 deletions src/chatty/TwitchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,14 @@ private void sendMessage(String channel, String text, boolean allowCommandMessag
}
}

/**
* Check if the message should be sent as a reply.
*
* @param channel The channel to send the message to (not null)
* @param text The text to send (not null)
* @return true if the message was handled by this method, false if it
* should be sent normally
*/
private boolean sendAsReply(String channel, String text) {
boolean restricted = settings.getBoolean("mentionReplyRestricted");
boolean doubleAt = text.startsWith("@@");
Expand All @@ -888,7 +896,8 @@ private boolean sendAsReply(String channel, String text) {
if (result.action != SelectReplyMessageResult.Action.SEND_NORMALLY) {
// Should not send normally, so return true
if (result.action == SelectReplyMessageResult.Action.REPLY) {
sendReply(channel, actualMsg, username, result.atMsgId, null);
// If changed to parent msg-id, atMsg will be null
sendReply(channel, actualMsg, username, result.atMsgId, result.atMsg);
}
return true;
}
Expand All @@ -898,6 +907,15 @@ private boolean sendAsReply(String channel, String text) {
return false;
}

/**
* Send a reply.
*
* @param channel The channel to send to (not null)
* @param text The text to send (not null)
* @param atUsername The username to address (not null)
* @param atMsgId The msg-id to use as reply thread parent (not null)
* @param atMsg The parent msg text (may be null)
*/
private void sendReply(String channel, String text, String atUsername, String atMsgId, String atMsg) {
MsgTags tags = MsgTags.create("reply-parent-msg-id", atMsgId);
if (c.sendSpamProtectedMessage(channel, text, false, tags)) {
Expand Down Expand Up @@ -2950,7 +2968,7 @@ public void onChannelMessage(User user, String text, boolean action, MsgTags tag
}
else {
g.printMessage(user, text, action, tags);
if (tags.isReply() && tags.hasReplyUserMsg()) {
if (tags.isReply() && tags.hasReplyUserMsg() && tags.hasId()) {
ReplyManager.addReply(tags.getReplyParentMsgId(), tags.getId(), String.format("<%s> %s", user.getName(), text), tags.getReplyUserMsg());
}
if (!action) {
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/TwitchConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ public void onChannelCommand(MsgTags tags, String nick,
if (tags.containsKey("followers-only")) {
channelStates.setFollowersOnly(channel, tags.get("followers-only"));
}
if (!tags.isEmpty("room-id")) {
if (tags.hasValue("room-id")) {
listener.onRoomId(channel, tags.get("room-id"));
if (Helper.isRegularChannel(channel)) {
// Set id for room (this should not run too often to
Expand Down
18 changes: 14 additions & 4 deletions src/chatty/gui/components/SelectReplyMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ else if (action == Action.CTRL_ENTER) {
private void confirm() {
User.TextMessage selected = list.getSelectedValue();
if (selected != null) {
result = new SelectReplyMessageResult(selected.id);
result = new SelectReplyMessageResult(selected.id, selected.text);
if (continueThread.isSelected()) {
String parentMsgId = ReplyManager.getParentMsgId(selected.id);
if (parentMsgId != null) {
result = new SelectReplyMessageResult(parentMsgId);
// Overwrite result with parent msg-id if available
// Msg should be null for this, since the selected.text
// isn't the parent text
result = new SelectReplyMessageResult(parentMsgId, null);
}
}
}
Expand All @@ -177,9 +180,10 @@ private void confirm() {
public SelectReplyMessageResult select() {
if (list.getModel().getSize() == 0) {
// No messages available, so immediatelly return
return null;
return SEND_NORMALLY_RESULT;
}
list.setSelectedIndex(list.getModel().getSize() - 1);
list.ensureIndexIsVisible(list.getSelectedIndex());
setLocationRelativeTo(getParent());
setVisible(true);
return result;
Expand All @@ -194,15 +198,18 @@ public enum Action {
}

public final String atMsgId;
public final String atMsg;
public final Action action;

public SelectReplyMessageResult(String atMsgId) {
public SelectReplyMessageResult(String atMsgId, String atMsg) {
this.atMsgId = atMsgId;
this.atMsg = atMsg;
this.action = Action.REPLY;
}

public SelectReplyMessageResult(Action action) {
this.atMsgId = null;
this.atMsg = null;
this.action = action;
}

Expand All @@ -213,6 +220,9 @@ public static void main(String[] args) {
user.addMessage("abc", true, "1");
user.addMessage("abc2", true, "2");
user.addMessage("abc2", true, null);
for (int i=0;i<30;i++) {
user.addMessage("blah"+i, false, i+"msg-id");
}
System.out.println(SelectReplyMessage.show(user));
System.exit(0);
}
Expand Down
4 changes: 4 additions & 0 deletions src/chatty/gui/components/help/help-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,10 @@ <h3>Channels</h3>
<li><strong>off</strong> - Log no channels whatsoever</li>
</ul>

<p><em>Tip:</em> Add <code>$_whisper_</code> to the whitelist or blacklist
to affect all whispers that are output in the "One Window" tab or
"Per User" tabs.</p>

<h3>Other Settings</h3>
<dl class="dl-settings">
<dt>Folder</dt>
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/help/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1><a name="top">Chatty (Version: 0.13-b2)</a></h1>
<h1><a name="top">Chatty (Version: 0.13-b3)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down
3 changes: 2 additions & 1 deletion src/chatty/gui/components/settings/LogSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ private static class ChannelFormatter implements DataFormatter<String> {
*/
@Override
public String format(String input) {
if (input != null && !input.isEmpty() && !input.startsWith("#")) {
if (input != null && !input.isEmpty() && !input.startsWith("#")
&& !input.startsWith("$")) {
input = "#"+input;
}
if (input.length() == 1) {
Expand Down
35 changes: 11 additions & 24 deletions src/chatty/gui/components/textpane/FixSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import javax.swing.text.JTextComponent;

/**
* Move the dot/mark (selection or not) when text is added/removed, so it stays
* on the same content.
*
*
* @author tduva
*/
public class FixSelection implements DocumentListener {
Expand Down Expand Up @@ -38,27 +36,16 @@ public void changedUpdate(DocumentEvent e) {
}

private void fix(DocumentEvent e) {
int dot = c.getCaret().getDot();
int mark = c.getCaret().getMark();

int change = 0;
if (e.getType() == DocumentEvent.EventType.INSERT) {
change = e.getLength();
}
else if (e.getType() == DocumentEvent.EventType.REMOVE) {
change = -e.getLength();
}

// Check separately, something may be changed within the selection
if (dot > e.getOffset()) {
dot = dot + change;
}
if (mark > e.getOffset()) {
mark = mark + change;
}
c.getCaret().setDot(mark);
if (mark != dot) {
c.getCaret().moveDot(dot);
int start = c.getSelectionStart();
int end = c.getSelectionEnd();
if (start != end && start > e.getOffset()) {
if (e.getType() == DocumentEvent.EventType.INSERT) {
c.setSelectionStart(start + e.getLength());
c.setSelectionEnd(end + e.getLength());
} else if (e.getType() == DocumentEvent.EventType.REMOVE) {
c.setSelectionStart(start - e.getLength());
c.setSelectionEnd(end - e.getLength());
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/chatty/gui/components/textpane/LinkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,14 @@ private static void makeReplacementPopupText(String replacedText, MyPopup p) {
private static void makeReplyPopupText(String replyMsgId, MyPopup p) {
List<Reply> replies = ReplyManager.getReplies(replyMsgId);
StringBuilder b = new StringBuilder();
for (Reply reply : replies) {
b.append(StringUtil.addLinebreaks(Helper.htmlspecialchars_encode(reply.userMsg), 70, true));
b.append("<br />");
if (replies != null) {
for (Reply reply : replies) {
b.append(StringUtil.addLinebreaks(Helper.htmlspecialchars_encode(reply.userMsg), 70, true));
b.append("<br />");
}
}
else {
b.append("No reply data found (may have expired).");
}
p.setText(String.format("%sThread:<div style='text-align:left;font-weight:normal'>%s</div>",
POPUP_HTML_PREFIX, b.toString()));
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/util/ReplyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
public class ReplyManager {

private static final long DELETE_TIME = TimeUnit.HOURS.toMillis(4);
private static final long DELETE_TIME = TimeUnit.HOURS.toMillis(12);
// private static final long DELETE_TIME = TimeUnit.MINUTES.toMillis(2);

private static final Map<String, List<Reply>> data = new HashMap<>();
Expand Down
20 changes: 15 additions & 5 deletions src/chatty/util/chatlog/ChatLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,24 @@ private boolean isChanEnabled(String channel) {
if (mode.equals("off")) {
return false;
}
if (mode.equals("always")) {
else if (mode.equals("always")) {
return true;
}
if (mode.equals("blacklist") && !settings.listContains("logBlacklist", channel)) {
return true;
else if (mode.equals("blacklist")) {
if (!settings.listContains("logBlacklist", channel)) {
return true;
}
if (channel.startsWith("$") && !settings.listContains("logBlacklist", "$_whisper_")) {
return true;
}
}
if (mode.equals("whitelist") && settings.listContains("logWhitelist", channel)) {
return true;
else if (mode.equals("whitelist")) {
if (settings.listContains("logWhitelist", channel)) {
return true;
}
if (channel.startsWith("$") && settings.listContains("logWhitelist", "$_whisper_")) {
return true;
}
}
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/chatty/util/irc/IrcMsgTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public boolean isValueOf(String key, String... values) {
return false;
}

public boolean isEmpty(String key) {
return !tags.containsKey(key) || tags.get(key).isEmpty();
public boolean hasValue(String key) {
String value = tags.get(key);
return value != null && !value.isEmpty();
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/chatty/util/irc/MsgTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public String getId() {
return get("id");
}

public boolean hasId() {
return hasValue("id");
}

public int getBits() {
return getInteger("bits", 0);
}
Expand All @@ -46,7 +50,7 @@ public boolean isFromPubSub() {
}

public boolean hasReplyUserMsg() {
return containsKey("reply-parent-msg-body") && containsKey("reply-parent-display-name");
return hasValue("reply-parent-msg-body") && hasValue("reply-parent-display-name");
}

public String getReplyUserMsg() {
Expand All @@ -59,7 +63,7 @@ public String getReplyUserMsg() {
}

public boolean isReply() {
return containsKey("reply-parent-msg-id");
return hasValue("reply-parent-msg-id");
}

public String getReplyParentMsgId() {
Expand Down

0 comments on commit 7d5f5fb

Please sign in to comment.