Browse Source

Switch from `time` to `metadata`, store batch ID

tags/v0.9.0
Chris Smith 5 years ago
parent
commit
c40ebf68c0
50 changed files with 334 additions and 273 deletions
  1. 3
    0
      CHANGELOG
  2. 1
    1
      build.gradle.kts
  3. 4
    5
      src/main/kotlin/com/dmdirc/ktirc/IrcClientImpl.kt
  4. 57
    36
      src/main/kotlin/com/dmdirc/ktirc/events/Events.kt
  5. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/events/handlers/ChannelStateHandler.kt
  6. 2
    2
      src/main/kotlin/com/dmdirc/ktirc/events/mutators/ChannelFanOutMutator.kt
  7. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/events/mutators/ServerReadyMutator.kt
  8. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/AccountProcessor.kt
  9. 4
    4
      src/main/kotlin/com/dmdirc/ktirc/messages/AuthenticationProcessor.kt
  10. 14
    0
      src/main/kotlin/com/dmdirc/ktirc/messages/BatchProcessor.kt
  11. 6
    6
      src/main/kotlin/com/dmdirc/ktirc/messages/CapabilityProcessor.kt
  12. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/ISupportProcessor.kt
  13. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/JoinProcessor.kt
  14. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/KickProcessor.kt
  15. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/ModeProcessor.kt
  16. 4
    4
      src/main/kotlin/com/dmdirc/ktirc/messages/MotdProcessor.kt
  17. 2
    2
      src/main/kotlin/com/dmdirc/ktirc/messages/NamesProcessor.kt
  18. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/NickProcessor.kt
  19. 2
    2
      src/main/kotlin/com/dmdirc/ktirc/messages/NoticeProcessor.kt
  20. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/PartProcessor.kt
  21. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/PingProcessor.kt
  22. 3
    3
      src/main/kotlin/com/dmdirc/ktirc/messages/PrivmsgProcessor.kt
  23. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/QuitProcessor.kt
  24. 4
    4
      src/main/kotlin/com/dmdirc/ktirc/messages/TopicProcessor.kt
  25. 1
    1
      src/main/kotlin/com/dmdirc/ktirc/messages/WelcomeProcessor.kt
  26. 3
    0
      src/main/kotlin/com/dmdirc/ktirc/model/CapabilitiesState.kt
  27. 21
    6
      src/main/kotlin/com/dmdirc/ktirc/model/IrcMessage.kt
  28. 2
    2
      src/test/kotlin/com/dmdirc/ktirc/IrcClientImplTest.kt
  29. 10
    10
      src/test/kotlin/com/dmdirc/ktirc/events/EventUtilsTest.kt
  30. 27
    27
      src/test/kotlin/com/dmdirc/ktirc/events/handlers/CapabilitiesHandlerTest.kt
  31. 45
    45
      src/test/kotlin/com/dmdirc/ktirc/events/handlers/ChannelStateHandlerTest.kt
  32. 2
    1
      src/test/kotlin/com/dmdirc/ktirc/events/handlers/PingHandlerTest.kt
  33. 8
    8
      src/test/kotlin/com/dmdirc/ktirc/events/handlers/ServerStateHandlerTest.kt
  34. 18
    18
      src/test/kotlin/com/dmdirc/ktirc/events/handlers/UserStateHandlerTest.kt
  35. 5
    8
      src/test/kotlin/com/dmdirc/ktirc/events/mutators/ChannelFanOutMutatorTest.kt
  36. 6
    6
      src/test/kotlin/com/dmdirc/ktirc/events/mutators/ServerReadyMutatorTest.kt
  37. 12
    11
      src/test/kotlin/com/dmdirc/ktirc/io/MessageHandlerTest.kt
  38. 2
    2
      src/test/kotlin/com/dmdirc/ktirc/messages/AccountProcessorTest.kt
  39. 7
    7
      src/test/kotlin/com/dmdirc/ktirc/messages/AuthenticationProcessorTest.kt
  40. 3
    3
      src/test/kotlin/com/dmdirc/ktirc/messages/JoinProcessorTest.kt
  41. 2
    2
      src/test/kotlin/com/dmdirc/ktirc/messages/KickProcessorTest.kt
  42. 8
    8
      src/test/kotlin/com/dmdirc/ktirc/messages/ModeProcessorTest.kt
  43. 4
    4
      src/test/kotlin/com/dmdirc/ktirc/messages/MotdProcessorTest.kt
  44. 4
    4
      src/test/kotlin/com/dmdirc/ktirc/messages/NoticeProcessorTest.kt
  45. 2
    2
      src/test/kotlin/com/dmdirc/ktirc/messages/PartProcessorTest.kt
  46. 8
    8
      src/test/kotlin/com/dmdirc/ktirc/messages/PrivmsgProcessorTest.kt
  47. 2
    2
      src/test/kotlin/com/dmdirc/ktirc/messages/QuitProcessorTest.kt
  48. 4
    4
      src/test/kotlin/com/dmdirc/ktirc/messages/TopicProcessorTest.kt
  49. 1
    1
      src/test/kotlin/com/dmdirc/ktirc/messages/WelcomeProcessorTest.kt
  50. 10
    3
      src/test/kotlin/com/dmdirc/ktirc/model/IrcMessageTest.kt

+ 3
- 0
CHANGELOG View File

4
    e.g. IrcClient { server("irc.example.com", 6667) }
4
    e.g. IrcClient { server("irc.example.com", 6667) }
5
  * Add behaviour options
5
  * Add behaviour options
6
    * requestModesOnJoin - automatically sends a MODE request when joining a channel
6
    * requestModesOnJoin - automatically sends a MODE request when joining a channel
7
+ * Events now have a `metadata` property instead of a `time` (and time is available in metadata)
8
+   * IrcEvent.time is now deprecated but will remain until after v1.0.0.
9
+   * Metadata now contains the event's batch ID, if any.
7
  * (Internal) Introduced event mutators
10
  * (Internal) Introduced event mutators
8
    * Event mutators are now responsible for handling changing events in response to state
11
    * Event mutators are now responsible for handling changing events in response to state
9
      e.g. ChannelFanOutMutator creates Channel* events for global quits/nick changes/etc
12
      e.g. ChannelFanOutMutator creates Channel* events for global quits/nick changes/etc

+ 1
- 1
build.gradle.kts View File

9
     kotlin("jvm") version "1.3.21"
9
     kotlin("jvm") version "1.3.21"
10
     id("com.jfrog.bintray") version "1.8.4"
10
     id("com.jfrog.bintray") version "1.8.4"
11
     id("org.jetbrains.dokka") version "0.9.17"
11
     id("org.jetbrains.dokka") version "0.9.17"
12
-    id("name.remal.check-updates") version "1.0.112"
12
+    id("name.remal.check-updates") version "1.0.113"
13
 }
13
 }
14
 
14
 
15
 jacoco {
15
 jacoco {

+ 4
- 5
src/main/kotlin/com/dmdirc/ktirc/IrcClientImpl.kt View File

25
  */
25
  */
26
 // TODO: How should alternative nicknames work?
26
 // TODO: How should alternative nicknames work?
27
 // TODO: Should IRC Client take a pool of servers and rotate through, or make the caller do that?
27
 // TODO: Should IRC Client take a pool of servers and rotate through, or make the caller do that?
28
-// TODO: Should there be a default profile?
29
 internal class IrcClientImpl(private val config: IrcClientConfig) : IrcClient, CoroutineScope {
28
 internal class IrcClientImpl(private val config: IrcClientConfig) : IrcClient, CoroutineScope {
30
 
29
 
31
     private val log by logger()
30
     private val log by logger()
61
         with(socketFactory(this, config.server.host, config.server.port, config.server.useTls)) {
60
         with(socketFactory(this, config.server.host, config.server.port, config.server.useTls)) {
62
             socket = this
61
             socket = this
63
 
62
 
64
-            emitEvent(ServerConnecting(currentTimeProvider()))
63
+            emitEvent(ServerConnecting(EventMetadata(currentTimeProvider())))
65
 
64
 
66
             launch {
65
             launch {
67
                 try {
66
                 try {
68
                     connect()
67
                     connect()
69
-                    emitEvent(ServerConnected(currentTimeProvider()))
68
+                    emitEvent(ServerConnected(EventMetadata(currentTimeProvider())))
70
                     sendCapabilityList()
69
                     sendCapabilityList()
71
                     sendPasswordIfPresent()
70
                     sendPasswordIfPresent()
72
                     sendNickChange(config.profile.nickname)
71
                     sendNickChange(config.profile.nickname)
73
                     sendUser(config.profile.username, config.profile.realName)
72
                     sendUser(config.profile.username, config.profile.realName)
74
                     messageHandler.processMessages(this@IrcClientImpl, receiveChannel.map { parser.parse(it) })
73
                     messageHandler.processMessages(this@IrcClientImpl, receiveChannel.map { parser.parse(it) })
75
                 } catch (ex : Exception) {
74
                 } catch (ex : Exception) {
76
-                    emitEvent(ServerConnectionError(currentTimeProvider(), ex.toConnectionError(), ex.localizedMessage))
75
+                    emitEvent(ServerConnectionError(EventMetadata(currentTimeProvider()), ex.toConnectionError(), ex.localizedMessage))
77
                 }
76
                 }
78
 
77
 
79
                 reset()
78
                 reset()
80
-                emitEvent(ServerDisconnected(currentTimeProvider()))
79
+                emitEvent(ServerDisconnected(EventMetadata(currentTimeProvider())))
81
             }
80
             }
82
         }
81
         }
83
     }
82
     }

+ 57
- 36
src/main/kotlin/com/dmdirc/ktirc/events/Events.kt View File

6
 import com.dmdirc.ktirc.model.User
6
 import com.dmdirc.ktirc.model.User
7
 import java.time.LocalDateTime
7
 import java.time.LocalDateTime
8
 
8
 
9
+/**
10
+ * Metadata associated with an event.
11
+ *
12
+ * @param time The best-guess time at which the event occurred.
13
+ * @param batchId The ID of the batch this event is part of, if any.
14
+ */
15
+data class EventMetadata(val time: LocalDateTime, val batchId: String? = null)
16
+
9
 /** Base class for all events. */
17
 /** Base class for all events. */
10
-sealed class IrcEvent(val time: LocalDateTime)
18
+sealed class IrcEvent(val metadata: EventMetadata) {
19
+
20
+    /** The time at which the event occurred. */
21
+    @Deprecated("Only for backwards compatibility; to be removed post-1.0.0", replaceWith = ReplaceWith("metadata.time"))
22
+    val time: LocalDateTime
23
+        get() = metadata.time
24
+
25
+}
11
 
26
 
12
 /** Raised when a connection to the server is being established. */
27
 /** Raised when a connection to the server is being established. */
13
-class ServerConnecting(time: LocalDateTime) : IrcEvent(time)
28
+class ServerConnecting(metadata: EventMetadata) : IrcEvent(metadata)
14
 
29
 
15
 /** Raised when the connection to the server has been established. The server will not be ready for use yet. */
30
 /** Raised when the connection to the server has been established. The server will not be ready for use yet. */
16
-class ServerConnected(time: LocalDateTime) : IrcEvent(time)
31
+class ServerConnected(metadata: EventMetadata) : IrcEvent(metadata)
17
 
32
 
18
 /** Raised when the connection to the server has ended. */
33
 /** Raised when the connection to the server has ended. */
19
-class ServerDisconnected(time: LocalDateTime) : IrcEvent(time)
34
+class ServerDisconnected(metadata: EventMetadata) : IrcEvent(metadata)
20
 
35
 
21
 /** Raised when an error occurred trying to connect. */
36
 /** Raised when an error occurred trying to connect. */
22
-class ServerConnectionError(time: LocalDateTime, val error: ConnectionError, val details: String?) : IrcEvent(time)
37
+class ServerConnectionError(metadata: EventMetadata, val error: ConnectionError, val details: String?) : IrcEvent(metadata)
23
 
38
 
24
 /** Raised when the server is ready for use. */
39
 /** Raised when the server is ready for use. */
25
-class ServerReady(time: LocalDateTime) : IrcEvent(time)
40
+class ServerReady(metadata: EventMetadata) : IrcEvent(metadata)
26
 
41
 
27
 /** Raised when the server initially welcomes us to the IRC network. */
42
 /** Raised when the server initially welcomes us to the IRC network. */
28
-class ServerWelcome(time: LocalDateTime, val server: String, val localNick: String) : IrcEvent(time)
43
+class ServerWelcome(metadata: EventMetadata, val server: String, val localNick: String) : IrcEvent(metadata)
29
 
44
 
30
 /** Raised when the features supported by the server have changed. This may occur numerous times. */
45
 /** Raised when the features supported by the server have changed. This may occur numerous times. */
31
-class ServerFeaturesUpdated(time: LocalDateTime, val serverFeatures: ServerFeatureMap) : IrcEvent(time)
46
+class ServerFeaturesUpdated(metadata: EventMetadata, val serverFeatures: ServerFeatureMap) : IrcEvent(metadata)
32
 
47
 
33
 /** Raised whenever a PING is received from the server. */
48
 /** Raised whenever a PING is received from the server. */
34
-class PingReceived(time: LocalDateTime, val nonce: ByteArray) : IrcEvent(time)
49
+class PingReceived(metadata: EventMetadata, val nonce: ByteArray) : IrcEvent(metadata)
35
 
50
 
36
 /** Raised when a user joins a channel. */
51
 /** Raised when a user joins a channel. */
37
-class ChannelJoined(time: LocalDateTime, val user: User, val channel: String) : IrcEvent(time)
52
+class ChannelJoined(metadata: EventMetadata, val user: User, val channel: String) : IrcEvent(metadata)
38
 
53
 
39
 /** Raised when a user leaves a channel. */
54
 /** Raised when a user leaves a channel. */
40
-class ChannelParted(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
55
+class ChannelParted(metadata: EventMetadata, val user: User, val channel: String, val reason: String = "") : IrcEvent(metadata)
41
 
56
 
42
 /** Raised when a [victim] is kicked from a channel. */
57
 /** Raised when a [victim] is kicked from a channel. */
43
-class ChannelUserKicked(time: LocalDateTime, val user: User, val channel: String, val victim: String, val reason: String = "") : IrcEvent(time)
58
+class ChannelUserKicked(metadata: EventMetadata, val user: User, val channel: String, val victim: String, val reason: String = "") : IrcEvent(metadata)
44
 
59
 
45
 /** Raised when a user quits, and is in a channel. */
60
 /** Raised when a user quits, and is in a channel. */
46
-class ChannelQuit(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
61
+class ChannelQuit(metadata: EventMetadata, val user: User, val channel: String, val reason: String = "") : IrcEvent(metadata)
47
 
62
 
48
 /** Raised when a user changes nickname, and is in a channel. */
63
 /** Raised when a user changes nickname, and is in a channel. */
49
-class ChannelNickChanged(time: LocalDateTime, val user: User, val channel: String, val newNick: String) : IrcEvent(time)
64
+class ChannelNickChanged(metadata: EventMetadata, val user: User, val channel: String, val newNick: String) : IrcEvent(metadata)
50
 
65
 
51
 /** Raised when a batch of the channel's member list has been received. More batches may follow. */
66
 /** Raised when a batch of the channel's member list has been received. More batches may follow. */
52
-class ChannelNamesReceived(time: LocalDateTime, val channel: String, val names: List<String>) : IrcEvent(time)
67
+class ChannelNamesReceived(metadata: EventMetadata, val channel: String, val names: List<String>) : IrcEvent(metadata)
53
 
68
 
54
 /** Raised when the entirety of the channel's member list has been received. */
69
 /** Raised when the entirety of the channel's member list has been received. */
55
-class ChannelNamesFinished(time: LocalDateTime, val channel: String) : IrcEvent(time)
70
+class ChannelNamesFinished(metadata: EventMetadata, val channel: String) : IrcEvent(metadata)
56
 
71
 
57
 /** Raised when a channel topic is discovered (not changed). Usually followed by [ChannelTopicMetadataDiscovered] if the [topic] is non-null. */
72
 /** Raised when a channel topic is discovered (not changed). Usually followed by [ChannelTopicMetadataDiscovered] if the [topic] is non-null. */
58
-class ChannelTopicDiscovered(time: LocalDateTime, val channel: String, val topic: String?) : IrcEvent(time)
73
+class ChannelTopicDiscovered(metadata: EventMetadata, val channel: String, val topic: String?) : IrcEvent(metadata)
59
 
74
 
60
 /** Raised when a channel topic's metadata is discovered. */
75
 /** Raised when a channel topic's metadata is discovered. */
61
-class ChannelTopicMetadataDiscovered(time: LocalDateTime, val channel: String, val user: User, val setTime: LocalDateTime) : IrcEvent(time)
76
+class ChannelTopicMetadataDiscovered(metadata: EventMetadata, val channel: String, val user: User, val setTime: LocalDateTime) : IrcEvent(metadata)
62
 
77
 
63
 /**
78
 /**
64
  * Raised when a channel's topic is changed.
79
  * Raised when a channel's topic is changed.
65
  *
80
  *
66
  * If the topic has been unset (cleared), [topic] will be `null`
81
  * If the topic has been unset (cleared), [topic] will be `null`
67
  */
82
  */
68
-class ChannelTopicChanged(time: LocalDateTime, val user: User, val channel: String, val topic: String?) : IrcEvent(time)
83
+class ChannelTopicChanged(metadata: EventMetadata, val user: User, val channel: String, val topic: String?) : IrcEvent(metadata)
69
 
84
 
70
 /** Raised when a message is received. */
85
 /** Raised when a message is received. */
71
-class MessageReceived(time: LocalDateTime, val user: User, val target: String, val message: String, val messageId: String? = null) : IrcEvent(time)
86
+class MessageReceived(metadata: EventMetadata, val user: User, val target: String, val message: String, val messageId: String? = null) : IrcEvent(metadata)
72
 
87
 
73
 /**
88
 /**
74
  * Raised when a notice is received.
89
  * Raised when a notice is received.
75
  *
90
  *
76
  * The [user] may in fact be a server, or have a nickname of `*` while connecting.
91
  * The [user] may in fact be a server, or have a nickname of `*` while connecting.
77
  */
92
  */
78
-class NoticeReceived(time: LocalDateTime, val user: User, val target: String, val message: String) : IrcEvent(time)
93
+class NoticeReceived(metadata: EventMetadata, val user: User, val target: String, val message: String) : IrcEvent(metadata)
79
 
94
 
80
 /** Raised when an action is received. */
95
 /** Raised when an action is received. */
81
-class ActionReceived(time: LocalDateTime, val user: User, val target: String, val action: String, val messageId: String? = null) : IrcEvent(time)
96
+class ActionReceived(metadata: EventMetadata, val user: User, val target: String, val action: String, val messageId: String? = null) : IrcEvent(metadata)
82
 
97
 
83
 /** Raised when a CTCP is received. */
98
 /** Raised when a CTCP is received. */
84
-class CtcpReceived(time: LocalDateTime, val user: User, val target: String, val type: String, val content: String) : IrcEvent(time)
99
+class CtcpReceived(metadata: EventMetadata, val user: User, val target: String, val type: String, val content: String) : IrcEvent(metadata)
85
 
100
 
86
 /** Raised when a CTCP reply is received. */
101
 /** Raised when a CTCP reply is received. */
87
-class CtcpReplyReceived(time: LocalDateTime, val user: User, val target: String, val type: String, val content: String) : IrcEvent(time)
102
+class CtcpReplyReceived(metadata: EventMetadata, val user: User, val target: String, val type: String, val content: String) : IrcEvent(metadata)
88
 
103
 
89
 /** Raised when a user quits. */
104
 /** Raised when a user quits. */
90
-class UserQuit(time: LocalDateTime, val user: User, val reason: String = "") : IrcEvent(time)
105
+class UserQuit(metadata: EventMetadata, val user: User, val reason: String = "") : IrcEvent(metadata)
91
 
106
 
92
 /** Raised when a user changes nickname. */
107
 /** Raised when a user changes nickname. */
93
-class UserNickChanged(time: LocalDateTime, val user: User, val newNick: String) : IrcEvent(time)
108
+class UserNickChanged(metadata: EventMetadata, val user: User, val newNick: String) : IrcEvent(metadata)
94
 
109
 
95
 /**
110
 /**
96
  * Raised when a user's account changes (i.e., they auth'd or deauth'd with services).
111
  * Raised when a user's account changes (i.e., they auth'd or deauth'd with services).
97
  *
112
  *
98
  * This event is only raised if the server supports the `account-notify` capability.
113
  * This event is only raised if the server supports the `account-notify` capability.
99
  */
114
  */
100
-class UserAccountChanged(time: LocalDateTime, val user: User, val newAccount: String?) : IrcEvent(time)
115
+class UserAccountChanged(metadata: EventMetadata, val user: User, val newAccount: String?) : IrcEvent(metadata)
101
 
116
 
102
 /** Raised when available server capabilities are received. More batches may follow. */
117
 /** Raised when available server capabilities are received. More batches may follow. */
103
-class ServerCapabilitiesReceived(time: LocalDateTime, val capabilities: Map<Capability, String>) : IrcEvent(time)
118
+class ServerCapabilitiesReceived(metadata: EventMetadata, val capabilities: Map<Capability, String>) : IrcEvent(metadata)
104
 
119
 
105
 /** Raised when our requested capabilities are acknowledged. More batches may follow. */
120
 /** Raised when our requested capabilities are acknowledged. More batches may follow. */
106
-class ServerCapabilitiesAcknowledged(time: LocalDateTime, val capabilities: Map<Capability, String>) : IrcEvent(time)
121
+class ServerCapabilitiesAcknowledged(metadata: EventMetadata, val capabilities: Map<Capability, String>) : IrcEvent(metadata)
107
 
122
 
108
 /** Raised when the server has finished sending us capabilities. */
123
 /** Raised when the server has finished sending us capabilities. */
109
-class ServerCapabilitiesFinished(time: LocalDateTime) : IrcEvent(time)
124
+class ServerCapabilitiesFinished(metadata: EventMetadata) : IrcEvent(metadata)
110
 
125
 
111
 /** Raised when a line of the Message Of the Day has been received. */
126
 /** Raised when a line of the Message Of the Day has been received. */
112
-class MotdLineReceived(time: LocalDateTime, val line: String, val first: Boolean = false) : IrcEvent(time)
127
+class MotdLineReceived(metadata: EventMetadata, val line: String, val first: Boolean = false) : IrcEvent(metadata)
113
 
128
 
114
 /** Raised when a Message Of the Day has completed. */
129
 /** Raised when a Message Of the Day has completed. */
115
-class MotdFinished(time: LocalDateTime, val missing: Boolean = false) : IrcEvent(time)
130
+class MotdFinished(metadata: EventMetadata, val missing: Boolean = false) : IrcEvent(metadata)
116
 
131
 
117
 /**
132
 /**
118
  * Raised when a mode change occurs.
133
  * Raised when a mode change occurs.
121
  * and the given modes are thus exhaustive. Otherwise, the modes are a sequence of changes to apply to the existing
136
  * and the given modes are thus exhaustive. Otherwise, the modes are a sequence of changes to apply to the existing
122
  * state.
137
  * state.
123
  */
138
  */
124
-class ModeChanged(time: LocalDateTime, val target: String, val modes: String, val arguments: Array<String>, val discovered: Boolean = false) : IrcEvent(time)
139
+class ModeChanged(metadata: EventMetadata, val target: String, val modes: String, val arguments: Array<String>, val discovered: Boolean = false) : IrcEvent(metadata)
125
 
140
 
126
 /** Raised when an AUTHENTICATION message is received. [argument] is `null` if the server sent an empty reply ("+") */
141
 /** Raised when an AUTHENTICATION message is received. [argument] is `null` if the server sent an empty reply ("+") */
127
-class AuthenticationMessage(time: LocalDateTime, val argument: String?) : IrcEvent(time)
142
+class AuthenticationMessage(metadata: EventMetadata, val argument: String?) : IrcEvent(metadata)
128
 
143
 
129
 /** Raised when a SASL attempt finishes, successfully or otherwise. */
144
 /** Raised when a SASL attempt finishes, successfully or otherwise. */
130
-class SaslFinished(time: LocalDateTime, var success: Boolean) : IrcEvent(time)
145
+class SaslFinished(metadata: EventMetadata, var success: Boolean) : IrcEvent(metadata)
131
 
146
 
132
 /** Raised when the server says our SASL mechanism isn't available, but gives us a list of others. */
147
 /** Raised when the server says our SASL mechanism isn't available, but gives us a list of others. */
133
-class SaslMechanismNotAvailableError(time: LocalDateTime, var mechanisms: Collection<String>) : IrcEvent(time)
148
+class SaslMechanismNotAvailableError(metadata: EventMetadata, var mechanisms: Collection<String>) : IrcEvent(metadata)
149
+
150
+/** Indicates a batch of messages has begun. */
151
+class BatchStarted(metadata: EventMetadata, val referenceId: String, val batchType: String, val params: Array<String>) : IrcEvent(metadata)
152
+
153
+/** Indicates a batch of messages has finished. */
154
+class BatchFinished(metadata: EventMetadata, val referenceId: String) : IrcEvent(metadata)

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/events/handlers/ChannelStateHandler.kt View File

105
 
105
 
106
     private fun handleTopicChanged(client: IrcClient, event: ChannelTopicChanged) {
106
     private fun handleTopicChanged(client: IrcClient, event: ChannelTopicChanged) {
107
         client.channelState[event.channel]?.let {
107
         client.channelState[event.channel]?.let {
108
-            it.topic = ChannelTopic(event.topic, event.user, event.time)
108
+            it.topic = ChannelTopic(event.topic, event.user, event.metadata.time)
109
         }
109
         }
110
     }
110
     }
111
 
111
 

+ 2
- 2
src/main/kotlin/com/dmdirc/ktirc/events/mutators/ChannelFanOutMutator.kt View File

19
     private suspend fun SequenceScope<IrcEvent>.handleQuit(client: IrcClient, event: UserQuit) {
19
     private suspend fun SequenceScope<IrcEvent>.handleQuit(client: IrcClient, event: UserQuit) {
20
         client.channelState.forEach {
20
         client.channelState.forEach {
21
             if (it.users.contains(event.user.nickname)) {
21
             if (it.users.contains(event.user.nickname)) {
22
-                yield(ChannelQuit(event.time, event.user, it.name, event.reason))
22
+                yield(ChannelQuit(event.metadata, event.user, it.name, event.reason))
23
             }
23
             }
24
         }
24
         }
25
     }
25
     }
28
         client.channelState.forEach {
28
         client.channelState.forEach {
29
             it.users[event.user.nickname]?.let { chanUser ->
29
             it.users[event.user.nickname]?.let { chanUser ->
30
                 chanUser.nickname = event.newNick
30
                 chanUser.nickname = event.newNick
31
-                yield(ChannelNickChanged(event.time, event.user, it.name, event.newNick))
31
+                yield(ChannelNickChanged(event.metadata, event.user, it.name, event.newNick))
32
             }
32
             }
33
         }
33
         }
34
     }
34
     }

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/events/mutators/ServerReadyMutator.kt View File

28
         if (client.serverState.receivedWelcome
28
         if (client.serverState.receivedWelcome
29
                 && client.serverState.status == ServerStatus.Negotiating
29
                 && client.serverState.status == ServerStatus.Negotiating
30
                 && event::class !in excludedEvents) {
30
                 && event::class !in excludedEvents) {
31
-            yield(ServerReady(event.time))
31
+            yield(ServerReady(event.metadata))
32
         }
32
         }
33
         yield(event)
33
         yield(event)
34
     }.toList()
34
     }.toList()

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/AccountProcessor.kt View File

8
     override val commands = arrayOf("ACCOUNT")
8
     override val commands = arrayOf("ACCOUNT")
9
 
9
 
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
11
-        listOf(UserAccountChanged(message.time, user, message.accountName))
11
+        listOf(UserAccountChanged(message.metadata, user, message.accountName))
12
     } ?: emptyList()
12
     } ?: emptyList()
13
 
13
 
14
     private val IrcMessage.accountName
14
     private val IrcMessage.accountName

+ 4
- 4
src/main/kotlin/com/dmdirc/ktirc/messages/AuthenticationProcessor.kt View File

10
     override val commands = arrayOf("AUTHENTICATE", RPL_SASLSUCCESS, ERR_SASLFAIL, RPL_SASLMECHS)
10
     override val commands = arrayOf("AUTHENTICATE", RPL_SASLSUCCESS, ERR_SASLFAIL, RPL_SASLMECHS)
11
 
11
 
12
     override fun process(message: IrcMessage) = when(message.command) {
12
     override fun process(message: IrcMessage) = when(message.command) {
13
-        "AUTHENTICATE" -> listOf(AuthenticationMessage(message.time, message.authenticateArgument))
14
-        RPL_SASLSUCCESS -> listOf(SaslFinished(message.time, true))
15
-        ERR_SASLFAIL -> listOf(SaslFinished(message.time, false))
16
-        RPL_SASLMECHS -> listOf(SaslMechanismNotAvailableError(message.time, message.mechanisms))
13
+        "AUTHENTICATE" -> listOf(AuthenticationMessage(message.metadata, message.authenticateArgument))
14
+        RPL_SASLSUCCESS -> listOf(SaslFinished(message.metadata, true))
15
+        ERR_SASLFAIL -> listOf(SaslFinished(message.metadata, false))
16
+        RPL_SASLMECHS -> listOf(SaslMechanismNotAvailableError(message.metadata, message.mechanisms))
17
         else -> emptyList()
17
         else -> emptyList()
18
     }
18
     }
19
 
19
 

+ 14
- 0
src/main/kotlin/com/dmdirc/ktirc/messages/BatchProcessor.kt View File

1
+package com.dmdirc.ktirc.messages
2
+
3
+import com.dmdirc.ktirc.events.IrcEvent
4
+import com.dmdirc.ktirc.model.IrcMessage
5
+
6
+internal class BatchProcessor : MessageProcessor {
7
+
8
+    override val commands = arrayOf("BATCH")
9
+
10
+    override fun process(message: IrcMessage): List<IrcEvent> {
11
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
12
+    }
13
+
14
+}

+ 6
- 6
src/main/kotlin/com/dmdirc/ktirc/messages/CapabilityProcessor.kt View File

1
 package com.dmdirc.ktirc.messages
1
 package com.dmdirc.ktirc.messages
2
 
2
 
3
+import com.dmdirc.ktirc.events.EventMetadata
3
 import com.dmdirc.ktirc.events.ServerCapabilitiesAcknowledged
4
 import com.dmdirc.ktirc.events.ServerCapabilitiesAcknowledged
4
 import com.dmdirc.ktirc.events.ServerCapabilitiesFinished
5
 import com.dmdirc.ktirc.events.ServerCapabilitiesFinished
5
 import com.dmdirc.ktirc.events.ServerCapabilitiesReceived
6
 import com.dmdirc.ktirc.events.ServerCapabilitiesReceived
6
 import com.dmdirc.ktirc.model.IrcMessage
7
 import com.dmdirc.ktirc.model.IrcMessage
7
 import com.dmdirc.ktirc.model.capabilities
8
 import com.dmdirc.ktirc.model.capabilities
8
 import com.dmdirc.ktirc.util.logger
9
 import com.dmdirc.ktirc.util.logger
9
-import java.time.LocalDateTime
10
 
10
 
11
 internal class CapabilityProcessor : MessageProcessor {
11
 internal class CapabilityProcessor : MessageProcessor {
12
 
12
 
15
     override val commands = arrayOf("CAP")
15
     override val commands = arrayOf("CAP")
16
 
16
 
17
     override fun process(message: IrcMessage) = when (message.subCommand) {
17
     override fun process(message: IrcMessage) = when (message.subCommand) {
18
-        "LS" -> handleList(message.time, message.subCommandArguments)
19
-        "ACK" -> listOf(ServerCapabilitiesAcknowledged(message.time, message.params.capabilities))
18
+        "LS" -> handleList(message.metadata, message.subCommandArguments)
19
+        "ACK" -> listOf(ServerCapabilitiesAcknowledged(message.metadata, message.params.capabilities))
20
         else -> emptyList()
20
         else -> emptyList()
21
     }
21
     }
22
 
22
 
23
-    private fun handleList(time: LocalDateTime, lsParams: List<ByteArray>) = sequence {
24
-        yield(ServerCapabilitiesReceived(time, lsParams.capabilities))
23
+    private fun handleList(metadata: EventMetadata, lsParams: List<ByteArray>) = sequence {
24
+        yield(ServerCapabilitiesReceived(metadata, lsParams.capabilities))
25
         if (lsParams.size < 2 || String(lsParams[0]) != "*") {
25
         if (lsParams.size < 2 || String(lsParams[0]) != "*") {
26
-            yield(ServerCapabilitiesFinished(time))
26
+            yield(ServerCapabilitiesFinished(metadata))
27
         }
27
         }
28
     }.toList()
28
     }.toList()
29
 
29
 

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/ISupportProcessor.kt View File

15
 
15
 
16
     override val commands = arrayOf(RPL_ISUPPORT)
16
     override val commands = arrayOf(RPL_ISUPPORT)
17
 
17
 
18
-    override fun process(message: IrcMessage) = listOf(ServerFeaturesUpdated(message.time, ServerFeatureMap().apply {
18
+    override fun process(message: IrcMessage) = listOf(ServerFeaturesUpdated(message.metadata, ServerFeatureMap().apply {
19
         // Ignore the first (nickname) and last ("are supported by this server") params
19
         // Ignore the first (nickname) and last ("are supported by this server") params
20
         for (i in 1 until message.params.size - 1) {
20
         for (i in 1 until message.params.size - 1) {
21
             parseParam(message.params[i])
21
             parseParam(message.params[i])

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/JoinProcessor.kt View File

10
 
10
 
11
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
11
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
12
         user.addExtendedJoinFields(message.params)
12
         user.addExtendedJoinFields(message.params)
13
-        listOf(ChannelJoined(message.time, user, String(message.params[0])))
13
+        listOf(ChannelJoined(message.metadata, user, String(message.params[0])))
14
     } ?: emptyList()
14
     } ?: emptyList()
15
 
15
 
16
     private fun User.addExtendedJoinFields(params: List<ByteArray>) {
16
     private fun User.addExtendedJoinFields(params: List<ByteArray>) {

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/KickProcessor.kt View File

8
     override val commands = arrayOf("KICK")
8
     override val commands = arrayOf("KICK")
9
 
9
 
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
11
-        listOf(ChannelUserKicked(message.time, user, message.channel, message.victim, message.reason))
11
+        listOf(ChannelUserKicked(message.metadata, user, message.channel, message.victim, message.reason))
12
     } ?: emptyList()
12
     } ?: emptyList()
13
 
13
 
14
     private val IrcMessage.channel
14
     private val IrcMessage.channel

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/ModeProcessor.kt View File

11
         val isDiscovery = message.command == RPL_CHANNELMODEIS || message.command == RPL_UMODEIS
11
         val isDiscovery = message.command == RPL_CHANNELMODEIS || message.command == RPL_UMODEIS
12
         val paramOffset = if (message.command == RPL_CHANNELMODEIS) 1 else 0
12
         val paramOffset = if (message.command == RPL_CHANNELMODEIS) 1 else 0
13
         return listOf(ModeChanged(
13
         return listOf(ModeChanged(
14
-                message.time,
14
+                message.metadata,
15
                 target = String(message.params[paramOffset]),
15
                 target = String(message.params[paramOffset]),
16
                 modes = String(message.params[paramOffset + 1]),
16
                 modes = String(message.params[paramOffset + 1]),
17
                 arguments = message.params.takeLast(message.params.size - paramOffset - 2).map { String(it) }.toTypedArray(),
17
                 arguments = message.params.takeLast(message.params.size - paramOffset - 2).map { String(it) }.toTypedArray(),

+ 4
- 4
src/main/kotlin/com/dmdirc/ktirc/messages/MotdProcessor.kt View File

10
 
10
 
11
     override fun process(message: IrcMessage) = sequence {
11
     override fun process(message: IrcMessage) = sequence {
12
         when (message.command) {
12
         when (message.command) {
13
-            RPL_MOTDSTART -> yield(MotdLineReceived(message.time, String(message.params[1]), true))
14
-            RPL_MOTD -> yield(MotdLineReceived(message.time, String(message.params[1])))
15
-            ERR_NOMOTD -> yield(MotdFinished(message.time, missing = true))
16
-            RPL_ENDOFMOTD -> yield(MotdFinished(message.time))
13
+            RPL_MOTDSTART -> yield(MotdLineReceived(message.metadata, String(message.params[1]), true))
14
+            RPL_MOTD -> yield(MotdLineReceived(message.metadata, String(message.params[1])))
15
+            ERR_NOMOTD -> yield(MotdFinished(message.metadata, missing = true))
16
+            RPL_ENDOFMOTD -> yield(MotdFinished(message.metadata))
17
         }
17
         }
18
     }.toList()
18
     }.toList()
19
 
19
 

+ 2
- 2
src/main/kotlin/com/dmdirc/ktirc/messages/NamesProcessor.kt View File

9
     override val commands = arrayOf("353", "366")
9
     override val commands = arrayOf("353", "366")
10
 
10
 
11
     override fun process(message: IrcMessage) = when (message.command) {
11
     override fun process(message: IrcMessage) = when (message.command) {
12
-        "353" -> listOf(ChannelNamesReceived(message.time, String(message.params[2]), String(message.params[3]).split(' ')))
13
-        "366" -> listOf(ChannelNamesFinished(message.time, String(message.params[1])))
12
+        "353" -> listOf(ChannelNamesReceived(message.metadata, String(message.params[2]), String(message.params[3]).split(' ')))
13
+        "366" -> listOf(ChannelNamesFinished(message.metadata, String(message.params[1])))
14
         else -> emptyList()
14
         else -> emptyList()
15
     }
15
     }
16
 
16
 

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/NickProcessor.kt View File

8
     override val commands = arrayOf("NICK")
8
     override val commands = arrayOf("NICK")
9
 
9
 
10
     override fun process(message: IrcMessage) =
10
     override fun process(message: IrcMessage) =
11
-            message.sourceUser?.let { listOf(UserNickChanged(message.time, it, String(message.params[0]))) }
11
+            message.sourceUser?.let { listOf(UserNickChanged(message.metadata, it, String(message.params[0]))) }
12
                     ?: emptyList()
12
                     ?: emptyList()
13
 
13
 
14
 }
14
 }

+ 2
- 2
src/main/kotlin/com/dmdirc/ktirc/messages/NoticeProcessor.kt View File

12
 
12
 
13
     override fun process(message: IrcMessage) = when {
13
     override fun process(message: IrcMessage) = when {
14
             message.isCtcp() -> handleCtcp(message,  message.sourceUser)
14
             message.isCtcp() -> handleCtcp(message,  message.sourceUser)
15
-            else -> listOf(NoticeReceived(message.time,  message.sourceUser ?: User("*"), String(message.params[0]), String(message.params[1])))
15
+            else -> listOf(NoticeReceived(message.metadata,  message.sourceUser ?: User("*"), String(message.params[0]), String(message.params[1])))
16
         }
16
         }
17
 
17
 
18
     private fun handleCtcp(message: IrcMessage, user: User?): List<IrcEvent> {
18
     private fun handleCtcp(message: IrcMessage, user: User?): List<IrcEvent> {
20
         val content = String(message.params[1]).substring(1 until message.params[1].size - 1)
20
         val content = String(message.params[1]).substring(1 until message.params[1].size - 1)
21
         val parts = content.split(' ', limit=2)
21
         val parts = content.split(' ', limit=2)
22
         val body = if (parts.size == 2) parts[1] else ""
22
         val body = if (parts.size == 2) parts[1] else ""
23
-        return listOf(CtcpReplyReceived(message.time, user, String(message.params[0]), parts[0], body))
23
+        return listOf(CtcpReplyReceived(message.metadata, user, String(message.params[0]), parts[0], body))
24
     }
24
     }
25
 
25
 
26
     private fun IrcMessage.isCtcp() = params[1].size > 2 && params[1][0] == CTCP_BYTE && params[1][params[1].size - 1] == CTCP_BYTE
26
     private fun IrcMessage.isCtcp() = params[1].size > 2 && params[1][0] == CTCP_BYTE && params[1][params[1].size - 1] == CTCP_BYTE

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/PartProcessor.kt View File

8
     override val commands = arrayOf("PART")
8
     override val commands = arrayOf("PART")
9
 
9
 
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
11
-        listOf(ChannelParted(message.time, user, message.channel, message.reason))
11
+        listOf(ChannelParted(message.metadata, user, message.channel, message.reason))
12
     } ?: emptyList()
12
     } ?: emptyList()
13
 
13
 
14
     private val IrcMessage.channel
14
     private val IrcMessage.channel

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/PingProcessor.kt View File

7
 
7
 
8
     override val commands = arrayOf("PING")
8
     override val commands = arrayOf("PING")
9
 
9
 
10
-    override fun process(message: IrcMessage) = listOf(PingReceived(message.time, message.params[0]))
10
+    override fun process(message: IrcMessage) = listOf(PingReceived(message.metadata, message.params[0]))
11
 
11
 
12
 }
12
 }

+ 3
- 3
src/main/kotlin/com/dmdirc/ktirc/messages/PrivmsgProcessor.kt View File

15
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
15
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
16
         listOf(when {
16
         listOf(when {
17
             message.isCtcp() -> handleCtcp(message, user)
17
             message.isCtcp() -> handleCtcp(message, user)
18
-            else -> MessageReceived(message.time, user, String(message.params[0]), String(message.params[1]), message.messageId)
18
+            else -> MessageReceived(message.metadata, user, String(message.params[0]), String(message.params[1]), message.messageId)
19
         })
19
         })
20
     } ?: emptyList()
20
     } ?: emptyList()
21
 
21
 
24
         val parts = content.split(' ', limit=2)
24
         val parts = content.split(' ', limit=2)
25
         val body = if (parts.size == 2) parts[1] else ""
25
         val body = if (parts.size == 2) parts[1] else ""
26
         return when (parts[0].toUpperCase()) {
26
         return when (parts[0].toUpperCase()) {
27
-            "ACTION" -> ActionReceived(message.time, user, String(message.params[0]), body, message.messageId)
28
-            else -> CtcpReceived(message.time, user, String(message.params[0]), parts[0], body)
27
+            "ACTION" -> ActionReceived(message.metadata, user, String(message.params[0]), body, message.messageId)
28
+            else -> CtcpReceived(message.metadata, user, String(message.params[0]), parts[0], body)
29
         }
29
         }
30
     }
30
     }
31
 
31
 

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/QuitProcessor.kt View File

8
     override val commands = arrayOf("QUIT")
8
     override val commands = arrayOf("QUIT")
9
 
9
 
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
10
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
11
-        listOf(UserQuit(message.time, user, message.reason))
11
+        listOf(UserQuit(message.metadata, user, message.reason))
12
     } ?: emptyList()
12
     } ?: emptyList()
13
 
13
 
14
     private val IrcMessage.reason
14
     private val IrcMessage.reason

+ 4
- 4
src/main/kotlin/com/dmdirc/ktirc/messages/TopicProcessor.kt View File

15
 
15
 
16
     override fun process(message: IrcMessage) = sequence {
16
     override fun process(message: IrcMessage) = sequence {
17
         when (message.command) {
17
         when (message.command) {
18
-            RPL_TOPIC -> yield(ChannelTopicDiscovered(message.time, message.channel, String(message.params[2])))
19
-            RPL_NOTOPIC -> yield(ChannelTopicDiscovered(message.time, message.channel, null))
18
+            RPL_TOPIC -> yield(ChannelTopicDiscovered(message.metadata, message.channel, String(message.params[2])))
19
+            RPL_NOTOPIC -> yield(ChannelTopicDiscovered(message.metadata, message.channel, null))
20
             RPL_TOPICWHOTIME -> yield(ChannelTopicMetadataDiscovered(
20
             RPL_TOPICWHOTIME -> yield(ChannelTopicMetadataDiscovered(
21
-                    message.time, message.channel, message.params[2].asUser(), message.topicSetTime))
22
-            "TOPIC" -> message.sourceUser?.let { yield(ChannelTopicChanged(message.time, it, String(message.params[0]), String(message.params[1]))) }
21
+                    message.metadata, message.channel, message.params[2].asUser(), message.topicSetTime))
22
+            "TOPIC" -> message.sourceUser?.let { yield(ChannelTopicChanged(message.metadata, it, String(message.params[0]), String(message.params[1]))) }
23
         }
23
         }
24
     }.toList()
24
     }.toList()
25
 
25
 

+ 1
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/WelcomeProcessor.kt View File

7
 
7
 
8
     override val commands = arrayOf(RPL_WELCOME)
8
     override val commands = arrayOf(RPL_WELCOME)
9
 
9
 
10
-    override fun process(message: IrcMessage) = listOf(ServerWelcome(message.time, message.serverName(), String(message.params[0])))
10
+    override fun process(message: IrcMessage) = listOf(ServerWelcome(message.metadata, message.serverName(), String(message.params[0])))
11
 
11
 
12
     private fun IrcMessage.serverName() = prefix?.let { String(it) } ?: ""
12
     private fun IrcMessage.serverName() = prefix?.let { String(it) } ?: ""
13
 
13
 

+ 3
- 0
src/main/kotlin/com/dmdirc/ktirc/model/CapabilitiesState.kt View File

83
     /** Messages sent by the client are echo'd back on successful delivery. */
83
     /** Messages sent by the client are echo'd back on successful delivery. */
84
     object EchoMessages : Capability("echo-message")
84
     object EchoMessages : Capability("echo-message")
85
 
85
 
86
+    /** Messages can be sent in batches, and potentially handled differently by the client. */
87
+    object Batch : Capability("batch")
88
+
86
     // Capabilities that notify us of changes to other clients:
89
     // Capabilities that notify us of changes to other clients:
87
     /** Receive a notification when a user's account changes. */
90
     /** Receive a notification when a user's account changes. */
88
     object AccountChangeMessages : Capability("account-notify")
91
     object AccountChangeMessages : Capability("account-notify")

+ 21
- 6
src/main/kotlin/com/dmdirc/ktirc/model/IrcMessage.kt View File

1
 package com.dmdirc.ktirc.model
1
 package com.dmdirc.ktirc.model
2
 
2
 
3
+import com.dmdirc.ktirc.events.EventMetadata
3
 import com.dmdirc.ktirc.util.currentTimeProvider
4
 import com.dmdirc.ktirc.util.currentTimeProvider
4
 import com.dmdirc.ktirc.util.currentTimeZoneProvider
5
 import com.dmdirc.ktirc.util.currentTimeZoneProvider
5
 import java.time.Instant
6
 import java.time.Instant
8
 /**
9
 /**
9
  * Represents an IRC protocol message.
10
  * Represents an IRC protocol message.
10
  */
11
  */
11
-class IrcMessage(val tags: Map<MessageTag, String>, val prefix: ByteArray?, val command: String, val params: List<ByteArray>) {
12
+internal class IrcMessage(val tags: Map<MessageTag, String>, val prefix: ByteArray?, val command: String, val params: List<ByteArray>) {
12
 
13
 
13
     /** The time at which the message was sent, or our best guess at it. */
14
     /** The time at which the message was sent, or our best guess at it. */
14
-    val time: LocalDateTime = if (MessageTag.ServerTime in tags) {
15
-        LocalDateTime.ofInstant(Instant.parse(tags[MessageTag.ServerTime]), currentTimeZoneProvider())
16
-    } else {
17
-        currentTimeProvider()
18
-    }
15
+    val metadata = EventMetadata(time, batchId)
19
 
16
 
20
     /** The user that generated the message, if any. */
17
     /** The user that generated the message, if any. */
21
     val sourceUser by lazy {
18
     val sourceUser by lazy {
24
         }
21
         }
25
     }
22
     }
26
 
23
 
24
+    private val time
25
+        get() = if (MessageTag.ServerTime in tags) {
26
+            LocalDateTime.ofInstant(Instant.parse(tags[MessageTag.ServerTime]), currentTimeZoneProvider())
27
+        } else {
28
+            currentTimeProvider()
29
+        }
30
+
31
+    private val batchId
32
+        get() = tags[MessageTag.Batch]
33
+
27
 }
34
 }
28
 
35
 
29
 /**
36
 /**
30
  * Supported tags that may be applied to messages.
37
  * Supported tags that may be applied to messages.
31
  */
38
  */
39
+@Suppress("unused")
32
 sealed class MessageTag(val name: String) {
40
 sealed class MessageTag(val name: String) {
33
     /** Specifies the account name of the user, if the `account-tag` capability is negotiated. */
41
     /** Specifies the account name of the user, if the `account-tag` capability is negotiated. */
34
     object AccountName : MessageTag("account")
42
     object AccountName : MessageTag("account")
43
+
44
+    /** Specifies the ID that a batch message belongs to. */
45
+    object Batch : MessageTag("batch")
46
+
35
     /** Specifies the time the server received the message, if the `server-time` capability is negotiated. */
47
     /** Specifies the time the server received the message, if the `server-time` capability is negotiated. */
36
     object ServerTime : MessageTag("time")
48
     object ServerTime : MessageTag("time")
49
+
37
     /** A unique ID for the message, used to reply, react, edit, delete, etc. */
50
     /** A unique ID for the message, used to reply, react, edit, delete, etc. */
38
     object MessageId : MessageTag("draft/msgid")
51
     object MessageId : MessageTag("draft/msgid")
52
+
39
     /** Used to identify a message ID that was replied to, to enable threaded conversations. */
53
     /** Used to identify a message ID that was replied to, to enable threaded conversations. */
40
     object Reply : MessageTag("+draft/reply")
54
     object Reply : MessageTag("+draft/reply")
55
+
41
     /** Used to specify a slack-like reaction to another message. */
56
     /** Used to specify a slack-like reaction to another message. */
42
     object React : MessageTag("+draft/react")
57
     object React : MessageTag("+draft/react")
43
 }
58
 }

+ 2
- 2
src/test/kotlin/com/dmdirc/ktirc/IrcClientImplTest.kt View File

111
         verify(mockEventHandler, timeout(500).atLeast(2)).invoke(captor.capture())
111
         verify(mockEventHandler, timeout(500).atLeast(2)).invoke(captor.capture())
112
 
112
 
113
         assertTrue(captor.firstValue is ServerConnecting)
113
         assertTrue(captor.firstValue is ServerConnecting)
114
-        assertEquals(TestConstants.time, captor.firstValue.time)
114
+        assertEquals(TestConstants.time, captor.firstValue.metadata.time)
115
 
115
 
116
         assertTrue(captor.secondValue is ServerConnected)
116
         assertTrue(captor.secondValue is ServerConnected)
117
-        assertEquals(TestConstants.time, captor.secondValue.time)
117
+        assertEquals(TestConstants.time, captor.secondValue.metadata.time)
118
     }
118
     }
119
 
119
 
120
     @Test
120
     @Test

+ 10
- 10
src/test/kotlin/com/dmdirc/ktirc/events/EventUtilsTest.kt View File

29
 
29
 
30
     @Test
30
     @Test
31
     fun `ChannelNamesReceived#toModesAndUsers parses nicknames and mode prefixes`() {
31
     fun `ChannelNamesReceived#toModesAndUsers parses nicknames and mode prefixes`() {
32
-        val event = ChannelNamesReceived(TestConstants.time, "#thegibson", listOf(
32
+        val event = ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf(
33
                 "@+acidBurn", "@zeroCool", "thePlague"
33
                 "@+acidBurn", "@zeroCool", "thePlague"
34
         ))
34
         ))
35
 
35
 
48
 
48
 
49
     @Test
49
     @Test
50
     fun `ChannelNamesReceived#toModesAndUsers parses extended joins with prefixes`() {
50
     fun `ChannelNamesReceived#toModesAndUsers parses extended joins with prefixes`() {
51
-        val event = ChannelNamesReceived(TestConstants.time, "#thegibson", listOf(
51
+        val event = ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf(
52
                 "@+acidBurn!libby@root.localhost", "zeroCool!dade@root.localhost"
52
                 "@+acidBurn!libby@root.localhost", "zeroCool!dade@root.localhost"
53
         ))
53
         ))
54
 
54
 
69
     @Test
69
     @Test
70
     fun `reply sends response to user when message is private`() {
70
     fun `reply sends response to user when message is private`() {
71
         serverState.localNickname = "zeroCool"
71
         serverState.localNickname = "zeroCool"
72
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "Zerocool", "Hack the planet!")
72
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "Zerocool", "Hack the planet!")
73
 
73
 
74
         ircClient.reply(message, "OK")
74
         ircClient.reply(message, "OK")
75
         verify(ircClient).send("PRIVMSG acidBurn :OK")
75
         verify(ircClient).send("PRIVMSG acidBurn :OK")
77
 
77
 
78
     @Test
78
     @Test
79
     fun `reply sends unprefixed response to user when message is in a channel`() {
79
     fun `reply sends unprefixed response to user when message is in a channel`() {
80
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!")
80
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!")
81
 
81
 
82
         ircClient.reply(message, "OK")
82
         ircClient.reply(message, "OK")
83
         verify(ircClient).send("PRIVMSG #TheGibson :OK")
83
         verify(ircClient).send("PRIVMSG #TheGibson :OK")
85
 
85
 
86
     @Test
86
     @Test
87
     fun `reply sends prefixed response to user when message is in a channel`() {
87
     fun `reply sends prefixed response to user when message is in a channel`() {
88
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!")
88
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!")
89
 
89
 
90
         ircClient.reply(message, "OK", prefixWithNickname = true)
90
         ircClient.reply(message, "OK", prefixWithNickname = true)
91
         verify(ircClient).send("PRIVMSG #TheGibson :acidBurn: OK")
91
         verify(ircClient).send("PRIVMSG #TheGibson :acidBurn: OK")
94
     @Test
94
     @Test
95
     fun `reply sends response with message ID to user when message is private`() {
95
     fun `reply sends response with message ID to user when message is private`() {
96
         serverState.localNickname = "zeroCool"
96
         serverState.localNickname = "zeroCool"
97
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "Zerocool", "Hack the planet!", "abc123")
97
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "Zerocool", "Hack the planet!", "abc123")
98
 
98
 
99
         ircClient.reply(message, "OK")
99
         ircClient.reply(message, "OK")
100
         verify(ircClient).send("@+draft/reply=abc123 PRIVMSG acidBurn :OK")
100
         verify(ircClient).send("@+draft/reply=abc123 PRIVMSG acidBurn :OK")
102
 
102
 
103
     @Test
103
     @Test
104
     fun `reply sends unprefixed response with message ID to user when message is in a channel`() {
104
     fun `reply sends unprefixed response with message ID to user when message is in a channel`() {
105
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!", "abc123")
105
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!", "abc123")
106
 
106
 
107
         ircClient.reply(message, "OK")
107
         ircClient.reply(message, "OK")
108
         verify(ircClient).send("@+draft/reply=abc123 PRIVMSG #TheGibson :OK")
108
         verify(ircClient).send("@+draft/reply=abc123 PRIVMSG #TheGibson :OK")
110
 
110
 
111
     @Test
111
     @Test
112
     fun `reply sends prefixed response with message ID to user when message is in a channel`() {
112
     fun `reply sends prefixed response with message ID to user when message is in a channel`() {
113
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!", "abc123")
113
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!", "abc123")
114
 
114
 
115
         ircClient.reply(message, "OK", prefixWithNickname = true)
115
         ircClient.reply(message, "OK", prefixWithNickname = true)
116
         verify(ircClient).send("@+draft/reply=abc123 PRIVMSG #TheGibson :acidBurn: OK")
116
         verify(ircClient).send("@+draft/reply=abc123 PRIVMSG #TheGibson :acidBurn: OK")
120
     @Test
120
     @Test
121
     fun `react sends response to user when message is private`() {
121
     fun `react sends response to user when message is private`() {
122
         serverState.localNickname = "zeroCool"
122
         serverState.localNickname = "zeroCool"
123
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "Zerocool", "Hack the planet!", "msgId")
123
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "Zerocool", "Hack the planet!", "msgId")
124
 
124
 
125
         ircClient.react(message, ":P")
125
         ircClient.react(message, ":P")
126
         verify(ircClient).send("@+draft/react=:P;+draft/reply=msgId TAGMSG acidBurn")
126
         verify(ircClient).send("@+draft/react=:P;+draft/reply=msgId TAGMSG acidBurn")
128
 
128
 
129
     @Test
129
     @Test
130
     fun `react sends unprefixed response to user when message is in a channel`() {
130
     fun `react sends unprefixed response to user when message is in a channel`() {
131
-        val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!", "msgId")
131
+        val message = MessageReceived(EventMetadata(TestConstants.time), User("acidBurn"), "#TheGibson", "Hack the planet!", "msgId")
132
 
132
 
133
         ircClient.react(message, ":P")
133
         ircClient.react(message, ":P")
134
         verify(ircClient).send("@+draft/react=:P;+draft/reply=msgId TAGMSG #TheGibson")
134
         verify(ircClient).send("@+draft/react=:P;+draft/reply=msgId TAGMSG #TheGibson")

+ 27
- 27
src/test/kotlin/com/dmdirc/ktirc/events/handlers/CapabilitiesHandlerTest.kt View File

38
 
38
 
39
     @Test
39
     @Test
40
     fun `adds new capabilities to the state`() {
40
     fun `adds new capabilities to the state`() {
41
-        handler.processEvent(ircClient, ServerCapabilitiesReceived(TestConstants.time, hashMapOf(
41
+        handler.processEvent(ircClient, ServerCapabilitiesReceived(EventMetadata(TestConstants.time), hashMapOf(
42
                 Capability.EchoMessages to "",
42
                 Capability.EchoMessages to "",
43
                 Capability.HostsInNamesReply to "123"
43
                 Capability.HostsInNamesReply to "123"
44
         )))
44
         )))
52
     fun `updates negotiation state when capabilities finished`() {
52
     fun `updates negotiation state when capabilities finished`() {
53
         serverState.capabilities.advertisedCapabilities[Capability.EchoMessages] = ""
53
         serverState.capabilities.advertisedCapabilities[Capability.EchoMessages] = ""
54
 
54
 
55
-        handler.processEvent(ircClient, ServerCapabilitiesFinished(TestConstants.time))
55
+        handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
56
 
56
 
57
         assertEquals(CapabilitiesNegotiationState.AWAITING_ACK, serverState.capabilities.negotiationState)
57
         assertEquals(CapabilitiesNegotiationState.AWAITING_ACK, serverState.capabilities.negotiationState)
58
     }
58
     }
62
         serverState.capabilities.advertisedCapabilities[Capability.EchoMessages] = ""
62
         serverState.capabilities.advertisedCapabilities[Capability.EchoMessages] = ""
63
         serverState.capabilities.advertisedCapabilities[Capability.AccountChangeMessages] = ""
63
         serverState.capabilities.advertisedCapabilities[Capability.AccountChangeMessages] = ""
64
 
64
 
65
-        handler.processEvent(ircClient, ServerCapabilitiesFinished(TestConstants.time))
65
+        handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
66
 
66
 
67
         verify(ircClient).send(argThat { equals("CAP REQ :echo-message account-notify") || equals("CAP REQ :account-notify echo-message") })
67
         verify(ircClient).send(argThat { equals("CAP REQ :echo-message account-notify") || equals("CAP REQ :account-notify echo-message") })
68
     }
68
     }
69
 
69
 
70
     @Test
70
     @Test
71
     fun `sends END when blank capabilities received`() {
71
     fun `sends END when blank capabilities received`() {
72
-        handler.processEvent(ircClient, ServerCapabilitiesFinished(TestConstants.time))
72
+        handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
73
 
73
 
74
         verify(ircClient).send("CAP END")
74
         verify(ircClient).send("CAP END")
75
     }
75
     }
76
 
76
 
77
     @Test
77
     @Test
78
     fun `updates negotiation when blank capabilities received`() {
78
     fun `updates negotiation when blank capabilities received`() {
79
-        handler.processEvent(ircClient, ServerCapabilitiesFinished(TestConstants.time))
79
+        handler.processEvent(ircClient, ServerCapabilitiesFinished(EventMetadata(TestConstants.time)))
80
 
80
 
81
         assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
81
         assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
82
     }
82
     }
83
 
83
 
84
     @Test
84
     @Test
85
     fun `sends END when capabilities acknowledged and no enabled mechanisms`() {
85
     fun `sends END when capabilities acknowledged and no enabled mechanisms`() {
86
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
86
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
87
                 Capability.EchoMessages to "",
87
                 Capability.EchoMessages to "",
88
                 Capability.HostsInNamesReply to ""
88
                 Capability.HostsInNamesReply to ""
89
         )))
89
         )))
94
     @Test
94
     @Test
95
     fun `sends END when capabilities acknowledged and no sasl state`() {
95
     fun `sends END when capabilities acknowledged and no sasl state`() {
96
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
96
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
97
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
97
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
98
                 Capability.EchoMessages to "",
98
                 Capability.EchoMessages to "",
99
                 Capability.HostsInNamesReply to ""
99
                 Capability.HostsInNamesReply to ""
100
         )))
100
         )))
106
     fun `sends END when capabilities acknowledged and no shared mechanism`() {
106
     fun `sends END when capabilities acknowledged and no shared mechanism`() {
107
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
107
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
108
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "fake1,fake2"
108
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "fake1,fake2"
109
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
109
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
110
                 Capability.SaslAuthentication to "",
110
                 Capability.SaslAuthentication to "",
111
                 Capability.HostsInNamesReply to ""
111
                 Capability.HostsInNamesReply to ""
112
         )))
112
         )))
118
     fun `sets current SASL mechanism when capabilities acknowledged with shared mechanism`() {
118
     fun `sets current SASL mechanism when capabilities acknowledged with shared mechanism`() {
119
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
119
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
120
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "mech1,fake2"
120
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "mech1,fake2"
121
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
121
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
122
                 Capability.SaslAuthentication to "",
122
                 Capability.SaslAuthentication to "",
123
                 Capability.HostsInNamesReply to ""
123
                 Capability.HostsInNamesReply to ""
124
         )))
124
         )))
130
     fun `sets current SASL mechanism when capabilities acknowledged with no declared mechanisms`() {
130
     fun `sets current SASL mechanism when capabilities acknowledged with no declared mechanisms`() {
131
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
131
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
132
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = ""
132
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = ""
133
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
133
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
134
                 Capability.SaslAuthentication to "",
134
                 Capability.SaslAuthentication to "",
135
                 Capability.HostsInNamesReply to ""
135
                 Capability.HostsInNamesReply to ""
136
         )))
136
         )))
142
     fun `sends authenticate when capabilities acknowledged with shared mechanism`() {
142
     fun `sends authenticate when capabilities acknowledged with shared mechanism`() {
143
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
143
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
144
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "mech1,fake2"
144
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "mech1,fake2"
145
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
145
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
146
                 Capability.SaslAuthentication to "",
146
                 Capability.SaslAuthentication to "",
147
                 Capability.HostsInNamesReply to ""
147
                 Capability.HostsInNamesReply to ""
148
         )))
148
         )))
154
     fun `sends authenticate when capabilities acknowledged with no declared mechanisms`() {
154
     fun `sends authenticate when capabilities acknowledged with no declared mechanisms`() {
155
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
155
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
156
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = ""
156
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = ""
157
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
157
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
158
                 Capability.SaslAuthentication to "",
158
                 Capability.SaslAuthentication to "",
159
                 Capability.HostsInNamesReply to ""
159
                 Capability.HostsInNamesReply to ""
160
         )))
160
         )))
166
     fun `updates negotiation state when capabilities acknowledged with shared mechanism`() {
166
     fun `updates negotiation state when capabilities acknowledged with shared mechanism`() {
167
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
167
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
168
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "mech1,fake2"
168
         serverState.capabilities.advertisedCapabilities[Capability.SaslAuthentication] = "mech1,fake2"
169
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
169
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
170
                 Capability.SaslAuthentication to "",
170
                 Capability.SaslAuthentication to "",
171
                 Capability.HostsInNamesReply to ""
171
                 Capability.HostsInNamesReply to ""
172
         )))
172
         )))
176
 
176
 
177
     @Test
177
     @Test
178
     fun `updates negotiation state when capabilities acknowledged`() {
178
     fun `updates negotiation state when capabilities acknowledged`() {
179
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
179
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
180
                 Capability.EchoMessages to "",
180
                 Capability.EchoMessages to "",
181
                 Capability.HostsInNamesReply to "123"
181
                 Capability.HostsInNamesReply to "123"
182
         )))
182
         )))
186
 
186
 
187
     @Test
187
     @Test
188
     fun `stores enabled caps when capabilities acknowledged`() {
188
     fun `stores enabled caps when capabilities acknowledged`() {
189
-        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(TestConstants.time, hashMapOf(
189
+        handler.processEvent(ircClient, ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), hashMapOf(
190
                 Capability.EchoMessages to "",
190
                 Capability.EchoMessages to "",
191
                 Capability.HostsInNamesReply to "123"
191
                 Capability.HostsInNamesReply to "123"
192
         )))
192
         )))
199
     @Test
199
     @Test
200
     fun `aborts authentication attempt if not expecting one`() {
200
     fun `aborts authentication attempt if not expecting one`() {
201
         serverState.sasl.currentMechanism = null
201
         serverState.sasl.currentMechanism = null
202
-        handler.processEvent(ircClient, AuthenticationMessage(TestConstants.time, "+"))
202
+        handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), "+"))
203
 
203
 
204
         verify(ircClient).send("AUTHENTICATE *")
204
         verify(ircClient).send("AUTHENTICATE *")
205
     }
205
     }
209
         serverState.sasl.currentMechanism = saslMech1
209
         serverState.sasl.currentMechanism = saslMech1
210
 
210
 
211
         val argument = "ABC"
211
         val argument = "ABC"
212
-        handler.processEvent(ircClient, AuthenticationMessage(TestConstants.time, argument))
212
+        handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
213
 
213
 
214
         verify(saslMech1).handleAuthenticationEvent(ircClient, argument.fromBase64())
214
         verify(saslMech1).handleAuthenticationEvent(ircClient, argument.fromBase64())
215
     }
215
     }
219
         serverState.sasl.currentMechanism = saslMech1
219
         serverState.sasl.currentMechanism = saslMech1
220
 
220
 
221
         val argument = "A".repeat(400)
221
         val argument = "A".repeat(400)
222
-        handler.processEvent(ircClient, AuthenticationMessage(TestConstants.time, argument))
222
+        handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
223
 
223
 
224
         assertEquals(argument, serverState.sasl.saslBuffer)
224
         assertEquals(argument, serverState.sasl.saslBuffer)
225
         verify(saslMech1, never()).handleAuthenticationEvent(any(), any())
225
         verify(saslMech1, never()).handleAuthenticationEvent(any(), any())
230
         serverState.sasl.currentMechanism = saslMech1
230
         serverState.sasl.currentMechanism = saslMech1
231
 
231
 
232
         serverState.sasl.saslBuffer = "A".repeat(400)
232
         serverState.sasl.saslBuffer = "A".repeat(400)
233
-        handler.processEvent(ircClient, AuthenticationMessage(TestConstants.time, "B".repeat(400)))
233
+        handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), "B".repeat(400)))
234
 
234
 
235
         assertEquals("A".repeat(400) + "B".repeat(400), serverState.sasl.saslBuffer)
235
         assertEquals("A".repeat(400) + "B".repeat(400), serverState.sasl.saslBuffer)
236
         verify(saslMech1, never()).handleAuthenticationEvent(any(), any())
236
         verify(saslMech1, never()).handleAuthenticationEvent(any(), any())
243
         serverState.sasl.saslBuffer = "A".repeat(400)
243
         serverState.sasl.saslBuffer = "A".repeat(400)
244
 
244
 
245
         val argument = "ABCD"
245
         val argument = "ABCD"
246
-        handler.processEvent(ircClient, AuthenticationMessage(TestConstants.time, argument))
246
+        handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), argument))
247
 
247
 
248
         val captor = argumentCaptor<ByteArray>()
248
         val captor = argumentCaptor<ByteArray>()
249
         verify(saslMech1).handleAuthenticationEvent(same(ircClient), captor.capture())
249
         verify(saslMech1).handleAuthenticationEvent(same(ircClient), captor.capture())
256
 
256
 
257
         serverState.sasl.saslBuffer = "A".repeat(400)
257
         serverState.sasl.saslBuffer = "A".repeat(400)
258
 
258
 
259
-        handler.processEvent(ircClient, AuthenticationMessage(TestConstants.time, null))
259
+        handler.processEvent(ircClient, AuthenticationMessage(EventMetadata(TestConstants.time), null))
260
 
260
 
261
         val captor = argumentCaptor<ByteArray>()
261
         val captor = argumentCaptor<ByteArray>()
262
         verify(saslMech1).handleAuthenticationEvent(same(ircClient), captor.capture())
262
         verify(saslMech1).handleAuthenticationEvent(same(ircClient), captor.capture())
265
 
265
 
266
     @Test
266
     @Test
267
     fun `sends END when SASL auth finished`() {
267
     fun `sends END when SASL auth finished`() {
268
-        handler.processEvent(ircClient, SaslFinished(TestConstants.time, true))
268
+        handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
269
 
269
 
270
         verify(ircClient).send("CAP END")
270
         verify(ircClient).send("CAP END")
271
     }
271
     }
272
 
272
 
273
     @Test
273
     @Test
274
     fun `sets negotiation state when SASL auth finished`() {
274
     fun `sets negotiation state when SASL auth finished`() {
275
-        handler.processEvent(ircClient, SaslFinished(TestConstants.time, true))
275
+        handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
276
 
276
 
277
         assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
277
         assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
278
     }
278
     }
285
             mechanismState = "root@thegibson"
285
             mechanismState = "root@thegibson"
286
         }
286
         }
287
 
287
 
288
-        handler.processEvent(ircClient, SaslFinished(TestConstants.time, true))
288
+        handler.processEvent(ircClient, SaslFinished(EventMetadata(TestConstants.time), true))
289
 
289
 
290
         with (serverState.sasl) {
290
         with (serverState.sasl) {
291
             assertNull(currentMechanism)
291
             assertNull(currentMechanism)
297
     @Test
297
     @Test
298
     fun `sends a new authenticate request when sasl mechanism rejected and new one is acceptable`() {
298
     fun `sends a new authenticate request when sasl mechanism rejected and new one is acceptable`() {
299
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
299
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
300
-        handler.processEvent(ircClient, SaslMechanismNotAvailableError(TestConstants.time, listOf("mech1", "fake2")))
300
+        handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("mech1", "fake2")))
301
 
301
 
302
         verify(ircClient).send("AUTHENTICATE mech1")
302
         verify(ircClient).send("AUTHENTICATE mech1")
303
     }
303
     }
305
     @Test
305
     @Test
306
     fun `sends cap end when sasl mechanism rejected and no new one is acceptable`() {
306
     fun `sends cap end when sasl mechanism rejected and no new one is acceptable`() {
307
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
307
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
308
-        handler.processEvent(ircClient, SaslMechanismNotAvailableError(TestConstants.time, listOf("fake1", "fake2")))
308
+        handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("fake1", "fake2")))
309
 
309
 
310
         verify(ircClient).send("CAP END")
310
         verify(ircClient).send("CAP END")
311
     }
311
     }
313
     @Test
313
     @Test
314
     fun `sets negotiation state when sasl mechanism rejected and no new one is acceptable`() {
314
     fun `sets negotiation state when sasl mechanism rejected and no new one is acceptable`() {
315
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
315
         serverState.sasl.mechanisms.addAll(listOf(saslMech1, saslMech2, saslMech3))
316
-        handler.processEvent(ircClient, SaslMechanismNotAvailableError(TestConstants.time, listOf("fake1", "fake2")))
316
+        handler.processEvent(ircClient, SaslMechanismNotAvailableError(EventMetadata(TestConstants.time), listOf("fake1", "fake2")))
317
 
317
 
318
         assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
318
         assertEquals(CapabilitiesNegotiationState.FINISHED, serverState.capabilities.negotiationState)
319
     }
319
     }

+ 45
- 45
src/test/kotlin/com/dmdirc/ktirc/events/handlers/ChannelStateHandlerTest.kt View File

29
 
29
 
30
     @Test
30
     @Test
31
     fun `creates new state object for local joins`() {
31
     fun `creates new state object for local joins`() {
32
-        handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("acidburn", "libby", "root.localhost"), "#thegibson"))
32
+        handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson"))
33
         assertTrue("#thegibson" in channelStateMap)
33
         assertTrue("#thegibson" in channelStateMap)
34
     }
34
     }
35
 
35
 
36
     @Test
36
     @Test
37
     fun `does not create new state object for remote joins`() {
37
     fun `does not create new state object for remote joins`() {
38
-        handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson"))
38
+        handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
39
         assertFalse("#thegibson" in channelStateMap)
39
         assertFalse("#thegibson" in channelStateMap)
40
     }
40
     }
41
 
41
 
43
     fun `adds joiners to channel state`() {
43
     fun `adds joiners to channel state`() {
44
         channelStateMap += ChannelState("#thegibson") { CaseMapping.Rfc }
44
         channelStateMap += ChannelState("#thegibson") { CaseMapping.Rfc }
45
 
45
 
46
-        handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson"))
46
+        handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
47
 
47
 
48
         assertTrue("zerocool" in channelStateMap["#thegibson"]?.users!!)
48
         assertTrue("zerocool" in channelStateMap["#thegibson"]?.users!!)
49
     }
49
     }
55
         channel.users += ChannelUser("thePlague")
55
         channel.users += ChannelUser("thePlague")
56
         channelStateMap += channel
56
         channelStateMap += channel
57
 
57
 
58
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("zeroCool")))
58
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
59
 
59
 
60
         assertEquals(1, channel.users.count())
60
         assertEquals(1, channel.users.count())
61
         assertNotNull(channel.users["zeroCool"])
61
         assertNotNull(channel.users["zeroCool"])
66
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
66
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
67
         channelStateMap += channel
67
         channelStateMap += channel
68
 
68
 
69
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("zeroCool")))
70
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("acidBurn")))
71
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("thePlague")))
69
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
70
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("acidBurn")))
71
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("thePlague")))
72
 
72
 
73
         assertEquals(3, channel.users.count())
73
         assertEquals(3, channel.users.count())
74
         assertNotNull(channel.users["zeroCool"])
74
         assertNotNull(channel.users["zeroCool"])
81
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
81
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
82
         channelStateMap += channel
82
         channelStateMap += channel
83
 
83
 
84
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("zeroCool")))
85
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
86
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("acidBurn")))
87
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("thePlague")))
84
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("zeroCool")))
85
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
86
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("acidBurn")))
87
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("thePlague")))
88
 
88
 
89
         assertEquals(2, channel.users.count())
89
         assertEquals(2, channel.users.count())
90
         assertNotNull(channel.users["acidBurn"])
90
         assertNotNull(channel.users["acidBurn"])
97
         channelStateMap += channel
97
         channelStateMap += channel
98
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
98
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
99
 
99
 
100
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("@zeroCool", "@+acidBurn", "+thePlague", "cerealKiller")))
101
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
100
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool", "@+acidBurn", "+thePlague", "cerealKiller")))
101
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
102
 
102
 
103
         assertEquals(4, channel.users.count())
103
         assertEquals(4, channel.users.count())
104
         assertEquals("o", channel.users["zeroCool"]?.modes)
104
         assertEquals("o", channel.users["zeroCool"]?.modes)
113
         channelStateMap += channel
113
         channelStateMap += channel
114
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
114
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
115
 
115
 
116
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
117
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
116
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
117
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
118
 
118
 
119
         assertEquals(2, channel.users.count())
119
         assertEquals(2, channel.users.count())
120
         assertEquals("o", channel.users["zeroCool"]?.modes)
120
         assertEquals("o", channel.users["zeroCool"]?.modes)
127
         channelStateMap += channel
127
         channelStateMap += channel
128
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
128
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
129
 
129
 
130
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
130
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@zeroCool!dade@root.localhost", "+acidBurn!libby@root.localhost")))
131
 
131
 
132
         assertTrue(channel.receivingUserList)
132
         assertTrue(channel.receivingUserList)
133
 
133
 
134
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
134
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
135
 
135
 
136
         assertFalse(channel.receivingUserList)
136
         assertFalse(channel.receivingUserList)
137
     }
137
     }
143
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
143
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
144
         behaviour.requestModesOnJoin = true
144
         behaviour.requestModesOnJoin = true
145
 
145
 
146
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
146
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
147
 
147
 
148
         verify(ircClient).send("MODE :#thegibson")
148
         verify(ircClient).send("MODE :#thegibson")
149
     }
149
     }
156
         behaviour.requestModesOnJoin = true
156
         behaviour.requestModesOnJoin = true
157
         channel.modesDiscovered = true
157
         channel.modesDiscovered = true
158
 
158
 
159
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
159
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
160
 
160
 
161
         verify(ircClient, never()).send("MODE :#thegibson")
161
         verify(ircClient, never()).send("MODE :#thegibson")
162
     }
162
     }
168
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
168
         serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
169
         behaviour.requestModesOnJoin = false
169
         behaviour.requestModesOnJoin = false
170
 
170
 
171
-        handler.processEvent(ircClient, ChannelNamesFinished(TestConstants.time, "#thegibson"))
171
+        handler.processEvent(ircClient, ChannelNamesFinished(EventMetadata(TestConstants.time), "#thegibson"))
172
 
172
 
173
         verify(ircClient, never()).send("MODE :#thegibson")
173
         verify(ircClient, never()).send("MODE :#thegibson")
174
     }
174
     }
178
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
178
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
179
         channelStateMap += channel
179
         channelStateMap += channel
180
 
180
 
181
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("acidburn", "libby", "root.localhost"), "#thegibson"))
181
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson"))
182
 
182
 
183
         assertFalse("#thegibson" in channelStateMap)
183
         assertFalse("#thegibson" in channelStateMap)
184
     }
184
     }
189
         channel.users += ChannelUser("ZeroCool")
189
         channel.users += ChannelUser("ZeroCool")
190
         channelStateMap += channel
190
         channelStateMap += channel
191
 
191
 
192
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson"))
192
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
193
 
193
 
194
         assertFalse("zerocool" in channel.users)
194
         assertFalse("zerocool" in channel.users)
195
     }
195
     }
199
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
199
         val channel = ChannelState("#thegibson") { CaseMapping.Rfc }
200
         channelStateMap += channel
200
         channelStateMap += channel
201
 
201
 
202
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson", "acidburn", "Bye!"))
202
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson", "acidburn", "Bye!"))
203
 
203
 
204
         assertFalse("#thegibson" in channelStateMap)
204
         assertFalse("#thegibson" in channelStateMap)
205
     }
205
     }
210
         channel.users += ChannelUser("ZeroCool")
210
         channel.users += ChannelUser("ZeroCool")
211
         channelStateMap += channel
211
         channelStateMap += channel
212
 
212
 
213
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("acidburn", "libby", "root.localhost"), "#thegibson", "zerocool", "Bye!"))
213
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson", "zerocool", "Bye!"))
214
 
214
 
215
         assertFalse("zerocool" in channel.users)
215
         assertFalse("zerocool" in channel.users)
216
     }
216
     }
232
             channelStateMap += this
232
             channelStateMap += this
233
         }
233
         }
234
 
234
 
235
-        handler.processEvent(ircClient, ChannelQuit(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#thegibson"))
236
-        handler.processEvent(ircClient, ChannelQuit(TestConstants.time, User("zerocool", "dade", "root.localhost"), "#dumpsterdiving"))
235
+        handler.processEvent(ircClient, ChannelQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#thegibson"))
236
+        handler.processEvent(ircClient, ChannelQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "#dumpsterdiving"))
237
 
237
 
238
         assertFalse("zerocool" in channelStateMap["#thegibson"]!!.users)
238
         assertFalse("zerocool" in channelStateMap["#thegibson"]!!.users)
239
         assertFalse("zerocool" in channelStateMap["#dumpsterdiving"]!!.users)
239
         assertFalse("zerocool" in channelStateMap["#dumpsterdiving"]!!.users)
247
         channel.users += ChannelUser("acidBurn")
247
         channel.users += ChannelUser("acidBurn")
248
         channelStateMap += channel
248
         channelStateMap += channel
249
 
249
 
250
-        handler.processEvent(ircClient, ChannelNickChanged(TestConstants.time, User("acidburn", "libby", "root.localhost"), "#thegibson", "acidB"))
251
-        handler.processEvent(ircClient, ChannelNickChanged(TestConstants.time, User("acidburn", "libby", "root.localhost"), "#dumpsterdiving", "acidB"))
250
+        handler.processEvent(ircClient, ChannelNickChanged(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#thegibson", "acidB"))
251
+        handler.processEvent(ircClient, ChannelNickChanged(EventMetadata(TestConstants.time), User("acidburn", "libby", "root.localhost"), "#dumpsterdiving", "acidB"))
252
 
252
 
253
         assertFalse("acidBurn" in channel.users)
253
         assertFalse("acidBurn" in channel.users)
254
         assertTrue("acidB" in channel.users)
254
         assertTrue("acidB" in channel.users)
261
         channelStateMap += channel
261
         channelStateMap += channel
262
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
262
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
263
 
263
 
264
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+", emptyArray(), true))
264
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+", emptyArray(), true))
265
 
265
 
266
         assertTrue(channel.modesDiscovered)
266
         assertTrue(channel.modesDiscovered)
267
     }
267
     }
272
         channelStateMap += channel
272
         channelStateMap += channel
273
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
273
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
274
 
274
 
275
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+ceg", arrayOf("CCC", "EEE"), true))
275
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+ceg", arrayOf("CCC", "EEE"), true))
276
 
276
 
277
         assertEquals("CCC", channel.modes['c'])
277
         assertEquals("CCC", channel.modes['c'])
278
         assertEquals("EEE", channel.modes['e'])
278
         assertEquals("EEE", channel.modes['e'])
288
         channelStateMap += channel
288
         channelStateMap += channel
289
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
289
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
290
 
290
 
291
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "-c+d-eh+fg", arrayOf("CCC", "DDD", "FFF"), true))
291
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "-c+d-eh+fg", arrayOf("CCC", "DDD", "FFF"), true))
292
 
292
 
293
         assertNull(channel.modes['c'])
293
         assertNull(channel.modes['c'])
294
         assertEquals("DDD", channel.modes['d'])
294
         assertEquals("DDD", channel.modes['d'])
305
             channelStateMap += this
305
             channelStateMap += this
306
         }
306
         }
307
 
307
 
308
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+o", arrayOf("zeroCool")))
308
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+o", arrayOf("zeroCool")))
309
 
309
 
310
         assertEquals("o", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
310
         assertEquals("o", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
311
     }
311
     }
317
             channelStateMap += this
317
             channelStateMap += this
318
         }
318
         }
319
 
319
 
320
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+v", arrayOf("zeroCool")))
320
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+v", arrayOf("zeroCool")))
321
 
321
 
322
         assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
322
         assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
323
     }
323
     }
329
             channelStateMap += this
329
             channelStateMap += this
330
         }
330
         }
331
 
331
 
332
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+o", arrayOf("zeroCool")))
332
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+o", arrayOf("zeroCool")))
333
 
333
 
334
         assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
334
         assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
335
     }
335
     }
341
             channelStateMap += this
341
             channelStateMap += this
342
         }
342
         }
343
 
343
 
344
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "+vo", arrayOf("zeroCool", "zeroCool")))
344
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "+vo", arrayOf("zeroCool", "zeroCool")))
345
 
345
 
346
         assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
346
         assertEquals("ov", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
347
     }
347
     }
353
             channelStateMap += this
353
             channelStateMap += this
354
         }
354
         }
355
 
355
 
356
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "-vo", arrayOf("zeroCool", "zeroCool")))
356
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "-vo", arrayOf("zeroCool", "zeroCool")))
357
 
357
 
358
         assertEquals("", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
358
         assertEquals("", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
359
     }
359
     }
366
         }
366
         }
367
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
367
         serverState.features[ServerFeature.ChannelModes] = arrayOf("ab", "cd", "ef", "gh")
368
 
368
 
369
-        handler.processEvent(ircClient, ModeChanged(TestConstants.time, "#thegibson", "oa-v+b", arrayOf("zeroCool", "aaa", "zeroCool", "bbb")))
369
+        handler.processEvent(ircClient, ModeChanged(EventMetadata(TestConstants.time), "#thegibson", "oa-v+b", arrayOf("zeroCool", "aaa", "zeroCool", "bbb")))
370
 
370
 
371
         assertEquals("o", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
371
         assertEquals("o", channelStateMap["#thegibson"]?.users?.get("zeroCool")?.modes)
372
         assertEquals("aaa", channelStateMap["#thegibson"]?.modes?.get('a'))
372
         assertEquals("aaa", channelStateMap["#thegibson"]?.modes?.get('a'))
378
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
378
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
379
         channelStateMap += state
379
         channelStateMap += state
380
 
380
 
381
-        handler.processEvent(ircClient, ChannelTopicDiscovered(TestConstants.time, "#thegibson", "Hack the planet!"))
382
-        handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(TestConstants.time, "#thegibson", User("acidBurn"), TestConstants.otherTime))
381
+        handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", "Hack the planet!"))
382
+        handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(EventMetadata(TestConstants.time), "#thegibson", User("acidBurn"), TestConstants.otherTime))
383
 
383
 
384
         assertTrue(state.topicDiscovered)
384
         assertTrue(state.topicDiscovered)
385
         assertEquals(ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.otherTime), state.topic)
385
         assertEquals(ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.otherTime), state.topic)
390
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
390
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
391
         channelStateMap += state
391
         channelStateMap += state
392
 
392
 
393
-        handler.processEvent(ircClient, ChannelTopicDiscovered(TestConstants.time, "#thegibson", null))
393
+        handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", null))
394
 
394
 
395
         assertTrue(state.topicDiscovered)
395
         assertTrue(state.topicDiscovered)
396
         assertEquals(ChannelTopic(), state.topic)
396
         assertEquals(ChannelTopic(), state.topic)
403
         state.topicDiscovered = true
403
         state.topicDiscovered = true
404
         channelStateMap += state
404
         channelStateMap += state
405
 
405
 
406
-        handler.processEvent(ircClient, ChannelTopicDiscovered(TestConstants.time, "#thegibson", "Hack the planet"))
407
-        handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(TestConstants.time, "#thegibson", User("zeroCool"), TestConstants.time))
406
+        handler.processEvent(ircClient, ChannelTopicDiscovered(EventMetadata(TestConstants.time), "#thegibson", "Hack the planet"))
407
+        handler.processEvent(ircClient, ChannelTopicMetadataDiscovered(EventMetadata(TestConstants.time), "#thegibson", User("zeroCool"), TestConstants.time))
408
 
408
 
409
         assertTrue(state.topicDiscovered)
409
         assertTrue(state.topicDiscovered)
410
         assertEquals(ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.otherTime), state.topic)
410
         assertEquals(ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.otherTime), state.topic)
415
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
415
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
416
         channelStateMap += state
416
         channelStateMap += state
417
 
417
 
418
-        handler.processEvent(ircClient, ChannelTopicChanged(TestConstants.time, User("acidBurn"), "#thegibson", "Hack the planet!"))
418
+        handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#thegibson", "Hack the planet!"))
419
 
419
 
420
         assertEquals(ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.time), state.topic)
420
         assertEquals(ChannelTopic("Hack the planet!", User("acidBurn"), TestConstants.time), state.topic)
421
     }
421
     }
425
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
425
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
426
         channelStateMap += state
426
         channelStateMap += state
427
 
427
 
428
-        handler.processEvent(ircClient, ChannelTopicChanged(TestConstants.time, User("acidBurn"), "#thegibson", null))
428
+        handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#thegibson", null))
429
 
429
 
430
         assertEquals(ChannelTopic(null, User("acidBurn"), TestConstants.time), state.topic)
430
         assertEquals(ChannelTopic(null, User("acidBurn"), TestConstants.time), state.topic)
431
     }
431
     }
435
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
435
         val state = ChannelState("#thegibson") { CaseMapping.Rfc }
436
         channelStateMap += state
436
         channelStateMap += state
437
 
437
 
438
-        handler.processEvent(ircClient, ChannelTopicChanged(TestConstants.time, User("acidBurn"), "#dumpsterdiving", "Hack the planet!"))
438
+        handler.processEvent(ircClient, ChannelTopicChanged(EventMetadata(TestConstants.time), User("acidBurn"), "#dumpsterdiving", "Hack the planet!"))
439
 
439
 
440
         assertEquals(ChannelTopic(), state.topic)
440
         assertEquals(ChannelTopic(), state.topic)
441
     }
441
     }

+ 2
- 1
src/test/kotlin/com/dmdirc/ktirc/events/handlers/PingHandlerTest.kt View File

2
 
2
 
3
 import com.dmdirc.ktirc.IrcClient
3
 import com.dmdirc.ktirc.IrcClient
4
 import com.dmdirc.ktirc.TestConstants
4
 import com.dmdirc.ktirc.TestConstants
5
+import com.dmdirc.ktirc.events.EventMetadata
5
 import com.dmdirc.ktirc.events.PingReceived
6
 import com.dmdirc.ktirc.events.PingReceived
6
 import com.nhaarman.mockitokotlin2.mock
7
 import com.nhaarman.mockitokotlin2.mock
7
 import com.nhaarman.mockitokotlin2.verify
8
 import com.nhaarman.mockitokotlin2.verify
16
 
17
 
17
     @Test
18
     @Test
18
     fun `PingHandler responses to pings with a pong`() = runBlocking {
19
     fun `PingHandler responses to pings with a pong`() = runBlocking {
19
-        handler.processEvent(ircClient, PingReceived(TestConstants.time, "the_plague".toByteArray()))
20
+        handler.processEvent(ircClient, PingReceived(EventMetadata(TestConstants.time), "the_plague".toByteArray()))
20
         verify(ircClient).send("PONG :the_plague")
21
         verify(ircClient).send("PONG :the_plague")
21
     }
22
     }
22
 
23
 

+ 8
- 8
src/test/kotlin/com/dmdirc/ktirc/events/handlers/ServerStateHandlerTest.kt View File

23
 
23
 
24
     @Test
24
     @Test
25
     fun `sets local nickname on welcome event`() {
25
     fun `sets local nickname on welcome event`() {
26
-        handler.processEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
26
+        handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
27
         assertEquals("acidBurn", serverState.localNickname)
27
         assertEquals("acidBurn", serverState.localNickname)
28
     }
28
     }
29
 
29
 
30
     @Test
30
     @Test
31
     fun `sets server name on welcome event`() {
31
     fun `sets server name on welcome event`() {
32
-        handler.processEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
32
+        handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
33
         assertEquals("the.gibson", serverState.serverName)
33
         assertEquals("the.gibson", serverState.serverName)
34
     }
34
     }
35
 
35
 
36
     @Test
36
     @Test
37
     fun `sets receivedWelcome on welcome event`() {
37
     fun `sets receivedWelcome on welcome event`() {
38
-        handler.processEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
38
+        handler.processEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
39
         assertTrue(serverState.receivedWelcome)
39
         assertTrue(serverState.receivedWelcome)
40
     }
40
     }
41
 
41
 
42
     @Test
42
     @Test
43
     fun `sets state to connecting on event`() {
43
     fun `sets state to connecting on event`() {
44
-        handler.processEvent(ircClient, ServerConnecting(TestConstants.time))
44
+        handler.processEvent(ircClient, ServerConnecting(EventMetadata(TestConstants.time)))
45
         assertEquals(ServerStatus.Connecting, serverState.status)
45
         assertEquals(ServerStatus.Connecting, serverState.status)
46
     }
46
     }
47
 
47
 
48
     @Test
48
     @Test
49
     fun `sets state to disconnected on event`() {
49
     fun `sets state to disconnected on event`() {
50
         serverState.status = ServerStatus.Ready
50
         serverState.status = ServerStatus.Ready
51
-        handler.processEvent(ircClient, ServerDisconnected(TestConstants.time))
51
+        handler.processEvent(ircClient, ServerDisconnected(EventMetadata(TestConstants.time)))
52
         assertEquals(ServerStatus.Disconnected, serverState.status)
52
         assertEquals(ServerStatus.Disconnected, serverState.status)
53
     }
53
     }
54
 
54
 
55
     @Test
55
     @Test
56
     fun `sets state to negotiating on connected`() {
56
     fun `sets state to negotiating on connected`() {
57
-        handler.processEvent(ircClient, ServerConnected(TestConstants.time))
57
+        handler.processEvent(ircClient, ServerConnected(EventMetadata(TestConstants.time)))
58
         assertEquals(ServerStatus.Negotiating, serverState.status)
58
         assertEquals(ServerStatus.Negotiating, serverState.status)
59
     }
59
     }
60
 
60
 
61
     @Test
61
     @Test
62
     fun `sets state to ready on ServerReady`() {
62
     fun `sets state to ready on ServerReady`() {
63
-        handler.processEvent(ircClient, ServerReady(TestConstants.time))
63
+        handler.processEvent(ircClient, ServerReady(EventMetadata(TestConstants.time)))
64
         assertEquals(ServerStatus.Ready, serverState.status)
64
         assertEquals(ServerStatus.Ready, serverState.status)
65
     }
65
     }
66
 
66
 
70
         features[ServerFeature.ChannelModes] = arrayOf("abc", "def")
70
         features[ServerFeature.ChannelModes] = arrayOf("abc", "def")
71
         features[ServerFeature.WhoxSupport] = true
71
         features[ServerFeature.WhoxSupport] = true
72
 
72
 
73
-        handler.processEvent(ircClient, ServerFeaturesUpdated(TestConstants.time, features))
73
+        handler.processEvent(ircClient, ServerFeaturesUpdated(EventMetadata(TestConstants.time), features))
74
 
74
 
75
         assertArrayEquals(arrayOf("abc", "def"), serverState.features[ServerFeature.ChannelModes])
75
         assertArrayEquals(arrayOf("abc", "def"), serverState.features[ServerFeature.ChannelModes])
76
         assertEquals(true, serverState.features[ServerFeature.WhoxSupport])
76
         assertEquals(true, serverState.features[ServerFeature.WhoxSupport])

+ 18
- 18
src/test/kotlin/com/dmdirc/ktirc/events/handlers/UserStateHandlerTest.kt View File

36
     fun `adds channel to user on join`() {
36
     fun `adds channel to user on join`() {
37
         userState += User("acidBurn")
37
         userState += User("acidBurn")
38
 
38
 
39
-        handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("acidBurn", "libby", "root.localhost"), "#thegibson"))
39
+        handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#thegibson"))
40
 
40
 
41
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
41
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
42
     }
42
     }
45
     fun `updates user info on join`() {
45
     fun `updates user info on join`() {
46
         userState += User("acidBurn")
46
         userState += User("acidBurn")
47
 
47
 
48
-        handler.processEvent(ircClient, ChannelJoined(TestConstants.time, User("acidBurn", "libby", "root.localhost"), "#thegibson"))
48
+        handler.processEvent(ircClient, ChannelJoined(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#thegibson"))
49
 
49
 
50
         val details = userState["acidBurn"]?.details!!
50
         val details = userState["acidBurn"]?.details!!
51
         assertEquals("libby", details.ident)
51
         assertEquals("libby", details.ident)
58
         userState.addToChannel(User("acidBurn"), "#thegibson")
58
         userState.addToChannel(User("acidBurn"), "#thegibson")
59
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
59
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
60
 
60
 
61
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
61
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
62
 
62
 
63
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
63
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
64
     }
64
     }
68
         userState += User("acidBurn")
68
         userState += User("acidBurn")
69
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
69
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
70
 
70
 
71
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
71
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "#dumpsterdiving"))
72
 
72
 
73
         assertNull(userState["acidBurn"])
73
         assertNull(userState["acidBurn"])
74
     }
74
     }
83
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
83
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
84
         userState.addToChannel(User("zeroCool"), "#thegibson")
84
         userState.addToChannel(User("zeroCool"), "#thegibson")
85
 
85
 
86
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
86
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
87
 
87
 
88
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
88
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
89
         assertEquals(listOf("#thegibson"), userState["zeroCool"]?.channels?.toList())
89
         assertEquals(listOf("#thegibson"), userState["zeroCool"]?.channels?.toList())
94
         userState += User("acidBurn")
94
         userState += User("acidBurn")
95
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
95
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
96
 
96
 
97
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
97
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
98
 
98
 
99
         assertNull(userState["acidBurn"])
99
         assertNull(userState["acidBurn"])
100
     }
100
     }
104
         userState += User("zeroCool")
104
         userState += User("zeroCool")
105
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
105
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
106
 
106
 
107
-        handler.processEvent(ircClient, ChannelParted(TestConstants.time, User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
107
+        handler.processEvent(ircClient, ChannelParted(EventMetadata(TestConstants.time), User("zeroCool", "dade", "root.localhost"), "#dumpsterdiving"))
108
 
108
 
109
         assertNotNull(userState["zeroCool"])
109
         assertNotNull(userState["zeroCool"])
110
     }
110
     }
116
         userState.addToChannel(User("acidBurn"), "#thegibson")
116
         userState.addToChannel(User("acidBurn"), "#thegibson")
117
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
117
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
118
 
118
 
119
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("thePlague"), "#dumpsterdiving", "acidBurn"))
119
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "acidBurn"))
120
 
120
 
121
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
121
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
122
     }
122
     }
126
         userState += User("acidBurn")
126
         userState += User("acidBurn")
127
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
127
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
128
 
128
 
129
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("thePlague"), "#dumpsterdiving", "acidBurn"))
129
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "acidBurn"))
130
 
130
 
131
         assertNull(userState["acidBurn"])
131
         assertNull(userState["acidBurn"])
132
     }
132
     }
141
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
141
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
142
         userState.addToChannel(User("zeroCool"), "#thegibson")
142
         userState.addToChannel(User("zeroCool"), "#thegibson")
143
 
143
 
144
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("thePlague"), "#dumpsterdiving", "zeroCool"))
144
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
145
 
145
 
146
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
146
         assertEquals(listOf("#thegibson"), userState["acidBurn"]?.channels?.toList())
147
         assertEquals(listOf("#thegibson"), userState["zeroCool"]?.channels?.toList())
147
         assertEquals(listOf("#thegibson"), userState["zeroCool"]?.channels?.toList())
152
         userState += User("acidBurn")
152
         userState += User("acidBurn")
153
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
153
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
154
 
154
 
155
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("thePlague"), "#dumpsterdiving", "zeroCool"))
155
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
156
 
156
 
157
         assertNull(userState["acidBurn"])
157
         assertNull(userState["acidBurn"])
158
     }
158
     }
162
         userState += User("zeroCool")
162
         userState += User("zeroCool")
163
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
163
         userState.addToChannel(User("zeroCool"), "#dumpsterdiving")
164
 
164
 
165
-        handler.processEvent(ircClient, ChannelUserKicked(TestConstants.time, User("thePlague"), "#dumpsterdiving", "zeroCool"))
165
+        handler.processEvent(ircClient, ChannelUserKicked(EventMetadata(TestConstants.time), User("thePlague"), "#dumpsterdiving", "zeroCool"))
166
 
166
 
167
         assertNotNull(userState["zeroCool"])
167
         assertNotNull(userState["zeroCool"])
168
     }
168
     }
172
         userState += User("acidBurn")
172
         userState += User("acidBurn")
173
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
173
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
174
 
174
 
175
-        handler.processEvent(ircClient, UserQuit(TestConstants.time, User("acidBurn", "libby", "root.localhost")))
175
+        handler.processEvent(ircClient, UserQuit(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost")))
176
 
176
 
177
         assertNull(userState["acidBurn"])
177
         assertNull(userState["acidBurn"])
178
     }
178
     }
182
         userState += User("acidBurn")
182
         userState += User("acidBurn")
183
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
183
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
184
 
184
 
185
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("@acidBurn")))
185
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@acidBurn")))
186
 
186
 
187
         assertEquals(listOf("#dumpsterdiving", "#thegibson"), userState["acidBurn"]?.channels?.toList())
187
         assertEquals(listOf("#dumpsterdiving", "#thegibson"), userState["acidBurn"]?.channels?.toList())
188
     }
188
     }
192
         userState += User("acidBurn")
192
         userState += User("acidBurn")
193
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
193
         userState.addToChannel(User("acidBurn"), "#dumpsterdiving")
194
 
194
 
195
-        handler.processEvent(ircClient, ChannelNamesReceived(TestConstants.time, "#thegibson", listOf("@acidBurn!libby@root.localhost")))
195
+        handler.processEvent(ircClient, ChannelNamesReceived(EventMetadata(TestConstants.time), "#thegibson", listOf("@acidBurn!libby@root.localhost")))
196
 
196
 
197
         val details = userState["acidBurn"]?.details!!
197
         val details = userState["acidBurn"]?.details!!
198
         assertEquals("libby", details.ident)
198
         assertEquals("libby", details.ident)
203
     fun `updates user info on account change`() {
203
     fun `updates user info on account change`() {
204
         userState += User("acidBurn")
204
         userState += User("acidBurn")
205
 
205
 
206
-        handler.processEvent(ircClient, UserAccountChanged(TestConstants.time, User("acidBurn", "libby", "root.localhost"), "acidBurn"))
206
+        handler.processEvent(ircClient, UserAccountChanged(EventMetadata(TestConstants.time), User("acidBurn", "libby", "root.localhost"), "acidBurn"))
207
 
207
 
208
         val details = userState["acidBurn"]?.details!!
208
         val details = userState["acidBurn"]?.details!!
209
         assertEquals("acidBurn", details.account)
209
         assertEquals("acidBurn", details.account)
214
         val user = User("acidBurn", "libby", "root.localhost")
214
         val user = User("acidBurn", "libby", "root.localhost")
215
         whenever(ircClient.isLocalUser(user)).doReturn(true)
215
         whenever(ircClient.isLocalUser(user)).doReturn(true)
216
 
216
 
217
-        handler.processEvent(ircClient, UserNickChanged(TestConstants.time, user, "acid~"))
217
+        handler.processEvent(ircClient, UserNickChanged(EventMetadata(TestConstants.time), user, "acid~"))
218
 
218
 
219
         assertEquals("acid~", serverState.localNickname)
219
         assertEquals("acid~", serverState.localNickname)
220
     }
220
     }
224
         val user = User("acidBurn", "libby", "root.localhost")
224
         val user = User("acidBurn", "libby", "root.localhost")
225
         userState += User("AcidBurn")
225
         userState += User("AcidBurn")
226
 
226
 
227
-        handler.processEvent(ircClient, UserNickChanged(TestConstants.time, user, "acid~"))
227
+        handler.processEvent(ircClient, UserNickChanged(EventMetadata(TestConstants.time), user, "acid~"))
228
 
228
 
229
         assertNotNull(userState["acid~"])
229
         assertNotNull(userState["acid~"])
230
         assertNull(userState["AcidBurn"])
230
         assertNull(userState["AcidBurn"])

+ 5
- 8
src/test/kotlin/com/dmdirc/ktirc/events/mutators/ChannelFanOutMutatorTest.kt View File

3
 import com.dmdirc.ktirc.BehaviourConfig
3
 import com.dmdirc.ktirc.BehaviourConfig
4
 import com.dmdirc.ktirc.IrcClient
4
 import com.dmdirc.ktirc.IrcClient
5
 import com.dmdirc.ktirc.TestConstants
5
 import com.dmdirc.ktirc.TestConstants
6
-import com.dmdirc.ktirc.events.ChannelNickChanged
7
-import com.dmdirc.ktirc.events.ChannelQuit
8
-import com.dmdirc.ktirc.events.UserNickChanged
9
-import com.dmdirc.ktirc.events.UserQuit
6
+import com.dmdirc.ktirc.events.*
10
 import com.dmdirc.ktirc.io.CaseMapping
7
 import com.dmdirc.ktirc.io.CaseMapping
11
 import com.dmdirc.ktirc.model.*
8
 import com.dmdirc.ktirc.model.*
12
 import com.nhaarman.mockitokotlin2.doReturn
9
 import com.nhaarman.mockitokotlin2.doReturn
45
             channelStateMap += this
42
             channelStateMap += this
46
         }
43
         }
47
 
44
 
48
-        val quitEvent = UserQuit(TestConstants.time, User("zerocool", "dade", "root.localhost"), "Hack the planet!")
45
+        val quitEvent = UserQuit(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "Hack the planet!")
49
         val events = mutator.mutateEvent(ircClient, quitEvent)
46
         val events = mutator.mutateEvent(ircClient, quitEvent)
50
 
47
 
51
         val names = mutableListOf<String>()
48
         val names = mutableListOf<String>()
53
         Assertions.assertSame(quitEvent, events[0])
50
         Assertions.assertSame(quitEvent, events[0])
54
         events.subList(1, events.size).forEach { event ->
51
         events.subList(1, events.size).forEach { event ->
55
             (event as ChannelQuit).let {
52
             (event as ChannelQuit).let {
56
-                Assertions.assertEquals(TestConstants.time, it.time)
53
+                Assertions.assertEquals(TestConstants.time, it.metadata.time)
57
                 Assertions.assertEquals("zerocool", it.user.nickname)
54
                 Assertions.assertEquals("zerocool", it.user.nickname)
58
                 Assertions.assertEquals("Hack the planet!", it.reason)
55
                 Assertions.assertEquals("Hack the planet!", it.reason)
59
                 names.add(it.channel)
56
                 names.add(it.channel)
81
             channelStateMap += this
78
             channelStateMap += this
82
         }
79
         }
83
 
80
 
84
-        val nickEvent = UserNickChanged(TestConstants.time, User("zerocool", "dade", "root.localhost"), "zer0c00l")
81
+        val nickEvent = UserNickChanged(EventMetadata(TestConstants.time), User("zerocool", "dade", "root.localhost"), "zer0c00l")
85
         val events = mutator.mutateEvent(ircClient, nickEvent)
82
         val events = mutator.mutateEvent(ircClient, nickEvent)
86
 
83
 
87
         val names = mutableListOf<String>()
84
         val names = mutableListOf<String>()
89
         Assertions.assertSame(nickEvent, events[0])
86
         Assertions.assertSame(nickEvent, events[0])
90
         events.subList(1, events.size).forEach { event ->
87
         events.subList(1, events.size).forEach { event ->
91
             (event as ChannelNickChanged).let {
88
             (event as ChannelNickChanged).let {
92
-                Assertions.assertEquals(TestConstants.time, it.time)
89
+                Assertions.assertEquals(TestConstants.time, it.metadata.time)
93
                 Assertions.assertEquals("zerocool", it.user.nickname)
90
                 Assertions.assertEquals("zerocool", it.user.nickname)
94
                 Assertions.assertEquals("zer0c00l", it.newNick)
91
                 Assertions.assertEquals("zer0c00l", it.newNick)
95
                 names.add(it.channel)
92
                 names.add(it.channel)

+ 6
- 6
src/test/kotlin/com/dmdirc/ktirc/events/mutators/ServerReadyMutatorTest.kt View File

27
         ircClient.serverState.status = ServerStatus.Negotiating
27
         ircClient.serverState.status = ServerStatus.Negotiating
28
 
28
 
29
         listOf(
29
         listOf(
30
-                ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"),
31
-                PingReceived(TestConstants.time, "1234".toByteArray()),
32
-                ServerCapabilitiesReceived(TestConstants.time, emptyMap()),
33
-                ServerCapabilitiesAcknowledged(TestConstants.time, emptyMap()),
34
-                ServerCapabilitiesFinished(TestConstants.time)
30
+                ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"),
31
+                PingReceived(EventMetadata(TestConstants.time), "1234".toByteArray()),
32
+                ServerCapabilitiesReceived(EventMetadata(TestConstants.time), emptyMap()),
33
+                ServerCapabilitiesAcknowledged(EventMetadata(TestConstants.time), emptyMap()),
34
+                ServerCapabilitiesFinished(EventMetadata(TestConstants.time))
35
         ).forEach {
35
         ).forEach {
36
             assertEquals(1, mutator.mutateEvent(ircClient, it).size)
36
             assertEquals(1, mutator.mutateEvent(ircClient, it).size)
37
         }
37
         }
38
 
38
 
39
-        val event = MessageReceived(TestConstants.time, User("zeroCool"), "acidBurn", "Welcome!")
39
+        val event = MessageReceived(EventMetadata(TestConstants.time), User("zeroCool"), "acidBurn", "Welcome!")
40
         val events = mutator.mutateEvent(ircClient, event)
40
         val events = mutator.mutateEvent(ircClient, event)
41
         assertEquals(2, events.size)
41
         assertEquals(2, events.size)
42
         assertSame(event, events[1])
42
         assertSame(event, events[1])

+ 12
- 11
src/test/kotlin/com/dmdirc/ktirc/io/MessageHandlerTest.kt View File

2
 
2
 
3
 import com.dmdirc.ktirc.IrcClient
3
 import com.dmdirc.ktirc.IrcClient
4
 import com.dmdirc.ktirc.TestConstants
4
 import com.dmdirc.ktirc.TestConstants
5
+import com.dmdirc.ktirc.events.EventMetadata
5
 import com.dmdirc.ktirc.events.ServerConnected
6
 import com.dmdirc.ktirc.events.ServerConnected
6
 import com.dmdirc.ktirc.events.ServerReady
7
 import com.dmdirc.ktirc.events.ServerReady
7
 import com.dmdirc.ktirc.events.ServerWelcome
8
 import com.dmdirc.ktirc.events.ServerWelcome
67
         val eventHandler2 = mock<EventHandler>()
68
         val eventHandler2 = mock<EventHandler>()
68
         val handler = MessageHandler(listOf(joinProcessor, nickProcessor), emptyList(), mutableListOf(eventHandler1, eventHandler2))
69
         val handler = MessageHandler(listOf(joinProcessor, nickProcessor), emptyList(), mutableListOf(eventHandler1, eventHandler2))
69
         val joinMessage = IrcMessage(emptyMap(), null, "JOIN", emptyList())
70
         val joinMessage = IrcMessage(emptyMap(), null, "JOIN", emptyList())
70
-        whenever(joinProcessor.process(any())).thenReturn(listOf(ServerConnected(TestConstants.time), ServerWelcome(TestConstants.time, "the.gibson", "acidBurn")))
71
+        whenever(joinProcessor.process(any())).thenReturn(listOf(ServerConnected(EventMetadata(TestConstants.time)), ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn")))
71
 
72
 
72
         with(Channel<IrcMessage>(1)) {
73
         with(Channel<IrcMessage>(1)) {
73
             send(joinMessage)
74
             send(joinMessage)
86
         val eventHandler1 = mock<EventHandler>()
87
         val eventHandler1 = mock<EventHandler>()
87
         val eventHandler2 = mock<EventHandler>()
88
         val eventHandler2 = mock<EventHandler>()
88
         val handler = MessageHandler(emptyList(), emptyList(), mutableListOf(eventHandler1, eventHandler2))
89
         val handler = MessageHandler(emptyList(), emptyList(), mutableListOf(eventHandler1, eventHandler2))
89
-        handler.emitEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
90
+        handler.emitEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
90
 
91
 
91
         verify(eventHandler1).processEvent(same(ircClient), isA<ServerWelcome>())
92
         verify(eventHandler1).processEvent(same(ircClient), isA<ServerWelcome>())
92
         verify(eventHandler2).processEvent(same(ircClient), isA<ServerWelcome>())
93
         verify(eventHandler2).processEvent(same(ircClient), isA<ServerWelcome>())
95
     @Test
96
     @Test
96
     fun `mutates events in order`() {
97
     fun `mutates events in order`() {
97
         val eventMutator1 = mock<EventMutator> {
98
         val eventMutator1 = mock<EventMutator> {
98
-            on { mutateEvent(any(), isA<ServerWelcome>()) } doReturn listOf(ServerReady(TestConstants.time))
99
+            on { mutateEvent(any(), isA<ServerWelcome>()) } doReturn listOf(ServerReady(EventMetadata(TestConstants.time)))
99
         }
100
         }
100
         val eventMutator2 = mock<EventMutator> {
101
         val eventMutator2 = mock<EventMutator> {
101
-            on { mutateEvent(any(), isA<ServerReady>()) } doReturn listOf(ServerConnected(TestConstants.time))
102
+            on { mutateEvent(any(), isA<ServerReady>()) } doReturn listOf(ServerConnected(EventMetadata(TestConstants.time)))
102
         }
103
         }
103
         val eventHandler = mock<EventHandler>()
104
         val eventHandler = mock<EventHandler>()
104
 
105
 
105
         val handler = MessageHandler(emptyList(), listOf(eventMutator1, eventMutator2), mutableListOf(eventHandler))
106
         val handler = MessageHandler(emptyList(), listOf(eventMutator1, eventMutator2), mutableListOf(eventHandler))
106
-        handler.emitEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
107
+        handler.emitEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
107
 
108
 
108
         verify(eventMutator1).mutateEvent(same(ircClient), isA<ServerWelcome>())
109
         verify(eventMutator1).mutateEvent(same(ircClient), isA<ServerWelcome>())
109
         verify(eventMutator2).mutateEvent(same(ircClient), isA<ServerReady>())
110
         verify(eventMutator2).mutateEvent(same(ircClient), isA<ServerReady>())
115
     fun `allows mutators to fan out events`() {
116
     fun `allows mutators to fan out events`() {
116
         val eventMutator1 = mock<EventMutator> {
117
         val eventMutator1 = mock<EventMutator> {
117
             on { mutateEvent(any(), isA<ServerWelcome>()) } doReturn listOf(
118
             on { mutateEvent(any(), isA<ServerWelcome>()) } doReturn listOf(
118
-                    ServerReady(TestConstants.time),
119
-                    ServerConnected(TestConstants.time)
119
+                    ServerReady(EventMetadata(TestConstants.time)),
120
+                    ServerConnected(EventMetadata(TestConstants.time))
120
             )
121
             )
121
         }
122
         }
122
         val eventMutator2 = mock<EventMutator> {
123
         val eventMutator2 = mock<EventMutator> {
123
-            on { mutateEvent(any(), isA<ServerReady>()) } doReturn listOf(ServerReady(TestConstants.time))
124
-            on { mutateEvent(any(), isA<ServerConnected>()) } doReturn listOf(ServerConnected(TestConstants.time))
124
+            on { mutateEvent(any(), isA<ServerReady>()) } doReturn listOf(ServerReady(EventMetadata(TestConstants.time)))
125
+            on { mutateEvent(any(), isA<ServerConnected>()) } doReturn listOf(ServerConnected(EventMetadata(TestConstants.time)))
125
         }
126
         }
126
         val eventHandler = mock<EventHandler>()
127
         val eventHandler = mock<EventHandler>()
127
 
128
 
128
         val handler = MessageHandler(emptyList(), listOf(eventMutator1, eventMutator2), mutableListOf(eventHandler))
129
         val handler = MessageHandler(emptyList(), listOf(eventMutator1, eventMutator2), mutableListOf(eventHandler))
129
-        handler.emitEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
130
+        handler.emitEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
130
 
131
 
131
         with (inOrder(eventMutator2, eventHandler)) {
132
         with (inOrder(eventMutator2, eventHandler)) {
132
             verify(eventMutator2).mutateEvent(same(ircClient), isA<ServerReady>())
133
             verify(eventMutator2).mutateEvent(same(ircClient), isA<ServerReady>())
145
         val eventHandler = mock<EventHandler>()
146
         val eventHandler = mock<EventHandler>()
146
 
147
 
147
         val handler = MessageHandler(emptyList(), listOf(eventMutator1, eventMutator2), mutableListOf(eventHandler))
148
         val handler = MessageHandler(emptyList(), listOf(eventMutator1, eventMutator2), mutableListOf(eventHandler))
148
-        handler.emitEvent(ircClient, ServerWelcome(TestConstants.time, "the.gibson", "acidBurn"))
149
+        handler.emitEvent(ircClient, ServerWelcome(EventMetadata(TestConstants.time), "the.gibson", "acidBurn"))
149
 
150
 
150
         verify(eventMutator2, never()).mutateEvent(any(), any())
151
         verify(eventMutator2, never()).mutateEvent(any(), any())
151
         verify(eventHandler, never()).processEvent(any(), any())
152
         verify(eventHandler, never()).processEvent(any(), any())

+ 2
- 2
src/test/kotlin/com/dmdirc/ktirc/messages/AccountProcessorTest.kt View File

22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "ACCOUNT", params("acidBurn")))
22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "ACCOUNT", params("acidBurn")))
23
         assertEquals(1, events.size)
23
         assertEquals(1, events.size)
24
 
24
 
25
-        assertEquals(TestConstants.time, events[0].time)
25
+        assertEquals(TestConstants.time, events[0].metadata.time)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
27
         assertEquals("acidBurn", events[0].newAccount)
27
         assertEquals("acidBurn", events[0].newAccount)
28
     }
28
     }
33
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "ACCOUNT", params("*")))
33
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "ACCOUNT", params("*")))
34
         assertEquals(1, events.size)
34
         assertEquals(1, events.size)
35
 
35
 
36
-        assertEquals(TestConstants.time, events[0].time)
36
+        assertEquals(TestConstants.time, events[0].metadata.time)
37
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
37
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
38
         assertEquals(null, events[0].newAccount)
38
         assertEquals(null, events[0].newAccount)
39
     }
39
     }

+ 7
- 7
src/test/kotlin/com/dmdirc/ktirc/messages/AuthenticationProcessorTest.kt View File

26
 
26
 
27
         assertEquals(1, events.size)
27
         assertEquals(1, events.size)
28
         val event = events[0] as AuthenticationMessage
28
         val event = events[0] as AuthenticationMessage
29
-        assertEquals(TestConstants.time, event.time)
29
+        assertEquals(TestConstants.time, event.metadata.time)
30
         assertNull(event.argument)
30
         assertNull(event.argument)
31
     }
31
     }
32
 
32
 
36
 
36
 
37
         assertEquals(1, events.size)
37
         assertEquals(1, events.size)
38
         val event = events[0] as AuthenticationMessage
38
         val event = events[0] as AuthenticationMessage
39
-        assertEquals(TestConstants.time, event.time)
39
+        assertEquals(TestConstants.time, event.metadata.time)
40
         assertNull(event.argument)
40
         assertNull(event.argument)
41
     }
41
     }
42
 
42
 
46
 
46
 
47
         assertEquals(1, events.size)
47
         assertEquals(1, events.size)
48
         val event = events[0] as AuthenticationMessage
48
         val event = events[0] as AuthenticationMessage
49
-        assertEquals(TestConstants.time, event.time)
49
+        assertEquals(TestConstants.time, event.metadata.time)
50
         assertEquals("HackThePlanet", event.argument)
50
         assertEquals("HackThePlanet", event.argument)
51
     }
51
     }
52
 
52
 
56
 
56
 
57
         assertEquals(1, events.size)
57
         assertEquals(1, events.size)
58
         val event = events[0] as SaslFinished
58
         val event = events[0] as SaslFinished
59
-        assertEquals(TestConstants.time, event.time)
59
+        assertEquals(TestConstants.time, event.metadata.time)
60
         assertTrue(event.success)
60
         assertTrue(event.success)
61
     }
61
     }
62
 
62
 
66
 
66
 
67
         assertEquals(1, events.size)
67
         assertEquals(1, events.size)
68
         val event = events[0] as SaslFinished
68
         val event = events[0] as SaslFinished
69
-        assertEquals(TestConstants.time, event.time)
69
+        assertEquals(TestConstants.time, event.metadata.time)
70
         assertFalse(event.success)
70
         assertFalse(event.success)
71
     }
71
     }
72
 
72
 
76
 
76
 
77
         assertEquals(1, events.size)
77
         assertEquals(1, events.size)
78
         val event = events[0] as SaslMechanismNotAvailableError
78
         val event = events[0] as SaslMechanismNotAvailableError
79
-        assertEquals(TestConstants.time, event.time)
79
+        assertEquals(TestConstants.time, event.metadata.time)
80
         assertEquals(listOf("PLAIN", "EXTERNAL", "MAGIC"), event.mechanisms)
80
         assertEquals(listOf("PLAIN", "EXTERNAL", "MAGIC"), event.mechanisms)
81
     }
81
     }
82
 
82
 
86
 
86
 
87
         assertEquals(1, events.size)
87
         assertEquals(1, events.size)
88
         val event = events[0] as SaslMechanismNotAvailableError
88
         val event = events[0] as SaslMechanismNotAvailableError
89
-        assertEquals(TestConstants.time, event.time)
89
+        assertEquals(TestConstants.time, event.metadata.time)
90
         assertTrue(event.mechanisms.isEmpty())
90
         assertTrue(event.mechanisms.isEmpty())
91
     }
91
     }
92
 
92
 

+ 3
- 3
src/test/kotlin/com/dmdirc/ktirc/messages/JoinProcessorTest.kt View File

22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", params("#crashandburn")))
22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", params("#crashandburn")))
23
         assertEquals(1, events.size)
23
         assertEquals(1, events.size)
24
 
24
 
25
-        assertEquals(TestConstants.time, events[0].time)
25
+        assertEquals(TestConstants.time, events[0].metadata.time)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
27
         assertEquals("#crashandburn", events[0].channel)
27
         assertEquals("#crashandburn", events[0].channel)
28
     }
28
     }
40
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", params("#crashandburn", "acidBurn", "Libby")))
40
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", params("#crashandburn", "acidBurn", "Libby")))
41
         assertEquals(1, events.size)
41
         assertEquals(1, events.size)
42
 
42
 
43
-        assertEquals(TestConstants.time, events[0].time)
43
+        assertEquals(TestConstants.time, events[0].metadata.time)
44
         assertEquals(User("acidburn", "libby", "root.localhost", account = "acidBurn", realName = "Libby"), events[0].user)
44
         assertEquals(User("acidburn", "libby", "root.localhost", account = "acidBurn", realName = "Libby"), events[0].user)
45
         assertEquals("#crashandburn", events[0].channel)
45
         assertEquals("#crashandburn", events[0].channel)
46
     }
46
     }
51
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", params("#crashandburn", "*", "Libby")))
51
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", params("#crashandburn", "*", "Libby")))
52
         assertEquals(1, events.size)
52
         assertEquals(1, events.size)
53
 
53
 
54
-        assertEquals(TestConstants.time, events[0].time)
54
+        assertEquals(TestConstants.time, events[0].metadata.time)
55
         assertEquals(User("acidburn", "libby", "root.localhost", realName = "Libby"), events[0].user)
55
         assertEquals(User("acidburn", "libby", "root.localhost", realName = "Libby"), events[0].user)
56
         assertEquals("#crashandburn", events[0].channel)
56
         assertEquals("#crashandburn", events[0].channel)
57
     }
57
     }

+ 2
- 2
src/test/kotlin/com/dmdirc/ktirc/messages/KickProcessorTest.kt View File

22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "KICK", params("#crashandburn", "zeroCool")))
22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "KICK", params("#crashandburn", "zeroCool")))
23
         assertEquals(1, events.size)
23
         assertEquals(1, events.size)
24
 
24
 
25
-        assertEquals(TestConstants.time, events[0].time)
25
+        assertEquals(TestConstants.time, events[0].metadata.time)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
27
         assertEquals("#crashandburn", events[0].channel)
27
         assertEquals("#crashandburn", events[0].channel)
28
         assertEquals("zeroCool", events[0].victim)
28
         assertEquals("zeroCool", events[0].victim)
35
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "KICK", params("#crashandburn", "zeroCool", "Hack the planet!")))
35
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "KICK", params("#crashandburn", "zeroCool", "Hack the planet!")))
36
         assertEquals(1, events.size)
36
         assertEquals(1, events.size)
37
 
37
 
38
-        assertEquals(TestConstants.time, events[0].time)
38
+        assertEquals(TestConstants.time, events[0].metadata.time)
39
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
39
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
40
         assertEquals("#crashandburn", events[0].channel)
40
         assertEquals("#crashandburn", events[0].channel)
41
         assertEquals("zeroCool", events[0].victim)
41
         assertEquals("zeroCool", events[0].victim)

+ 8
- 8
src/test/kotlin/com/dmdirc/ktirc/messages/ModeProcessorTest.kt View File

21
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "221", params("acidBurn", "+hax")))
21
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "221", params("acidBurn", "+hax")))
22
         assertEquals(1, events.size)
22
         assertEquals(1, events.size)
23
 
23
 
24
-        assertEquals(TestConstants.time, events[0].time)
24
+        assertEquals(TestConstants.time, events[0].metadata.time)
25
         assertEquals("acidBurn", events[0].target)
25
         assertEquals("acidBurn", events[0].target)
26
         assertEquals("+hax", events[0].modes)
26
         assertEquals("+hax", events[0].modes)
27
         assertEquals(0, events[0].arguments.size)
27
         assertEquals(0, events[0].arguments.size)
34
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "221", params("acidBurn", "+hax", "123", "467")))
34
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "221", params("acidBurn", "+hax", "123", "467")))
35
         assertEquals(1, events.size)
35
         assertEquals(1, events.size)
36
 
36
 
37
-        assertEquals(TestConstants.time, events[0].time)
37
+        assertEquals(TestConstants.time, events[0].metadata.time)
38
         assertEquals("acidBurn", events[0].target)
38
         assertEquals("acidBurn", events[0].target)
39
         assertEquals("+hax", events[0].modes)
39
         assertEquals("+hax", events[0].modes)
40
         assertEquals(2, events[0].arguments.size)
40
         assertEquals(2, events[0].arguments.size)
49
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("acidBurn", "+hax")))
49
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("acidBurn", "+hax")))
50
         assertEquals(1, events.size)
50
         assertEquals(1, events.size)
51
 
51
 
52
-        assertEquals(TestConstants.time, events[0].time)
52
+        assertEquals(TestConstants.time, events[0].metadata.time)
53
         assertEquals("acidBurn", events[0].target)
53
         assertEquals("acidBurn", events[0].target)
54
         assertEquals("+hax", events[0].modes)
54
         assertEquals("+hax", events[0].modes)
55
         assertEquals(0, events[0].arguments.size)
55
         assertEquals(0, events[0].arguments.size)
62
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("acidBurn", "+hax", "123", "467")))
62
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("acidBurn", "+hax", "123", "467")))
63
         assertEquals(1, events.size)
63
         assertEquals(1, events.size)
64
 
64
 
65
-        assertEquals(TestConstants.time, events[0].time)
65
+        assertEquals(TestConstants.time, events[0].metadata.time)
66
         assertEquals("acidBurn", events[0].target)
66
         assertEquals("acidBurn", events[0].target)
67
         assertEquals("+hax", events[0].modes)
67
         assertEquals("+hax", events[0].modes)
68
         assertEquals(2, events[0].arguments.size)
68
         assertEquals(2, events[0].arguments.size)
77
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "324", params("acidBurn", "#thegibson", "+hax")))
77
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "324", params("acidBurn", "#thegibson", "+hax")))
78
         assertEquals(1, events.size)
78
         assertEquals(1, events.size)
79
 
79
 
80
-        assertEquals(TestConstants.time, events[0].time)
80
+        assertEquals(TestConstants.time, events[0].metadata.time)
81
         assertEquals("#thegibson", events[0].target)
81
         assertEquals("#thegibson", events[0].target)
82
         assertEquals("+hax", events[0].modes)
82
         assertEquals("+hax", events[0].modes)
83
         assertEquals(0, events[0].arguments.size)
83
         assertEquals(0, events[0].arguments.size)
90
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "324", params("acidBurn", "#thegibson", "+hax", "123", "467")))
90
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "324", params("acidBurn", "#thegibson", "+hax", "123", "467")))
91
         assertEquals(1, events.size)
91
         assertEquals(1, events.size)
92
 
92
 
93
-        assertEquals(TestConstants.time, events[0].time)
93
+        assertEquals(TestConstants.time, events[0].metadata.time)
94
         assertEquals("#thegibson", events[0].target)
94
         assertEquals("#thegibson", events[0].target)
95
         assertEquals("+hax", events[0].modes)
95
         assertEquals("+hax", events[0].modes)
96
         assertEquals(2, events[0].arguments.size)
96
         assertEquals(2, events[0].arguments.size)
105
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("#thegibson", "+hax")))
105
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("#thegibson", "+hax")))
106
         assertEquals(1, events.size)
106
         assertEquals(1, events.size)
107
 
107
 
108
-        assertEquals(TestConstants.time, events[0].time)
108
+        assertEquals(TestConstants.time, events[0].metadata.time)
109
         assertEquals("#thegibson", events[0].target)
109
         assertEquals("#thegibson", events[0].target)
110
         assertEquals("+hax", events[0].modes)
110
         assertEquals("+hax", events[0].modes)
111
         assertEquals(0, events[0].arguments.size)
111
         assertEquals(0, events[0].arguments.size)
118
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("#thegibson", "+hax", "123", "467")))
118
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "MODE", params("#thegibson", "+hax", "123", "467")))
119
         assertEquals(1, events.size)
119
         assertEquals(1, events.size)
120
 
120
 
121
-        assertEquals(TestConstants.time, events[0].time)
121
+        assertEquals(TestConstants.time, events[0].metadata.time)
122
         assertEquals("#thegibson", events[0].target)
122
         assertEquals("#thegibson", events[0].target)
123
         assertEquals("+hax", events[0].modes)
123
         assertEquals("+hax", events[0].modes)
124
         assertEquals(2, events[0].arguments.size)
124
         assertEquals(2, events[0].arguments.size)

+ 4
- 4
src/test/kotlin/com/dmdirc/ktirc/messages/MotdProcessorTest.kt View File

24
         assertEquals(1, events.size)
24
         assertEquals(1, events.size)
25
 
25
 
26
         val event = events[0] as MotdFinished
26
         val event = events[0] as MotdFinished
27
-        assertEquals(TestConstants.time, events[0].time)
27
+        assertEquals(TestConstants.time, events[0].metadata.time)
28
         assertTrue(event.missing)
28
         assertTrue(event.missing)
29
     }
29
     }
30
 
30
 
35
         assertEquals(1, events.size)
35
         assertEquals(1, events.size)
36
 
36
 
37
         val event = events[0] as MotdFinished
37
         val event = events[0] as MotdFinished
38
-        assertEquals(TestConstants.time, events[0].time)
38
+        assertEquals(TestConstants.time, events[0].metadata.time)
39
         assertFalse(event.missing)
39
         assertFalse(event.missing)
40
     }
40
     }
41
 
41
 
46
         assertEquals(1, events.size)
46
         assertEquals(1, events.size)
47
 
47
 
48
         val event = events[0] as MotdLineReceived
48
         val event = events[0] as MotdLineReceived
49
-        assertEquals(TestConstants.time, event.time)
49
+        assertEquals(TestConstants.time, event.metadata.time)
50
         assertEquals("- the.gibson MOTD -", event.line)
50
         assertEquals("- the.gibson MOTD -", event.line)
51
         assertTrue(event.first)
51
         assertTrue(event.first)
52
     }
52
     }
58
         assertEquals(1, events.size)
58
         assertEquals(1, events.size)
59
 
59
 
60
         val event = events[0] as MotdLineReceived
60
         val event = events[0] as MotdLineReceived
61
-        assertEquals(TestConstants.time, event.time)
61
+        assertEquals(TestConstants.time, event.metadata.time)
62
         assertEquals("Hack the planet!", event.line)
62
         assertEquals("Hack the planet!", event.line)
63
         assertFalse(event.first)
63
         assertFalse(event.first)
64
     }
64
     }

+ 4
- 4
src/test/kotlin/com/dmdirc/ktirc/messages/NoticeProcessorTest.kt View File

25
         assertEquals(1, events.size)
25
         assertEquals(1, events.size)
26
 
26
 
27
         val event = events[0] as NoticeReceived
27
         val event = events[0] as NoticeReceived
28
-        assertEquals(TestConstants.time, event.time)
28
+        assertEquals(TestConstants.time, event.metadata.time)
29
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
29
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
30
         assertEquals("#crashandburn", event.target)
30
         assertEquals("#crashandburn", event.target)
31
         assertEquals("hack the planet!", event.message)
31
         assertEquals("hack the planet!", event.message)
38
         assertEquals(1, events.size)
38
         assertEquals(1, events.size)
39
 
39
 
40
         val event = events[0] as NoticeReceived
40
         val event = events[0] as NoticeReceived
41
-        assertEquals(TestConstants.time, event.time)
41
+        assertEquals(TestConstants.time, event.metadata.time)
42
         assertEquals(User("*"), event.user)
42
         assertEquals(User("*"), event.user)
43
         assertEquals("#crashandburn", event.target)
43
         assertEquals("#crashandburn", event.target)
44
         assertEquals("hack the planet!", event.message)
44
         assertEquals("hack the planet!", event.message)
51
         assertEquals(1, events.size)
51
         assertEquals(1, events.size)
52
 
52
 
53
         val event = events[0] as CtcpReplyReceived
53
         val event = events[0] as CtcpReplyReceived
54
-        assertEquals(TestConstants.time, event.time)
54
+        assertEquals(TestConstants.time, event.metadata.time)
55
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
55
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
56
         assertEquals("#crashandburn", event.target)
56
         assertEquals("#crashandburn", event.target)
57
         assertEquals("PING", event.type)
57
         assertEquals("PING", event.type)
65
         assertEquals(1, events.size)
65
         assertEquals(1, events.size)
66
 
66
 
67
         val event = events[0] as CtcpReplyReceived
67
         val event = events[0] as CtcpReplyReceived
68
-        assertEquals(TestConstants.time, event.time)
68
+        assertEquals(TestConstants.time, event.metadata.time)
69
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
69
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
70
         assertEquals("#crashandburn", event.target)
70
         assertEquals("#crashandburn", event.target)
71
         assertEquals("PING", event.type)
71
         assertEquals("PING", event.type)

+ 2
- 2
src/test/kotlin/com/dmdirc/ktirc/messages/PartProcessorTest.kt View File

22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "PART", params("#crashandburn")))
22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "PART", params("#crashandburn")))
23
         assertEquals(1, events.size)
23
         assertEquals(1, events.size)
24
 
24
 
25
-        assertEquals(TestConstants.time, events[0].time)
25
+        assertEquals(TestConstants.time, events[0].metadata.time)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
27
         assertEquals("#crashandburn", events[0].channel)
27
         assertEquals("#crashandburn", events[0].channel)
28
         assertEquals("", events[0].reason)
28
         assertEquals("", events[0].reason)
34
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "PART", params("#crashandburn", "Hack the planet!")))
34
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "PART", params("#crashandburn", "Hack the planet!")))
35
         assertEquals(1, events.size)
35
         assertEquals(1, events.size)
36
 
36
 
37
-        assertEquals(TestConstants.time, events[0].time)
37
+        assertEquals(TestConstants.time, events[0].metadata.time)
38
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
38
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
39
         assertEquals("#crashandburn", events[0].channel)
39
         assertEquals("#crashandburn", events[0].channel)
40
         assertEquals("Hack the planet!", events[0].reason)
40
         assertEquals("Hack the planet!", events[0].reason)

+ 8
- 8
src/test/kotlin/com/dmdirc/ktirc/messages/PrivmsgProcessorTest.kt View File

28
         assertEquals(1, events.size)
28
         assertEquals(1, events.size)
29
 
29
 
30
         val event = events[0] as MessageReceived
30
         val event = events[0] as MessageReceived
31
-        assertEquals(TestConstants.time, event.time)
31
+        assertEquals(TestConstants.time, event.metadata.time)
32
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
32
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
33
         assertEquals("#crashandburn", event.target)
33
         assertEquals("#crashandburn", event.target)
34
         assertEquals("hack the planet!", event.message)
34
         assertEquals("hack the planet!", event.message)
42
         assertEquals(1, events.size)
42
         assertEquals(1, events.size)
43
 
43
 
44
         val event = events[0] as MessageReceived
44
         val event = events[0] as MessageReceived
45
-        assertEquals(TestConstants.time, event.time)
45
+        assertEquals(TestConstants.time, event.metadata.time)
46
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
46
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
47
         assertEquals("#crashandburn", event.target)
47
         assertEquals("#crashandburn", event.target)
48
         assertEquals("hack the planet!", event.message)
48
         assertEquals("hack the planet!", event.message)
56
         assertEquals(1, events.size)
56
         assertEquals(1, events.size)
57
 
57
 
58
         val event = events[0] as ActionReceived
58
         val event = events[0] as ActionReceived
59
-        assertEquals(TestConstants.time, event.time)
59
+        assertEquals(TestConstants.time, event.metadata.time)
60
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
60
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
61
         assertEquals("#crashandburn", event.target)
61
         assertEquals("#crashandburn", event.target)
62
         assertEquals("hacks the planet", event.action)
62
         assertEquals("hacks the planet", event.action)
70
         assertEquals(1, events.size)
70
         assertEquals(1, events.size)
71
 
71
 
72
         val event = events[0] as ActionReceived
72
         val event = events[0] as ActionReceived
73
-        assertEquals(TestConstants.time, event.time)
73
+        assertEquals(TestConstants.time, event.metadata.time)
74
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
74
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
75
         assertEquals("#crashandburn", event.target)
75
         assertEquals("#crashandburn", event.target)
76
         assertEquals("hacks the planet", event.action)
76
         assertEquals("hacks the planet", event.action)
84
         assertEquals(1, events.size)
84
         assertEquals(1, events.size)
85
 
85
 
86
         val event = events[0] as ActionReceived
86
         val event = events[0] as ActionReceived
87
-        assertEquals(TestConstants.time, event.time)
87
+        assertEquals(TestConstants.time, event.metadata.time)
88
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
88
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
89
         assertEquals("#crashandburn", event.target)
89
         assertEquals("#crashandburn", event.target)
90
         assertEquals("", event.action)
90
         assertEquals("", event.action)
98
         assertEquals(1, events.size)
98
         assertEquals(1, events.size)
99
 
99
 
100
         val event = events[0] as ActionReceived
100
         val event = events[0] as ActionReceived
101
-        assertEquals(TestConstants.time, event.time)
101
+        assertEquals(TestConstants.time, event.metadata.time)
102
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
102
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
103
         assertEquals("#crashandburn", event.target)
103
         assertEquals("#crashandburn", event.target)
104
         assertEquals("hacks the planet", event.action)
104
         assertEquals("hacks the planet", event.action)
112
         assertEquals(1, events.size)
112
         assertEquals(1, events.size)
113
 
113
 
114
         val event = events[0] as CtcpReceived
114
         val event = events[0] as CtcpReceived
115
-        assertEquals(TestConstants.time, event.time)
115
+        assertEquals(TestConstants.time, event.metadata.time)
116
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
116
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
117
         assertEquals("#crashandburn", event.target)
117
         assertEquals("#crashandburn", event.target)
118
         assertEquals("PING", event.type)
118
         assertEquals("PING", event.type)
126
         assertEquals(1, events.size)
126
         assertEquals(1, events.size)
127
 
127
 
128
         val event = events[0] as CtcpReceived
128
         val event = events[0] as CtcpReceived
129
-        assertEquals(TestConstants.time, event.time)
129
+        assertEquals(TestConstants.time, event.metadata.time)
130
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
130
         assertEquals(User("acidburn", "libby", "root.localhost"), event.user)
131
         assertEquals("#crashandburn", event.target)
131
         assertEquals("#crashandburn", event.target)
132
         assertEquals("PING", event.type)
132
         assertEquals("PING", event.type)

+ 2
- 2
src/test/kotlin/com/dmdirc/ktirc/messages/QuitProcessorTest.kt View File

22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "QUIT", emptyList()))
22
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "QUIT", emptyList()))
23
         assertEquals(1, events.size)
23
         assertEquals(1, events.size)
24
 
24
 
25
-        assertEquals(TestConstants.time, events[0].time)
25
+        assertEquals(TestConstants.time, events[0].metadata.time)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
26
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
27
         assertEquals("", events[0].reason)
27
         assertEquals("", events[0].reason)
28
     }
28
     }
33
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "QUIT", params("Hack the planet!")))
33
                 IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "QUIT", params("Hack the planet!")))
34
         assertEquals(1, events.size)
34
         assertEquals(1, events.size)
35
 
35
 
36
-        assertEquals(TestConstants.time, events[0].time)
36
+        assertEquals(TestConstants.time, events[0].metadata.time)
37
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
37
         assertEquals(User("acidburn", "libby", "root.localhost"), events[0].user)
38
         assertEquals("Hack the planet!", events[0].reason)
38
         assertEquals("Hack the planet!", events[0].reason)
39
     }
39
     }

+ 4
- 4
src/test/kotlin/com/dmdirc/ktirc/messages/TopicProcessorTest.kt View File

29
         assertEquals(1, events.size)
29
         assertEquals(1, events.size)
30
 
30
 
31
         val event = events[0] as ChannelTopicDiscovered
31
         val event = events[0] as ChannelTopicDiscovered
32
-        assertEquals(TestConstants.time, event.time)
32
+        assertEquals(TestConstants.time, event.metadata.time)
33
         assertEquals("#thegibson", event.channel)
33
         assertEquals("#thegibson", event.channel)
34
         assertEquals("Hack the planet!", event.topic)
34
         assertEquals("Hack the planet!", event.topic)
35
     }
35
     }
40
         assertEquals(1, events.size)
40
         assertEquals(1, events.size)
41
 
41
 
42
         val event = events[0] as ChannelTopicDiscovered
42
         val event = events[0] as ChannelTopicDiscovered
43
-        assertEquals(TestConstants.time, event.time)
43
+        assertEquals(TestConstants.time, event.metadata.time)
44
         assertEquals("#thegibson", event.channel)
44
         assertEquals("#thegibson", event.channel)
45
         assertNull(event.topic)
45
         assertNull(event.topic)
46
     }
46
     }
51
         assertEquals(1, events.size)
51
         assertEquals(1, events.size)
52
 
52
 
53
         val event = events[0] as ChannelTopicMetadataDiscovered
53
         val event = events[0] as ChannelTopicMetadataDiscovered
54
-        assertEquals(TestConstants.time, event.time)
54
+        assertEquals(TestConstants.time, event.metadata.time)
55
         assertEquals("#thegibson", event.channel)
55
         assertEquals("#thegibson", event.channel)
56
         assertEquals("zeroCool", event.user.nickname)
56
         assertEquals("zeroCool", event.user.nickname)
57
         assertEquals(TestConstants.otherTime, event.setTime)
57
         assertEquals(TestConstants.otherTime, event.setTime)
63
         assertEquals(1, events.size)
63
         assertEquals(1, events.size)
64
 
64
 
65
         val event = events[0] as ChannelTopicChanged
65
         val event = events[0] as ChannelTopicChanged
66
-        assertEquals(TestConstants.time, event.time)
66
+        assertEquals(TestConstants.time, event.metadata.time)
67
         assertEquals(User("acidBurn", "acidB", "the.gibson"), event.user)
67
         assertEquals(User("acidBurn", "acidB", "the.gibson"), event.user)
68
         assertEquals("#thegibson", event.channel)
68
         assertEquals("#thegibson", event.channel)
69
         assertEquals("Hack the planet!", event.topic)
69
         assertEquals("Hack the planet!", event.topic)

+ 1
- 1
src/test/kotlin/com/dmdirc/ktirc/messages/WelcomeProcessorTest.kt View File

22
         val events = processor.process(IrcMessage(emptyMap(), "thegibson.com".toByteArray(), "001", params(
22
         val events = processor.process(IrcMessage(emptyMap(), "thegibson.com".toByteArray(), "001", params(
23
                 "acidBurn", "Welcome to the Internet Relay Network, acidBurn!burn@hacktheplanet.com")))
23
                 "acidBurn", "Welcome to the Internet Relay Network, acidBurn!burn@hacktheplanet.com")))
24
         assertEquals(1, events.size)
24
         assertEquals(1, events.size)
25
-        assertEquals(TestConstants.time, events[0].time)
25
+        assertEquals(TestConstants.time, events[0].metadata.time)
26
         assertEquals("acidBurn", events[0].localNick)
26
         assertEquals("acidBurn", events[0].localNick)
27
         assertEquals("thegibson.com", events[0].server)
27
         assertEquals("thegibson.com", events[0].server)
28
     }
28
     }

+ 10
- 3
src/test/kotlin/com/dmdirc/ktirc/model/IrcMessageTest.kt View File

15
     fun `Gets UTC time from ServerTime tag if present`() {
15
     fun `Gets UTC time from ServerTime tag if present`() {
16
         currentTimeZoneProvider = { ZoneId.of("Z") }
16
         currentTimeZoneProvider = { ZoneId.of("Z") }
17
         val message = IrcMessage(hashMapOf(MessageTag.ServerTime to "1995-09-15T09:00:00.0000Z"), null, "", emptyList())
17
         val message = IrcMessage(hashMapOf(MessageTag.ServerTime to "1995-09-15T09:00:00.0000Z"), null, "", emptyList())
18
-        assertEquals(LocalDateTime.parse("1995-09-15T09:00:00"), message.time)
18
+        assertEquals(LocalDateTime.parse("1995-09-15T09:00:00"), message.metadata.time)
19
     }
19
     }
20
 
20
 
21
     @Test
21
     @Test
22
     fun `Converts time in ServerTime tag to local timezone`() {
22
     fun `Converts time in ServerTime tag to local timezone`() {
23
         currentTimeZoneProvider = { ZoneId.of("America/New_York") }
23
         currentTimeZoneProvider = { ZoneId.of("America/New_York") }
24
         val message = IrcMessage(hashMapOf(MessageTag.ServerTime to "1995-09-15T09:00:00.0000Z"), null, "", emptyList())
24
         val message = IrcMessage(hashMapOf(MessageTag.ServerTime to "1995-09-15T09:00:00.0000Z"), null, "", emptyList())
25
-        assertEquals(LocalDateTime.parse("1995-09-15T05:00:00"), message.time)
25
+        assertEquals(LocalDateTime.parse("1995-09-15T05:00:00"), message.metadata.time)
26
     }
26
     }
27
 
27
 
28
     @Test
28
     @Test
29
     fun `Uses current local time if no tag present`() {
29
     fun `Uses current local time if no tag present`() {
30
         currentTimeProvider = { TestConstants.time }
30
         currentTimeProvider = { TestConstants.time }
31
         val message = IrcMessage(emptyMap(), null, "", emptyList())
31
         val message = IrcMessage(emptyMap(), null, "", emptyList())
32
-        assertEquals(LocalDateTime.parse("1995-09-15T09:00:00"), message.time)
32
+        assertEquals(LocalDateTime.parse("1995-09-15T09:00:00"), message.metadata.time)
33
+    }
34
+
35
+    @Test
36
+    fun `populates batch field if present`() {
37
+        currentTimeProvider = { TestConstants.time }
38
+        val message = IrcMessage(hashMapOf(MessageTag.Batch to "abc123"), null, "", emptyList())
39
+        assertEquals("abc123", message.metadata.batchId)
33
     }
40
     }
34
 
41
 
35
     @Test
42
     @Test

Loading…
Cancel
Save