Add com.shr4pnel.ferretirc.irc package to model the live state of IRC
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.shr4pnel.ferretirc.irc
|
||||
|
||||
import com.shr4pnel.ferretirc.net.messages.ClientMessage
|
||||
import com.shr4pnel.ferretirc.net.messages.ServerMessage
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
import kotlinx.coroutines.flow.onSubscription
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
|
||||
class Server(private val msgBuffer: SharedFlow<ServerMessage>, private val outgoingMessages: Channel<ClientMessage>, private val scope: CoroutineScope) {
|
||||
lateinit var features: ISupportFeatures
|
||||
private set
|
||||
|
||||
var channels: Set<IRCChannel> = setOf()
|
||||
private set
|
||||
|
||||
suspend fun fetchChannels(): Set<IRCChannel> {
|
||||
val buffer = mutableSetOf<IRCChannel>()
|
||||
|
||||
msgBuffer
|
||||
.onSubscription { outgoingMessages.send(ClientMessage.List()) }
|
||||
.filterIsInstance<ServerMessage.Numeric>()
|
||||
.takeWhile { it !is ServerMessage.Numeric.RPL_LISTEND }
|
||||
.filterIsInstance<ServerMessage.Numeric.RPL_LIST>()
|
||||
.collect { buffer.add(IRCChannel(it.chanName, it.clientCount, it.topic)) }
|
||||
|
||||
channels = buffer.toSortedSet(compareBy { it.chanName })
|
||||
return channels
|
||||
}
|
||||
|
||||
fun fetchFeatures() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user