Browse Source

Handle extended joins

tags/v0.1.0
Chris Smith 5 years ago
parent
commit
b025789870

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

@@ -2,13 +2,22 @@ package com.dmdirc.ktirc.messages
2 2
 
3 3
 import com.dmdirc.ktirc.events.ChannelJoined
4 4
 import com.dmdirc.ktirc.model.IrcMessage
5
+import com.dmdirc.ktirc.model.User
5 6
 
6 7
 internal class JoinProcessor : MessageProcessor {
7 8
 
8 9
     override val commands = arrayOf("JOIN")
9 10
 
10 11
     override fun process(message: IrcMessage) = message.sourceUser?.let { user ->
12
+        user.addExtendedJoinFields(message.params)
11 13
         listOf(ChannelJoined(message.time, user, String(message.params[0])))
12 14
     } ?: emptyList()
13 15
 
16
+    private fun User.addExtendedJoinFields(params: List<ByteArray>) {
17
+        if (params.size == 3) {
18
+            String(params[1]).let { account = if (it == "*") null else it }
19
+            realName = String(params[2])
20
+        }
21
+    }
22
+
14 23
 }

+ 7
- 6
src/main/kotlin/com/dmdirc/ktirc/model/CapabilitiesState.kt View File

@@ -17,23 +17,24 @@ enum class CapabilitiesNegotiationState {
17 17
 
18 18
 }
19 19
 
20
+@Suppress("unused")
20 21
 sealed class Capability(val name: String) {
21 22
     // Capabilities that enable more information in message tags:
22
-    object ServerTimeMessageTag : Capability("server-time") // TODO: Parse this and expose time in events
23
-    object UserAccountMessageTag : Capability("account-tag") // TODO: Add accounts to user info
23
+    object ServerTimeMessageTag : Capability("server-time")
24
+    object UserAccountMessageTag : Capability("account-tag")
24 25
 
25 26
     // Capabilities that extend existing commands to supply extra information:
26 27
     object HostsInNamesReply : Capability("userhost-in-names")
27 28
     object MultipleUserModePrefixes : Capability("multi-prefix")
28
-    object AccountAndRealNameInJoinMessages : Capability("extended-join") // TODO: Parse this
29
+    object AccountAndRealNameInJoinMessages : Capability("extended-join")
29 30
 
30 31
     // Capabilities that affect how messages are sent/received:
31 32
     object EchoMessages : Capability("echo-message")
32 33
 
33 34
     // Capabilities that notify us of changes to other clients:
34
-    object AccountChangeMessages : Capability("account-notify")
35
-    object AwayStateMessages : Capability("away-notify")
36
-    object HostChangeMessages : Capability("chghost")
35
+    object AccountChangeMessages : Capability("account-notify") // TODO: Add processor
36
+    object AwayStateMessages : Capability("away-notify") // TODO: Add processor
37
+    object HostChangeMessages : Capability("chghost") // TODO: Add processor
37 38
 }
38 39
 
39 40
 val capabilities: Map<String, Capability> by lazy {

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

@@ -32,4 +32,26 @@ internal class JoinProcessorTest {
32 32
         assertEquals(0, events.size)
33 33
     }
34 34
 
35
+    @Test
36
+    fun `JoinProcessor adds real name and account from extended join`() {
37
+        val events = JoinProcessor().process(
38
+                IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", listOf("#crashandburn", "acidBurn", "Libby").map { it.toByteArray() }))
39
+        assertEquals(1, events.size)
40
+
41
+        assertEquals(TestConstants.time, events[0].time)
42
+        assertEquals(User("acidburn", "libby", "root.localhost", account = "acidBurn", realName = "Libby"), events[0].user)
43
+        assertEquals("#crashandburn", events[0].channel)
44
+    }
45
+
46
+    @Test
47
+    fun `JoinProcessor ignores account if the user is not authed`() {
48
+        val events = JoinProcessor().process(
49
+                IrcMessage(emptyMap(), "acidburn!libby@root.localhost".toByteArray(), "JOIN", listOf("#crashandburn", "*", "Libby").map { it.toByteArray() }))
50
+        assertEquals(1, events.size)
51
+
52
+        assertEquals(TestConstants.time, events[0].time)
53
+        assertEquals(User("acidburn", "libby", "root.localhost", realName = "Libby"), events[0].user)
54
+        assertEquals("#crashandburn", events[0].channel)
55
+    }
56
+
35 57
 }

Loading…
Cancel
Save