Skip to content
Snippets Groups Projects
Verified Commit 0ea84be6 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

About 30% faster connections

parent c18a5675
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -46,6 +46,18 @@ class IrcChannel(
"UserModes" to QVariant.of(initUserModes(), Type.QVariantMap)
) + initProperties()
private inline fun QVariant_?.indexed(index: Int?) = this?.let {
index?.let { i ->
it.valueOr<QVariantList>(::emptyList)[i]
} ?: it
}
fun fromVariantMap(properties: QVariantMap, i: Int? = null) {
initSetChanModes(properties["ChanModes"].indexed(i).valueOr(::emptyMap))
initSetUserModes(properties["UserModes"].indexed(i).valueOr(::emptyMap))
initSetProperties(properties, i)
}
override fun fromVariantMap(properties: QVariantMap) {
initSetChanModes(properties["ChanModes"].valueOr(::emptyMap))
initSetUserModes(properties["UserModes"].valueOr(::emptyMap))
......@@ -100,10 +112,10 @@ class IrcChannel(
joinIrcUsersInternal(users, modes)
}
override fun initSetProperties(properties: QVariantMap) {
setTopic(properties["topic"].valueOr(this::topic))
setPassword(properties["password"].valueOr(this::password))
setEncrypted(properties["encrypted"].valueOr(this::encrypted))
override fun initSetProperties(properties: QVariantMap, i: Int?) {
setTopic(properties["topic"].indexed(i).valueOr(this::topic))
setPassword(properties["password"].indexed(i).valueOr(this::password))
setEncrypted(properties["encrypted"].indexed(i).valueOr(this::encrypted))
}
fun isKnownUser(ircUser: IrcUser): Boolean {
......
......@@ -19,10 +19,7 @@
package de.kuschku.libquassel.quassel.syncables
import de.kuschku.libquassel.protocol.QVariant
import de.kuschku.libquassel.protocol.QVariantMap
import de.kuschku.libquassel.protocol.Type
import de.kuschku.libquassel.protocol.valueOr
import de.kuschku.libquassel.protocol.*
import de.kuschku.libquassel.quassel.ExtendedFeature
import de.kuschku.libquassel.quassel.syncables.interfaces.IIrcUser
import de.kuschku.libquassel.session.SignalProxy
......@@ -42,6 +39,9 @@ class IrcUser(
}
override fun toVariantMap() = initProperties()
fun fromVariantMap(properties: QVariantMap, index: Int? = null) {
initSetProperties(properties, index)
}
override fun fromVariantMap(properties: QVariantMap) {
initSetProperties(properties)
}
......@@ -68,25 +68,31 @@ class IrcUser(
"userModes" to QVariant.of(userModes(), Type.QString)
)
override fun initSetProperties(properties: QVariantMap) {
setUser(properties["user"].valueOr(this::user))
setHost(properties["host"].valueOr(this::host))
setNick(properties["nick"].valueOr(this::nick))
setRealName(properties["realName"].valueOr(this::realName))
setAccount(properties["account"].valueOr(this::account))
setAway(properties["away"].valueOr(this::isAway))
setAwayMessage(properties["awayMessage"].valueOr(this::awayMessage))
setIdleTime(properties["idleTime"].valueOr(this::idleTime))
setLoginTime(properties["loginTime"].valueOr(this::loginTime))
setServer(properties["server"].valueOr(this::server))
setIrcOperator(properties["ircOperator"].valueOr(this::ircOperator))
setLastAwayMessageTime(properties["lastAwayMessageTime"].valueOr {
Instant.ofEpochSecond(properties["lastAwayMessage"].valueOr(this::lastAwayMessage).toLong())
private inline fun QVariant_?.indexed(index: Int?) = this?.let {
index?.let { i ->
it.valueOr<QVariantList>(::emptyList)[i]
} ?: it
}
override fun initSetProperties(properties: QVariantMap, i: Int?) {
setUser(properties["user"].indexed(i).valueOr(this::user))
setHost(properties["host"].indexed(i).valueOr(this::host))
setNick(properties["nick"].indexed(i).valueOr(this::nick))
setRealName(properties["realName"].indexed(i).valueOr(this::realName))
setAccount(properties["account"].indexed(i).valueOr(this::account))
setAway(properties["away"].indexed(i).valueOr(this::isAway))
setAwayMessage(properties["awayMessage"].indexed(i).valueOr(this::awayMessage))
setIdleTime(properties["idleTime"].indexed(i).valueOr(this::idleTime))
setLoginTime(properties["loginTime"].indexed(i).valueOr(this::loginTime))
setServer(properties["server"].indexed(i).valueOr(this::server))
setIrcOperator(properties["ircOperator"].indexed(i).valueOr(this::ircOperator))
setLastAwayMessageTime(properties["lastAwayMessageTime"].indexed(i).valueOr {
Instant.ofEpochSecond(properties["lastAwayMessage"].indexed(i).valueOr(this::lastAwayMessage).toLong())
})
setWhoisServiceReply(properties["whoisServiceReply"].valueOr(this::whoisServiceReply))
setSuserHost(properties["suserHost"].valueOr(this::suserHost))
setEncrypted(properties["encrypted"].valueOr(this::encrypted))
setUserModes(properties["userModes"].valueOr(this::userModes))
setWhoisServiceReply(properties["whoisServiceReply"].indexed(i).valueOr(this::whoisServiceReply))
setSuserHost(properties["suserHost"].indexed(i).valueOr(this::suserHost))
setEncrypted(properties["encrypted"].indexed(i).valueOr(this::encrypted))
setUserModes(properties["userModes"].indexed(i).valueOr(this::userModes))
}
fun updates(): Observable<IrcUser> = hasChangedNotification.map { this }
......
......@@ -32,7 +32,6 @@ import de.kuschku.libquassel.util.irc.IrcCaseMappers
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import java.nio.ByteBuffer
import java.nio.charset.Charset
import java.util.*
class Network constructor(
......@@ -192,11 +191,11 @@ class Network constructor(
if (info.identity > 0 && info.identity != identity())
setIdentity(info.identity)
if (info.codecForServer != codecForServer())
setCodecForServer(Charset.forName(info.codecForServer))
setCodecForServer(info.codecForServer)
if (info.codecForEncoding != codecForEncoding())
setCodecForEncoding(Charset.forName(info.codecForEncoding))
setCodecForEncoding(info.codecForEncoding)
if (info.codecForDecoding != codecForDecoding())
setCodecForDecoding(Charset.forName(info.codecForDecoding))
setCodecForDecoding(info.codecForDecoding)
// FIXME compare components
if (info.serverList.isNotEmpty())
setServerList(info.serverList.map { QVariant.of(it.toVariantMap(), QType.Network_Server) })
......@@ -348,19 +347,19 @@ class Network constructor(
capValue?.contains(saslMechanism, ignoreCase = true) ?: false)
}
fun newIrcUser(hostMask: String, initData: QVariantMap = emptyMap()): IrcUser {
fun newIrcUser(hostMask: String, initData: QVariantMap = emptyMap(),
index: Int? = null): IrcUser {
val nick = caseMapper.toLowerCase(HostmaskHelper.nick(hostMask))
val user = ircUser(nick)
return if (user == null) {
val ircUser = IrcUser(hostMask, this, proxy)
ircUser.init()
if (initData.isNotEmpty()) {
ircUser.fromVariantMap(initData)
ircUser.fromVariantMap(initData, index)
ircUser.initialized = true
}
proxy.synchronize(ircUser)
_ircUsers[nick] = ircUser
val mask = ircUser.hostMask()
live_ircUsers.onNext(_ircUsers)
ircUser
} else {
......@@ -375,13 +374,14 @@ class Network constructor(
fun ircUsers() = _ircUsers.values.toList()
fun ircUserCount(): UInt = _ircUsers.size
fun newIrcChannel(channelName: String, initData: QVariantMap = emptyMap()): IrcChannel =
fun newIrcChannel(channelName: String, initData: QVariantMap = emptyMap(),
index: Int? = null): IrcChannel =
ircChannel(channelName).let { channel ->
return if (channel == null) {
val ircChannel = IrcChannel(channelName, this, proxy)
ircChannel.init()
if (initData.isNotEmpty()) {
ircChannel.fromVariantMap(initData)
ircChannel.fromVariantMap(initData, index)
ircChannel.initialized = true
}
proxy.synchronize(ircChannel)
......@@ -402,18 +402,18 @@ class Network constructor(
fun ircChannels() = _ircChannels.values.toList()
fun ircChannelCount(): UInt = _ircChannels.size
fun codecForServer(): String = _codecForServer.name()
fun codecForEncoding(): String = _codecForEncoding.name()
fun codecForDecoding(): String = _codecForDecoding.name()
fun setCodecForDecoding(codec: Charset) {
fun codecForServer(): String = _codecForServer
fun codecForEncoding(): String = _codecForEncoding
fun codecForDecoding(): String = _codecForDecoding
fun setCodecForDecoding(codec: String) {
_codecForDecoding = codec
}
fun setCodecForEncoding(codec: Charset) {
fun setCodecForEncoding(codec: String) {
_codecForEncoding = codec
}
fun setCodecForServer(codec: Charset) {
fun setCodecForServer(codec: String) {
_codecForServer = codec
}
......@@ -615,27 +615,6 @@ class Network constructor(
setCodecForServer(Charsets.ISO_8859_1.decode(codecName).toString())
}
fun setCodecForDecoding(codecName: String) {
val charset = Charset.availableCharsets()[codecName]
if (charset != null) {
setCodecForDecoding(charset)
}
}
fun setCodecForEncoding(codecName: String) {
val charset = Charset.availableCharsets()[codecName]
if (charset != null) {
setCodecForEncoding(charset)
}
}
fun setCodecForServer(codecName: String) {
val charset = Charset.availableCharsets()[codecName]
if (charset != null) {
setCodecForServer(charset)
}
}
override fun addSupport(param: String, value: String?) {
_supports[param] = value
}
......@@ -773,25 +752,13 @@ class Network constructor(
val users: Map<String, QVariant_> = usersAndChannels["Users"].valueOr(::emptyMap)
val userKeys = users.keys
users["nick"].valueOr<QVariantList>(::emptyList).forEachIndexed { index, nick ->
val data = mutableMapOf<String, QVariant_>()
for (it in userKeys) {
val value = users[it].value<QVariantList>()?.get(index)
if (value != null)
data[it] = value
}
newIrcUser(nick.value(""), data)
newIrcUser(nick.value(""), users, index)
}
val channels: Map<String, QVariant_> = usersAndChannels["Channels"].valueOr(::emptyMap)
val channelKeys = channels.keys
channels["name"].valueOr<QVariantList>(::emptyList).forEachIndexed { index, nick ->
val data = mutableMapOf<String, QVariant_>()
for (it in channelKeys) {
val value = channels[it].value<QVariantList>()?.get(index)
if (value != null)
data[it] = value
}
newIrcChannel(nick.value(""), data)
newIrcChannel(nick.value(""), channels, index)
}
}
......@@ -1022,17 +989,17 @@ class Network constructor(
field = value
live_networkInfo.onNext(Unit)
}
private var _codecForServer: Charset = Charsets.UTF_8
private var _codecForServer: String = "UTF_8"
set(value) {
field = value
live_networkInfo.onNext(Unit)
}
private var _codecForEncoding: Charset = Charsets.UTF_8
private var _codecForEncoding: String = "UTF_8"
set(value) {
field = value
live_networkInfo.onNext(Unit)
}
private var _codecForDecoding: Charset = Charsets.UTF_8
private var _codecForDecoding: String = "UTF_8"
set(value) {
field = value
live_networkInfo.onNext(Unit)
......
......@@ -33,7 +33,7 @@ interface IIrcChannel : ISyncableObject {
fun initSetUserModes(usermodes: QVariantMap)
fun initProperties(): QVariantMap
fun initSetProperties(properties: QVariantMap)
fun initSetProperties(properties: QVariantMap, i: Int? = null)
@Slot
fun addChannelMode(mode: Char, value: String?)
......
......@@ -28,7 +28,7 @@ import org.threeten.bp.Instant
@Syncable(name = "IrcUser")
interface IIrcUser : ISyncableObject {
fun initProperties(): QVariantMap
fun initSetProperties(properties: QVariantMap)
fun initSetProperties(properties: QVariantMap, index: Int? = null)
@Slot
fun addUserModes(modes: String)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment