Skip to content
Snippets Groups Projects
Commit 24e1f8dd authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Handle avatars with unverified idents

parent ac39b921
Branches
Tags
No related merge requests found
......@@ -20,7 +20,7 @@ data class DisplayMessage(
val tag = Tag(content.messageId, content.followUp, isSelected, isExpanded, isMarkerLine)
val avatarUrl = content.sender.let {
Regex("[us]id(\\d+)").matchEntire(HostmaskHelper.user(it))?.groupValues?.lastOrNull()?.let {
Regex("~?[us]id(\\d+)").matchEntire(HostmaskHelper.user(it))?.groupValues?.lastOrNull()?.let {
"https://www.irccloud.com/avatar-redirect/$it"
}
}
......
package de.kuschku.libquassel.protocol
import de.kuschku.libquassel.protocol.primitive.serializer.Serializer
import java.nio.ByteBuffer
import java.nio.CharBuffer
sealed class QVariant<T> constructor(val data: T?, val type: Type, val serializer: Serializer<T>) {
class Typed<T> internal constructor(data: T?, type: Type, serializer: Serializer<T>) :
QVariant<T>(data, type, serializer) {
override fun toString() = "QVariant.Typed(${type.serializableName}, ${toString(data)})"
override fun toString() = "QVariant.Typed(${type.serializableName}, $data})"
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Typed<*>) return false
if (data != other.data) return false
if (type != other.type) return false
return true
}
override fun hashCode(): Int {
var result = data?.hashCode() ?: 0
result = 31 * result + type.hashCode()
return result
}
}
class Custom<T> internal constructor(data: T?, val qtype: QType, serializer: Serializer<T>) :
QVariant<T>(data, qtype.type, serializer) {
override fun toString() = "QVariant.Custom($qtype, ${toString(data)})"
override fun toString() = "QVariant.Custom($qtype, $data)"
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Custom<*>) return false
if (data != other.data) return false
if (qtype != other.qtype) return false
return true
}
override fun hashCode(): Int {
var result = data?.hashCode() ?: 0
result = 31 * result + qtype.hashCode()
return result
}
}
fun or(defValue: T): T {
......@@ -29,13 +57,6 @@ sealed class QVariant<T> constructor(val data: T?, val type: Type, val serialize
}
}
inline fun toString(data: Any?) = when (data) {
is ByteBuffer -> data.array()?.contentToString()
is CharBuffer -> data.array()?.contentToString()
is Array<*> -> data.contentToString()
else -> data.toString()
}
inline fun <reified U> QVariant_?.value(): U? = this?.value<U?>(null)
inline fun <reified U> QVariant_?.value(defValue: U): U = this?.data as? U ?: defValue
......
......@@ -34,12 +34,10 @@ class CertManager constructor(
override fun setSslCert(encoded: ByteBuffer?) {
_sslCert = encoded
super.setSslCert(encoded)
}
override fun setSslKey(encoded: ByteBuffer?) {
_sslKey = encoded
super.setSslKey(encoded)
}
private var _sslKey: ByteBuffer? = null
......
package de.kuschku.libquassel
import de.kuschku.libquassel.protocol.*
import de.kuschku.libquassel.quassel.ProtocolFeature
import de.kuschku.libquassel.quassel.QuasselFeatures
import de.kuschku.libquassel.session.BacklogStorage
import de.kuschku.libquassel.session.Session
import de.kuschku.libquassel.session.SocketAddress
import de.kuschku.libquassel.util.compatibility.reference.JavaHandlerService
import org.junit.BeforeClass
import org.junit.Test
import org.threeten.bp.Instant
import java.security.cert.X509Certificate
import java.util.logging.LogManager
import javax.net.ssl.X509TrustManager
class ConnectionUnitTest {
/*
companion object {
@JvmStatic
@BeforeClass
......@@ -21,9 +34,9 @@ class ConnectionUnitTest {
ClientData(
identifier = "libquassel test",
buildDate = Instant.EPOCH,
clientFeatures = Quassel_Feature.of(*LegacyFeature.validValues),
clientFeatures = QuasselFeatures.all(),
protocolFeatures = Protocol_Feature.of(ProtocolFeature.TLS, ProtocolFeature.Compression),
supportedProtocols = listOf(Protocol.Datastream),
supportedProtocols = listOf(Protocol.Datastream)
), object : X509TrustManager {
override fun checkClientTrusted(p0: Array<out X509Certificate>?, p1: String?) {
}
......@@ -38,9 +51,7 @@ class ConnectionUnitTest {
override fun clearMessages(bufferId: BufferId, idRange: IntRange) = Unit
override fun clearMessages(bufferId: BufferId) = Unit
override fun clearMessages() = Unit
}, user to pass,
) {}
}, user to pass, {}, {})
session.join()
}
*/
}
\ No newline at end of file
package de.kuschku.libquassel
import de.kuschku.libquassel.protocol.QType
import de.kuschku.libquassel.protocol.QVariant
import de.kuschku.libquassel.protocol.Type
import de.kuschku.libquassel.protocol.primitive.serializer.*
import de.kuschku.libquassel.quassel.QuasselFeatures
import de.kuschku.libquassel.util.nio.ChainedByteBuffer
......@@ -106,79 +103,6 @@ class SerializerUnitTest {
assertEquals("Test", roundTrip(StringSerializer.C, "Test"))
}
@Test
fun variantListSerializer() {
val value = listOf(
QVariant.of(1, Type.Int),
QVariant.of(ByteBuffer.wrap(byteArrayOf(
66,
97,
99,
107,
108,
111,
103,
77,
97,
110,
97,
103,
101,
114,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
)), Type.QByteArray),
QVariant.of(ByteBuffer.wrap(byteArrayOf(
114,
101,
113,
117,
101,
115,
116,
66,
97,
99,
107,
108,
111,
103,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
)), Type.QByteArray),
QVariant.of(1873, QType.BufferId),
QVariant.of(-1, QType.MsgId),
QVariant.of(-1, QType.MsgId),
QVariant.of(20, Type.Int),
QVariant.of(0, Type.Int)
)
assert(value == roundTrip(VariantListSerializer, value))
}
companion object {
fun <T> roundTrip(serializer: Serializer<T>, value: T,
features: QuasselFeatures = QuasselFeatures.all()): T {
......
......@@ -182,7 +182,7 @@ class QuasselViewModel : ViewModel() {
user.realName(),
user.isAway(),
network.support("CASEMAPPING"),
Regex("[us]id(\\d+)").matchEntire(user.user())?.groupValues?.lastOrNull()?.let {
Regex("~?[us]id(\\d+)").matchEntire(user.user())?.groupValues?.lastOrNull()?.let {
"https://www.irccloud.com/avatar-redirect/$it"
}
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment