ソースを参照

Add support for per-channel quit events

tags/v0.3.0
Chris Smith 5年前
コミット
6e6c4d446c

+ 1
- 0
CHANGELOG ファイルの表示

9
     * ServerConnected event is emitted as soon as the socket is connected
9
     * ServerConnected event is emitted as soon as the socket is connected
10
     * ServerReady event is emitted after logging in, negotiating, etc
10
     * ServerReady event is emitted after logging in, negotiating, etc
11
   * Added extra debugging to show what type of events are being dispatched
11
   * Added extra debugging to show what type of events are being dispatched
12
+  * Added ChannelQuit event, raised for each channel a user is in when they quit
12
   * (Internal) Event handlers can now return more events to emit
13
   * (Internal) Event handlers can now return more events to emit
13
 
14
 
14
 v0.2.1
15
 v0.2.1

+ 9
- 4
src/main/kotlin/com/dmdirc/ktirc/events/ChannelStateHandler.kt ファイルの表示

15
             is ChannelParted -> handlePart(client, event)
15
             is ChannelParted -> handlePart(client, event)
16
             is ChannelNamesReceived -> handleNamesReceived(client, event)
16
             is ChannelNamesReceived -> handleNamesReceived(client, event)
17
             is ChannelNamesFinished -> handleNamesFinished(client, event)
17
             is ChannelNamesFinished -> handleNamesFinished(client, event)
18
-            is UserQuit -> handleQuit(client, event)
18
+            is UserQuit -> return handleQuit(client, event)
19
         }
19
         }
20
         return emptyList()
20
         return emptyList()
21
     }
21
     }
61
         }
61
         }
62
     }
62
     }
63
 
63
 
64
-    private fun handleQuit(client: IrcClient, event: UserQuit) {
65
-        client.channelState.forEach { it.users -= event.user.nickname }
66
-    }
64
+    private fun handleQuit(client: IrcClient, event: UserQuit) = sequence {
65
+        client.channelState.forEach {
66
+            if (it.users.contains(event.user.nickname)) {
67
+                it.users -= event.user.nickname
68
+                yield(ChannelQuit(event.time, event.user, it.name, event.reason))
69
+            }
70
+        }
71
+    }.toList()
67
 
72
 
68
 }
73
 }

+ 3
- 0
src/main/kotlin/com/dmdirc/ktirc/events/Events.kt ファイルの表示

29
 /** Raised when a user leaves a channel. */
29
 /** Raised when a user leaves a channel. */
30
 class ChannelParted(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
30
 class ChannelParted(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
31
 
31
 
32
+/** Raised when a user quits, and is in a channel. */
33
+class ChannelQuit(time: LocalDateTime, val user: User, val channel: String, val reason: String = "") : IrcEvent(time)
34
+
32
 /** Raised when a batch of the channel's member list has been received. More batches may follow. */
35
 /** Raised when a batch of the channel's member list has been received. More batches may follow. */
33
 class ChannelNamesReceived(time: LocalDateTime, val channel: String, val names: List<String>) : IrcEvent(time)
36
 class ChannelNamesReceived(time: LocalDateTime, val channel: String, val names: List<String>) : IrcEvent(time)
34
 
37
 

+ 35
- 0
src/test/kotlin/com/dmdirc/ktirc/events/ChannelStateHandlerTest.kt ファイルの表示

161
         assertTrue("acidburn" in channelStateMap["#chat"]!!.users)
161
         assertTrue("acidburn" in channelStateMap["#chat"]!!.users)
162
     }
162
     }
163
 
163
 
164
+
165
+    @Test
166
+    fun `ChannelStateHandler raises ChannelQuit event for each channel a user quits from`() = runBlocking {
167
+        with (ChannelState("#thegibson") { CaseMapping.Rfc }) {
168
+            users += ChannelUser("ZeroCool")
169
+            channelStateMap += this
170
+        }
171
+
172
+        with (ChannelState("#dumpsterdiving") { CaseMapping.Rfc }) {
173
+            users += ChannelUser("ZeroCool")
174
+            channelStateMap += this
175
+        }
176
+
177
+        with (ChannelState("#chat") { CaseMapping.Rfc }) {
178
+            users += ChannelUser("AcidBurn")
179
+            channelStateMap += this
180
+        }
181
+
182
+        val events = handler.processEvent(ircClient, UserQuit(TestConstants.time, User("zerocool", "dade", "root.localhost"), "Hack the planet!"))
183
+
184
+        val names = mutableListOf<String>()
185
+        assertEquals(2, events.size)
186
+        events.forEach { event ->
187
+            (event as ChannelQuit).let {
188
+                assertEquals(TestConstants.time, it.time)
189
+                assertEquals("zerocool", it.user.nickname)
190
+                assertEquals("Hack the planet!", it.reason)
191
+                names.add(it.channel)
192
+            }
193
+        }
194
+
195
+        assertTrue("#thegibson" in names)
196
+        assertTrue("#dumpsterdiving" in names)
197
+    }
198
+
164
 }
199
 }

読み込み中…
キャンセル
保存