♻️ Slightly improve messy expression
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 9 Apr 2020 17:10:02 +0000 (19:10 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 9 Apr 2020 17:10:02 +0000 (19:10 +0200)
src/main/kotlin/net/pterodactylus/sone/web/FreenetSessionProvider.kt

index 80bacdf..8928f12 100644 (file)
@@ -41,10 +41,13 @@ class FreenetSessionProvider @Inject constructor(private val soneProvider: SoneP
                        sessionManager.useSession(toadletContext)
                                        ?.removeAttribute("Sone.CurrentSone")
                } else {
-                       (sessionManager.useSession(toadletContext)
-                                       ?: sessionManager.createSession(UUID.randomUUID().toString(), toadletContext))
+                       sessionManager.getOrCreateSession(toadletContext)
                                        ?.setAttribute("Sone.CurrentSone", sone.id)
                }
        }
 
+       private fun SessionManager.getOrCreateSession(toadletContext: ToadletContext) =
+                       useSession(toadletContext)
+                                       ?: createSession(UUID.randomUUID().toString(), toadletContext)
+
 }