From: David ‘Bombe’ Roden Date: Thu, 9 Apr 2020 17:10:02 +0000 (+0200) Subject: ♻️ Slightly improve messy expression X-Git-Tag: v82^2~17 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ecfd4c5a91d204ce4c001d19fa600cf42ac4cf43;p=Sone.git ♻️ Slightly improve messy expression --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/FreenetSessionProvider.kt b/src/main/kotlin/net/pterodactylus/sone/web/FreenetSessionProvider.kt index 80bacdf..8928f12 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/FreenetSessionProvider.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/FreenetSessionProvider.kt @@ -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) + }