Browse Source

Track user away state

tags/v1.1.0
Chris Smith 5 years ago
parent
commit
57d0747a5a

+ 1
- 0
CHANGELOG View File

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

+ 2
- 2
docs/index.adoc View File

@@ -1189,9 +1189,9 @@ See <<UserAccountChanged>>
1189 1189
 Accounts are automatically added to `User` properties in events
1190 1190
 
1191 1191
 | https://ircv3.net/specs/extensions/away-notify-3.1.html[away-notify] v3.1
1192
-| {set:cellbgcolor:#eeeeaa} Partial support
1192
+| {set:cellbgcolor:#a7eeaa} Supported
1193 1193
 | {set:cellbgcolor!}
1194
-See <<UserAway>>. State not yet tracked.
1194
+See <<UserAway>>.
1195 1195
 
1196 1196
 | https://ircv3.net/specs/extensions/batch-3.2.html[batch] v3.2
1197 1197
 | {set:cellbgcolor:#a7eeaa} Supported

+ 11
- 0
src/main/kotlin/com/dmdirc/ktirc/events/handlers/UserStateHandler.kt View File

@@ -16,6 +16,7 @@ internal class UserStateHandler : EventHandler {
16 16
             is UserNickChanged -> handleNickChanged(client, event)
17 17
             is UserHostChanged -> handleHostChanged(client, event)
18 18
             is UserQuit -> handleQuit(client.userState, event)
19
+            is UserAway -> handleAway(client.userState, event)
19 20
         }
20 21
     }
21 22
 
@@ -83,4 +84,14 @@ internal class UserStateHandler : EventHandler {
83 84
         state -= event.user
84 85
     }
85 86
 
87
+    private fun handleAway(state: UserState, event: UserAway) {
88
+        state[event.user]?.details?.let {
89
+            when (event.message) {
90
+                null -> it.awayMessage = null
91
+                "" -> if (it.awayMessage == null) it.awayMessage = ""
92
+                else -> it.awayMessage = event.message
93
+            }
94
+        }
95
+    }
96
+
86 97
 }

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

@@ -94,7 +94,7 @@ sealed class Capability(vararg val names:  String) {
94 94
     object AccountChangeMessages : Capability("account-notify")
95 95
 
96 96
     /** Receive a notification when a user's away state changes. */
97
-    object AwayStateMessages : Capability("away-notify") // TODO: Add processor
97
+    object AwayStateMessages : Capability("away-notify")
98 98
 
99 99
     /** Receive a notification when a user's host changes, instead of a quit/join. */
100 100
     object HostChangeMessages : Capability("chghost")

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

@@ -239,4 +239,34 @@ internal class UserStateHandlerTest {
239 239
         assertEquals("root.gibson", fakeUserState["acidBurn"]?.details?.hostname)
240 240
     }
241 241
 
242
+    @Test
243
+    fun `updates details for user back events`() {
244
+        val user = User("acidBurn", "libby", "root.localhost")
245
+        fakeUserState += User("AcidBurn", awayMessage = "Hacking the planet")
246
+
247
+        handler.processEvent(ircClient, UserAway(EventMetadata(TestConstants.time), user, null))
248
+
249
+        assertNull(fakeUserState["acidBurn"]?.details?.awayMessage)
250
+    }
251
+
252
+    @Test
253
+    fun `does not update away details for less detailed events`() {
254
+        val user = User("acidBurn", "libby", "root.localhost")
255
+        fakeUserState += User("AcidBurn", awayMessage = "Hacking the planet")
256
+
257
+        handler.processEvent(ircClient, UserAway(EventMetadata(TestConstants.time), user, ""))
258
+
259
+        assertEquals("Hacking the planet", fakeUserState["acidBurn"]?.details?.awayMessage)
260
+    }
261
+
262
+    @Test
263
+    fun `updates away details for away message`() {
264
+        val user = User("acidBurn", "libby", "root.localhost")
265
+        fakeUserState += User("AcidBurn")
266
+
267
+        handler.processEvent(ircClient, UserAway(EventMetadata(TestConstants.time), user, "Hacking the planet"))
268
+
269
+        assertEquals("Hacking the planet", fakeUserState["acidBurn"]?.details?.awayMessage)
270
+    }
271
+
242 272
 }

Loading…
Cancel
Save