Skip to content

Commit 7438b65

Browse files
committed
Labeled messages
1 parent 37a7b48 commit 7438b65

File tree

7 files changed

+195
-3
lines changed

7 files changed

+195
-3
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* * Copyright (C) 2013-2021 Matt Baxter https://kitteh.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies
9+
* of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kitteh.irc.client.library.defaults.element.messagetag;
25+
26+
import org.checkerframework.checker.nullness.qual.NonNull;
27+
import org.kitteh.irc.client.library.Client;
28+
import org.kitteh.irc.client.library.element.MessageTag;
29+
import org.kitteh.irc.client.library.feature.MessageTagManager;
30+
import org.kitteh.irc.client.library.util.TriFunction;
31+
32+
import java.util.Objects;
33+
34+
/**
35+
* Default implementation of {@link Label}.
36+
*/
37+
public class DefaultMessageTagLabel extends MessageTagManager.DefaultMessageTag implements MessageTag.Label {
38+
/**
39+
* Function to create this message tag.
40+
*/
41+
@SuppressWarnings("ConstantConditions")
42+
public static final TriFunction<Client, String, String, DefaultMessageTagLabel> FUNCTION = (client, name, value) -> new DefaultMessageTagLabel(name, value);
43+
44+
private final String label;
45+
46+
private DefaultMessageTagLabel(@NonNull String name, @NonNull String value) {
47+
super(name, value);
48+
this.label = value;
49+
}
50+
51+
@Override
52+
public @NonNull String getLabel() {
53+
return this.label;
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
return o instanceof Label && this.label.equals(((Label) o).getLabel());
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
return Objects.hash("Label", this.label);
64+
}
65+
}

src/main/java/org/kitteh/irc/client/library/defaults/feature/DefaultMessageTagManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.checkerframework.checker.nullness.qual.NonNull;
2727
import org.checkerframework.checker.nullness.qual.Nullable;
2828
import org.kitteh.irc.client.library.Client;
29+
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagLabel;
2930
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagMsgId;
3031
import org.kitteh.irc.client.library.defaults.element.messagetag.DefaultMessageTagTime;
3132
import org.kitteh.irc.client.library.element.MessageTag;
@@ -84,6 +85,7 @@ public DefaultMessageTagManager(Client.WithManagement client) {
8485
super(client);
8586
this.registerTagCreator(CapabilityManager.Defaults.SERVER_TIME, "time", DefaultMessageTagTime.FUNCTION);
8687
this.registerTagCreator(CapabilityManager.Defaults.MESSAGE_TAGS, "msgid", DefaultMessageTagMsgId.FUNCTION);
88+
this.registerTagCreator(CapabilityManager.Defaults.LABELED_RESPONSE, "label", DefaultMessageTagLabel.FUNCTION);
8789
}
8890

8991
@Override
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* * Copyright (C) 2013-2021 Matt Baxter https://kitteh.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies
9+
* of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kitteh.irc.client.library.defaults.listener;
25+
26+
import net.engio.mbassy.listener.Handler;
27+
import org.checkerframework.checker.nullness.qual.NonNull;
28+
import org.kitteh.irc.client.library.Client;
29+
import org.kitteh.irc.client.library.event.client.AckEvent;
30+
import org.kitteh.irc.client.library.event.client.ClientReceiveCommandEvent;
31+
import org.kitteh.irc.client.library.feature.filter.CommandFilter;
32+
33+
/**
34+
* Default ACK listener, producing events using default classes.
35+
*/
36+
public class DefaultAckListener extends AbstractDefaultListenerBase {
37+
/**
38+
* Constructs the listener.
39+
*
40+
* @param client client
41+
*/
42+
public DefaultAckListener(Client.@NonNull WithManagement client) {
43+
super(client);
44+
}
45+
46+
@CommandFilter("ACK")
47+
@Handler(priority = Integer.MAX_VALUE - 1)
48+
public void ack(ClientReceiveCommandEvent event) {
49+
this.fire(new AckEvent(this.getClient(), event.getSource()));
50+
}
51+
}

src/main/java/org/kitteh/irc/client/library/defaults/listener/DefaultListeners.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public enum DefaultListeners implements EventListenerSupplier {
3939
* @see DefaultAccountListener
4040
*/
4141
ACCOUNT(DefaultAccountListener::new),
42+
/**
43+
* ACK handling.
44+
*
45+
* @see DefaultAckListener
46+
*/
47+
ACK(DefaultAckListener::new),
4248
/**
4349
* AWAY handling.
4450
*

src/main/java/org/kitteh/irc/client/library/element/MessageTag.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,27 @@
3232
* Reflects a message tag.
3333
*/
3434
public interface MessageTag {
35+
/**
36+
* Represents the `label` tag as specified by the labeled responses spec.
37+
*/
38+
interface Label extends MessageTag {
39+
/**
40+
* Gets the label.
41+
*
42+
* @return the label
43+
*/
44+
@NonNull String getLabel();
45+
}
46+
3547
/**
3648
* Represents the `msgid` tag as specified by the Message IDs spec.
3749
*/
3850
interface MsgId extends MessageTag {
51+
/**
52+
* Gets the message id.
53+
*
54+
* @return the message id
55+
*/
3956
@NonNull String getId();
4057
}
4158

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* * Copyright (C) 2013-2021 Matt Baxter https://kitteh.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies
9+
* of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kitteh.irc.client.library.event.client;
25+
26+
import org.checkerframework.checker.nullness.qual.NonNull;
27+
import org.kitteh.irc.client.library.Client;
28+
import org.kitteh.irc.client.library.element.ServerMessage;
29+
import org.kitteh.irc.client.library.event.abstractbase.ServerMessageEventBase;
30+
31+
/**
32+
* An ACK has been received, which should have a label attached to correspond
33+
* with a previously sent message.
34+
*/
35+
public class AckEvent extends ServerMessageEventBase {
36+
/**
37+
* Constructs the event.
38+
*
39+
* @param client the client
40+
* @param sourceMessage source message
41+
*/
42+
public AckEvent(@NonNull Client client, @NonNull ServerMessage sourceMessage) {
43+
super(client, sourceMessage);
44+
}
45+
}

src/main/java/org/kitteh/irc/client/library/feature/CapabilityManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,17 @@ final class Defaults {
112112
*/
113113
public static final transient String INVITE_NOTIFY = "invite-notify";
114114

115+
/**
116+
* Labeled responses, which also requires the {@link #BATCH}
117+
* capability to function, via a "label" message id.
118+
*/
119+
public static final String LABELED_RESPONSE = "labeled-response";
120+
115121
/**
116122
* Message tags support, explicitly stating that client-only tags are
117-
* supported, but not a necessary capability for actually supporting
118-
* tags through other capabilities like account-tag, batch, or
119-
* server-time.
123+
* supported, required for msgid tag but not a necessary capability
124+
* for actually supporting tags through other capabilities like
125+
* account-tag, batch, or server-time.
120126
*/
121127
public static final String MESSAGE_TAGS = "message-tags";
122128

0 commit comments

Comments
 (0)