Browse Source

Handle away numerics

Closes #15
tags/v1.1.0
Chris Smith 5 years ago
parent
commit
dade80ced7

+ 1
- 1
CHANGELOG View File

3
  * Away support:
3
  * Away support:
4
    * Added sendAway() method
4
    * Added sendAway() method
5
    * Added UserAway event and fanned-out ChannelAway
5
    * Added UserAway event and fanned-out ChannelAway
6
-   * away message is now updated in the UserState
6
+   * Away message is now updated in the UserState
7
  * (Internal) improved the way byte buffers are used to
7
  * (Internal) improved the way byte buffers are used to
8
    reduce array copying and clean up code
8
    reduce array copying and clean up code
9
 
9
 

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

11
 
11
 
12
 internal const val RPL_UMODEIS = "221"
12
 internal const val RPL_UMODEIS = "221"
13
 
13
 
14
+internal const val RPL_UNAWAY = "305"
15
+internal const val RPL_NOWAWAY = "306"
14
 internal const val RPL_CHANNELMODEIS = "324"
16
 internal const val RPL_CHANNELMODEIS = "324"
15
 internal const val RPL_NOTOPIC = "331"
17
 internal const val RPL_NOTOPIC = "331"
16
 internal const val RPL_TOPIC = "332"
18
 internal const val RPL_TOPIC = "332"

+ 6
- 1
src/main/kotlin/com/dmdirc/ktirc/messages/processors/AwayProcessor.kt View File

1
 package com.dmdirc.ktirc.messages.processors
1
 package com.dmdirc.ktirc.messages.processors
2
 
2
 
3
 import com.dmdirc.ktirc.events.UserAway
3
 import com.dmdirc.ktirc.events.UserAway
4
+import com.dmdirc.ktirc.messages.RPL_NOWAWAY
5
+import com.dmdirc.ktirc.messages.RPL_UNAWAY
4
 import com.dmdirc.ktirc.model.IrcMessage
6
 import com.dmdirc.ktirc.model.IrcMessage
7
+import com.dmdirc.ktirc.model.User
5
 import com.dmdirc.ktirc.model.asUser
8
 import com.dmdirc.ktirc.model.asUser
6
 
9
 
7
 internal class AwayProcessor : MessageProcessor {
10
 internal class AwayProcessor : MessageProcessor {
8
 
11
 
9
-    override val commands = arrayOf("AWAY")
12
+    override val commands = arrayOf("AWAY", RPL_UNAWAY, RPL_NOWAWAY)
10
 
13
 
11
     override fun process(message: IrcMessage) = sequence {
14
     override fun process(message: IrcMessage) = sequence {
12
         when (message.command) {
15
         when (message.command) {
13
             "AWAY" -> message.prefix?.let { yield(UserAway(message.metadata, it.asUser(), message.awayMessage)) }
16
             "AWAY" -> message.prefix?.let { yield(UserAway(message.metadata, it.asUser(), message.awayMessage)) }
17
+            RPL_NOWAWAY -> yield(UserAway(message.metadata, User(String(message.params[0])), ""))
18
+            RPL_UNAWAY -> yield(UserAway(message.metadata, User(String(message.params[0])), null))
14
         }
19
         }
15
     }.toList()
20
     }.toList()
16
 
21
 

+ 24
- 0
src/test/kotlin/com/dmdirc/ktirc/messages/processors/AwayProcessorTest.kt View File

42
         assertNull(event.message)
42
         assertNull(event.message)
43
     }
43
     }
44
 
44
 
45
+    @Test
46
+    fun `raises away changed event for local user on NOWAWAY`() {
47
+        val events = AwayProcessor().process(
48
+                IrcMessage(emptyMap(), ":the.server".toByteArray(), "306", params("acidBurn", "You have been marked as being away")))
49
+        assertEquals(1, events.size)
50
+
51
+        val event = events[0]
52
+        assertEquals(TestConstants.time, event.metadata.time)
53
+        assertEquals(User("acidBurn"), event.user)
54
+        assertEquals("", event.message)
55
+    }
56
+
57
+    @Test
58
+    fun `raises away changed event for local user on UNAWAY`() {
59
+        val events = AwayProcessor().process(
60
+                IrcMessage(emptyMap(), ":the.server".toByteArray(), "305", params("acidBurn", "You are no longer marked as being away")))
61
+        assertEquals(1, events.size)
62
+
63
+        val event = events[0]
64
+        assertEquals(TestConstants.time, event.metadata.time)
65
+        assertEquals(User("acidBurn"), event.user)
66
+        assertNull(event.message)
67
+    }
68
+
45
     @Test
69
     @Test
46
     fun `does nothing on away if prefix missing`() {
70
     fun `does nothing on away if prefix missing`() {
47
         val events = AwayProcessor().process(IrcMessage(emptyMap(), null, "AWAY", params("*")))
71
         val events = AwayProcessor().process(IrcMessage(emptyMap(), null, "AWAY", params("*")))

Loading…
Cancel
Save