...
 
Commits (3)
......@@ -304,11 +304,11 @@ class QuasselNotificationBackend @Inject constructor(
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val senderColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> senderColors[senderColorIndex]
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> senderColors[senderColorIndex]
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
if (self) selfColor
else senderColors[senderColorIndex]
MessageSettings.ColorizeNicknamesMode.NONE -> selfColor
MessageSettings.SenderColorMode.NONE -> selfColor
}
val avatarList = AvatarHelper.avatar(messageSettings, ident, realName, avatarUrl, size)
......
......@@ -21,7 +21,7 @@ package de.kuschku.quasseldroid.settings
data class MessageSettings(
val showPrefix: ShowPrefixMode = ShowPrefixMode.HIGHEST,
val colorizeNicknames: ColorizeNicknamesMode = ColorizeNicknamesMode.ALL_BUT_MINE,
val colorizeNicknames: SenderColorMode = SenderColorMode.ALL_BUT_MINE,
val colorizeMirc: Boolean = true,
val useMonospace: Boolean = false,
val textSize: Int = 14,
......@@ -41,7 +41,7 @@ data class MessageSettings(
val replaceEmoji: Boolean = true
) {
enum class ColorizeNicknamesMode {
enum class SenderColorMode {
ALL,
ALL_BUT_MINE,
NONE;
......
......@@ -79,7 +79,7 @@ object Settings {
""
) ?: ""
) ?: MessageSettings.DEFAULT.showPrefix,
colorizeNicknames = MessageSettings.ColorizeNicknamesMode.of(
colorizeNicknames = MessageSettings.SenderColorMode.of(
getString(
context.getString(R.string.preference_colorize_nicknames_key),
""
......
......@@ -114,10 +114,10 @@ class ToolbarFragment : ServiceBoundFragment() {
val nickName = user.nick()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
user.network().isMyNick(nickName)
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
val fallbackDrawable = colorContext.buildTextDrawable(user.nick(), useSelfColor)
......
......@@ -19,13 +19,9 @@
package de.kuschku.quasseldroid.ui.chat.add.query
import android.graphics.Typeface
import android.os.Bundle
import android.text.Editable
import android.text.SpannableString
import android.text.TextWatcher
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -65,6 +61,7 @@ import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.helper.loadWithFallbacks
import de.kuschku.quasseldroid.util.helper.styledAttributes
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
import de.kuschku.quasseldroid.viewmodel.data.Avatar
......@@ -98,6 +95,9 @@ class QueryCreateFragment : ServiceBoundFragment() {
@Inject
lateinit var modelHelper: QueryCreateViewModelHelper
@Inject
lateinit var contentFormatter: ContentFormatter
private var hasSelectedNetwork = false
private var networkId = NetworkId(0)
......@@ -260,30 +260,13 @@ class QueryCreateFragment : ServiceBoundFragment() {
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE -> it.self
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE -> it.self
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
fun formatNick(nick: CharSequence): CharSequence {
val spannableString = SpannableString(nick)
spannableString.setSpan(
ForegroundColorSpan(senderColor),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
StyleSpan(Typeface.BOLD),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
return spannableString
}
it.copy(
displayNick = formatNick(it.nick),
displayNick = contentFormatter.formatNick(it.nick),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
initial = initial,
modes = when (messageSettings.showPrefix) {
......
......@@ -297,7 +297,7 @@ class ArchiveListAdapter(
}
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
name.text = item.props.network.networkName
name.text = item.props.name
bufferId = item.props.info.bufferId
networkId = item.props.info.networkId
......@@ -396,7 +396,7 @@ class ArchiveListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......@@ -487,7 +487,7 @@ class ArchiveListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......@@ -573,7 +573,7 @@ class ArchiveListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......
......@@ -218,7 +218,7 @@ class BufferListAdapter(
}
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
name.text = item.props.network.networkName
name.text = item.props.name
bufferId = item.props.info.bufferId
networkId = item.props.info.networkId
......@@ -317,7 +317,7 @@ class BufferListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......@@ -408,7 +408,7 @@ class BufferListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......
......@@ -19,10 +19,6 @@
package de.kuschku.quasseldroid.ui.chat.input
import android.graphics.Typeface
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import de.kuschku.libquassel.protocol.BufferId
......@@ -45,6 +41,7 @@ import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.emoji.EmojiData
import de.kuschku.quasseldroid.util.helper.styledAttributes
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.viewmodel.data.AutoCompleteItem
import de.kuschku.quasseldroid.viewmodel.data.BufferStatus
......@@ -56,6 +53,7 @@ class AutoCompleteHelper(
private val autoCompleteSettings: AutoCompleteSettings,
private val messageSettings: MessageSettings,
private val ircFormatDeserializer: IrcFormatDeserializer,
private val contentFormatter: ContentFormatter,
private val helper: EditorViewModelHelper
) {
private var autocompleteListener: ((AutoCompletionState) -> Unit)? = null
......@@ -110,31 +108,13 @@ class AutoCompleteHelper(
?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE -> it.self
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE -> it.self
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
fun formatNick(nick: CharSequence): CharSequence {
val spannableString = SpannableString(nick)
spannableString.setSpan(
ForegroundColorSpan(senderColor),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
StyleSpan(Typeface.BOLD),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
return spannableString
}
it.copy(
displayNick = formatNick(it.nick),
displayNick = contentFormatter.formatNick(it.nick),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
modes = when (messageSettings.showPrefix) {
MessageSettings.ShowPrefixMode.ALL ->
......
......@@ -41,6 +41,7 @@ import de.kuschku.quasseldroid.settings.AutoCompleteSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.util.emoji.EmojiData
import de.kuschku.quasseldroid.util.helper.*
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.IrcFormatSerializer
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
......@@ -87,6 +88,9 @@ class ChatlineFragment : ServiceBoundFragment() {
@Inject
lateinit var ircFormatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var ircFormatSerializer: IrcFormatSerializer
......@@ -120,6 +124,7 @@ class ChatlineFragment : ServiceBoundFragment() {
autoCompleteSettings,
messageSettings,
ircFormatDeserializer,
contentFormatter,
modelHelper
)
......
......@@ -266,10 +266,10 @@ class QuasselMessageRenderer @Inject constructor(
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
message.content.flag.hasFlag(Message_Flag.Self)
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
......@@ -301,10 +301,10 @@ class QuasselMessageRenderer @Inject constructor(
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
message.content.flag.hasFlag(Message_Flag.Self)
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
......
......@@ -19,11 +19,7 @@
package de.kuschku.quasseldroid.ui.chat.nicks
import android.graphics.Typeface
import android.os.Bundle
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -53,6 +49,7 @@ import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.helper.loadWithFallbacks
import de.kuschku.quasseldroid.util.helper.styledAttributes
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
import de.kuschku.quasseldroid.viewmodel.data.Avatar
......@@ -73,6 +70,9 @@ class NickListFragment : ServiceBoundFragment() {
@Inject
lateinit var ircFormatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var modelHelper: ChatViewModelHelper
......@@ -115,30 +115,14 @@ class NickListFragment : ServiceBoundFragment() {
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE -> it.self
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE -> it.self
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
fun formatNick(nick: CharSequence): CharSequence {
val spannableString = SpannableString(nick)
spannableString.setSpan(
ForegroundColorSpan(senderColor),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
StyleSpan(Typeface.BOLD),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
return spannableString
}
it.copy(
displayNick = formatNick(it.nick),
displayNick = contentFormatter.formatNick(it.nick),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
initial = initial,
modes = when (messageSettings.showPrefix) {
......
......@@ -38,6 +38,7 @@ import de.kuschku.quasseldroid.settings.AutoCompleteSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.ui.chat.input.*
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.IrcFormatSerializer
import de.kuschku.quasseldroid.util.ui.settings.fragment.Savable
......@@ -67,6 +68,9 @@ class TopicFragment : ServiceBoundSettingsFragment(), Savable {
@Inject
lateinit var formatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var formatSerializer: IrcFormatSerializer
......@@ -88,6 +92,7 @@ class TopicFragment : ServiceBoundSettingsFragment(), Savable {
autoCompleteSettings,
messageSettings,
formatDeserializer,
contentFormatter,
modelHelper
)
......
......@@ -38,6 +38,7 @@ import de.kuschku.quasseldroid.settings.AppearanceSettings
import de.kuschku.quasseldroid.settings.AutoCompleteSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.ui.chat.input.*
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.IrcFormatSerializer
import de.kuschku.quasseldroid.util.ui.settings.fragment.Changeable
......@@ -71,6 +72,9 @@ class AliasItemFragment : ServiceBoundSettingsFragment(), Savable, Changeable {
@Inject
lateinit var formatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var formatSerializer: IrcFormatSerializer
......@@ -99,6 +103,7 @@ class AliasItemFragment : ServiceBoundSettingsFragment(), Savable, Changeable {
autoCompleteSettings,
messageSettings,
formatDeserializer,
contentFormatter,
modelHelper
)
......
......@@ -61,6 +61,7 @@ import de.kuschku.quasseldroid.util.avatars.MatrixApi
import de.kuschku.quasseldroid.util.avatars.MatrixAvatarInfo
import de.kuschku.quasseldroid.util.helper.*
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.spans.IrcItalicSpan
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
import de.kuschku.quasseldroid.util.ui.BetterLinkMovementMethod
......@@ -133,6 +134,9 @@ class UserInfoFragment : ServiceBoundFragment() {
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var ircFormatDeserializer: IrcFormatDeserializer
@Inject
lateinit var messageSettings: MessageSettings
......@@ -318,8 +322,7 @@ class UserInfoFragment : ServiceBoundFragment() {
}
}
}
nick.text = user.nick
nick.text = ircFormatDeserializer.formatString(user.nick, messageSettings.colorizeMirc)
val (content, _) = contentFormatter.formatContent(
user.realName ?: "",
networkId = user.networkId
......@@ -337,11 +340,19 @@ class UserInfoFragment : ServiceBoundFragment() {
account.text = user.account
accountContainer.visibleIf(!user.account.isNullOrBlank())
ident.text = user.user
identContainer.visibleIf(!user.user.isNullOrBlank())
val (userIdent, _) = contentFormatter.formatContent(
user.user ?: "",
networkId = user.networkId
)
ident.text = userIdent
identContainer.visibleIf(userIdent.isNotBlank())
host.text = user.host
hostContainer.visibleIf(!user.host.isNullOrBlank())
val (userHost, _) = contentFormatter.formatContent(
user.host ?: "",
networkId = user.networkId
)
host.text = userHost
hostContainer.visibleIf(userHost.isNotBlank())
server.text = user.server
serverContainer.visibleIf(!user.server.isNullOrBlank())
......
......@@ -183,11 +183,11 @@ class ContentFormatter @Inject constructor(
showHostmask: Boolean = false, senderColors: IntArray = this.senderColors,
@ColorInt selfColor: Int = this.selfColor) =
when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL ->
MessageSettings.SenderColorMode.ALL ->
formatNickImpl(sender, false, !highlight, showHostmask, senderColors, selfColor)
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
formatNickImpl(sender, self, !highlight, showHostmask, senderColors, selfColor)
MessageSettings.ColorizeNicknamesMode.NONE ->
MessageSettings.SenderColorMode.NONE ->
formatNickImpl(sender, false, false, showHostmask, senderColors, selfColor)
}
......
......@@ -19,8 +19,13 @@
package de.kuschku.quasseldroid.util.irc.format.spans
import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.text.TextPaint
import android.text.style.URLSpan
import android.util.Log
import android.view.View
class QuasselURLSpan(text: String, private val highlight: Boolean) : URLSpan(text) {
override fun updateDrawState(ds: TextPaint?) {
......@@ -29,4 +34,14 @@ class QuasselURLSpan(text: String, private val highlight: Boolean) : URLSpan(tex
ds.isUnderlineText = true
}
}
override fun onClick(widget: View) {
try {
widget.context?.startActivity(Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(url)
})
} catch (e: ActivityNotFoundException) {
Log.w("QuasselURLSpan", "Actvity was not found for $url")
}
}
}
......@@ -25,6 +25,7 @@ import de.kuschku.quasseldroid.settings.AppearanceSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.util.ColorContext
import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.viewmodel.data.BufferListItem
import de.kuschku.quasseldroid.viewmodel.data.BufferProps
......@@ -35,10 +36,19 @@ class BufferPresenter @Inject constructor(
val appearanceSettings: AppearanceSettings,
val messageSettings: MessageSettings,
val ircFormatDeserializer: IrcFormatDeserializer,
val contentFormatter: ContentFormatter,
val colorContext: ColorContext
) {
fun render(props: BufferProps): BufferProps {
return props.copy(
name = when {
props.info.type.hasFlag(Buffer_Type.QueryBuffer) ->
ircFormatDeserializer.formatString(props.info.bufferName, messageSettings.colorizeMirc)
props.info.type.hasFlag(Buffer_Type.StatusBuffer) ->
props.network.networkName
else ->
props.info.bufferName ?: ""
},
description = ircFormatDeserializer.formatString(
props.description.toString(),
colorize = messageSettings.colorizeMirc
......@@ -47,10 +57,10 @@ class BufferPresenter @Inject constructor(
props.ircUser?.let {
val nickName = it.nick()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
props.ircUser?.network()?.isMyNick(nickName) == true
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
colorContext.buildTextDrawable(it.nick(), useSelfColor)
......
......@@ -428,4 +428,45 @@ class ExpressionMatchTest {
assertFalse(invalidRegex.match("network"))
assertFalse(invalidRegex.match("testnetwork"))
}
// Tests imported from https://github.com/ircdocs/parser-tests/blob/master/tests/mask-match.yaml
@Test
fun testDan() {
val mask1 = ExpressionMatch("*@127.0.0.1",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask1.match("coolguy!ab@127.0.0.1"))
assertTrue(mask1.match("cooldud3!~bc@127.0.0.1"))
assertFalse(mask1.match("coolguy!ab@127.0.0.5"))
assertFalse(mask1.match("cooldud3!~d@124.0.0.1"))
val mask2 = ExpressionMatch("cool*@*",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask2.match("coolguy!ab@127.0.0.1"))
assertTrue(mask2.match("cooldud3!~bc@127.0.0.1"))
assertTrue(mask2.match("cool132!ab@example.com"))
assertFalse(mask2.match("koolguy!ab@127.0.0.5"))
assertFalse(mask2.match("cooodud3!~d@124.0.0.1"))
val mask3 = ExpressionMatch("cool!*@*",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask3.match("cool!guyab@127.0.0.1"))
assertTrue(mask3.match("cool!~dudebc@127.0.0.1"))
assertTrue(mask3.match("cool!312ab@example.com"))
assertFalse(mask3.match("coolguy!ab@127.0.0.1"))
assertFalse(mask3.match("cooldud3!~bc@127.0.0.1"))
assertFalse(mask3.match("koolguy!ab@127.0.0.5"))
assertFalse(mask3.match("cooodud3!~d@124.0.0.1"))
// Cause failures in fnmatch/glob based matchers
val mask4 = ExpressionMatch("cool[guy]!*@*",
ExpressionMatch.MatchMode.MatchWildcard,
caseSensitive = false)
assertTrue(mask4.match("cool[guy]!guy@127.0.0.1"))
assertTrue(mask4.match("cool[guy]!a@example.com"))
assertFalse(mask4.match("coolg!ab@127.0.0.1"))
assertFalse(mask4.match("cool[!ac@127.0.1.1"))
}
}
......@@ -25,155 +25,182 @@ import org.junit.Test
class HostmaskHelperTest {
@Test
fun testNormal() {
assertEquals("justJanne",
HostmaskHelper.nick("justJanne!kuschku@lithium.kuschku.de"))
assertEquals("justJanne",
HostmaskHelper.split("justJanne!kuschku@lithium.kuschku.de").first)
assertEquals("kuschku",
HostmaskHelper.user("justJanne!kuschku@lithium.kuschku.de"))
assertEquals("kuschku",
HostmaskHelper.split("justJanne!kuschku@lithium.kuschku.de").second)
assertEquals("lithium.kuschku.de",
HostmaskHelper.host("justJanne!kuschku@lithium.kuschku.de"))
assertEquals("lithium.kuschku.de",
HostmaskHelper.split("justJanne!kuschku@lithium.kuschku.de").third)
assertEquals("justJanne!kuschku@lithium.kuschku.de", HostmaskHelper.build(
"justJanne", "kuschku", "lithium.kuschku.de"
))
runTest(
source = "justJanne!kuschku@lithium.kuschku.de",
nick = "justJanne",
user = "kuschku",
host = "lithium.kuschku.de"
)
assertEquals(
"justJanne!kuschku@lithium.kuschku.de",
HostmaskHelper.build(nick = "justJanne", user = "kuschku", host = "lithium.kuschku.de")
)
}
@Test
fun testUnvalidatedIdent() {
assertEquals("justJanne",
HostmaskHelper.nick("justJanne!~kuschku@lithium.kuschku.de"))
assertEquals("justJanne",
HostmaskHelper.split("justJanne!~kuschku@lithium.kuschku.de").first)
assertEquals("~kuschku",
HostmaskHelper.user("justJanne!~kuschku@lithium.kuschku.de"))
assertEquals("~kuschku",
HostmaskHelper.split("justJanne!~kuschku@lithium.kuschku.de").second)
assertEquals("lithium.kuschku.de",
HostmaskHelper.host("justJanne!~kuschku@lithium.kuschku.de"))
assertEquals("lithium.kuschku.de",
HostmaskHelper.split("justJanne!~kuschku@lithium.kuschku.de").third)
assertEquals("justJanne!~kuschku@lithium.kuschku.de", HostmaskHelper.build(
"justJanne", "~kuschku", "lithium.kuschku.de"
))
runTest(
source = "justJanne!~kuschku@lithium.kuschku.de",
nick = "justJanne",
user = "~kuschku",
host = "lithium.kuschku.de"
)
assertEquals(
"justJanne!~kuschku@lithium.kuschku.de",
HostmaskHelper.build(nick = "justJanne", user = "~kuschku", host = "lithium.kuschku.de")
)
}
@Test
fun testUnicode() {
assertEquals("bärlauch",
HostmaskHelper.nick("bärlauch!maße@flüge.de"))
assertEquals("bärlauch",
HostmaskHelper.split("bärlauch!maße@flüge.de").first)
assertEquals("maße",
HostmaskHelper.user("bärlauch!maße@flüge.de"))
assertEquals("maße",
HostmaskHelper.split("bärlauch!maße@flüge.de").second)
assertEquals("flüge.de",
HostmaskHelper.host("bärlauch!maße@flüge.de"))
assertEquals("flüge.de",
HostmaskHelper.split("bärlauch!maße@flüge.de").third)
assertEquals("bärlauch!maße@flüge.de", HostmaskHelper.build(
"bärlauch", "maße", "flüge.de"
))
runTest(
source = "bärlauch!maße@flüge.de",
nick = "bärlauch",
user = "maße",
host = "flüge.de"
)
assertEquals(
"bärlauch!maße@flüge.de",
HostmaskHelper.build(nick = "bärlauch", user = "maße", host = "flüge.de")
)
}
@Test
fun testServer() {
assertEquals("irc.freenode.org",
HostmaskHelper.nick("irc.freenode.org"))
assertEquals("irc.freenode.org",
HostmaskHelper.split("irc.freenode.org").first)
assertEquals("",
HostmaskHelper.user("irc.freenode.org"))
assertEquals("",
HostmaskHelper.split("irc.freenode.org").second)
assertEquals("",
HostmaskHelper.host("irc.freenode.org"))
assertEquals("",
HostmaskHelper.split("irc.freenode.org").third)
assertEquals("irc.freenode.org", HostmaskHelper.build(
"irc.freenode.org", "", ""
))
runTest(
source = "irc.freenode.org",
nick = "irc.freenode.org",
user = "",
host = ""
)
assertEquals(
"irc.freenode.org",
HostmaskHelper.build(nick = "irc.freenode.org", user = "", host = "")
)
}
@Test
fun testAtNick() {
assertEquals("@nick",
HostmaskHelper.nick("@nick!~ident@example.org"))
assertEquals("@nick",
HostmaskHelper.split("@nick!~ident@example.org").first)
assertEquals("~ident",
HostmaskHelper.user("@nick!~ident@example.org"))
assertEquals("~ident",
HostmaskHelper.split("@nick!~ident@example.org").second)
assertEquals("example.org",
HostmaskHelper.host("@nick!~ident@example.org"))
assertEquals("example.org",
HostmaskHelper.split("@nick!~ident@example.org").third)
assertEquals("@nick!~ident@example.org", HostmaskHelper.build(
"@nick", "~ident", "example.org"
))
runTest(
source = "@nick!~ident@example.org",
nick = "@nick",
user = "~ident",
host = "example.org"
)
assertEquals(
"@nick!~ident@example.org",
HostmaskHelper.build(nick = "@nick", user = "~ident", host = "example.org")
)
}
@Test
fun testReversedDelimiters() {
assertEquals("a",
HostmaskHelper.nick("a@a!"))
assertEquals("a",
HostmaskHelper.split("a@a!").first)
assertEquals("",
HostmaskHelper.user("a@a!"))
assertEquals("",
HostmaskHelper.split("a@a!").second)
assertEquals("a!",
HostmaskHelper.host("a@a!"))
assertEquals("a!",
HostmaskHelper.split("a@a!").third)
assertEquals("a@a!", HostmaskHelper.build(
"a", "", "a!"
))
runTest(
source = "a@a!",
nick = "a",
user = "",
host = "a!"
)
assertEquals(
"a@a!",
HostmaskHelper.build(nick = "a", user = "", host = "a!")
)
}
@Test
fun testDiscord() {
assertEquals("Gin_",
HostmaskHelper.nick("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord"))
assertEquals("Gin_",
HostmaskHelper.split("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord").first)
assertEquals("Gin_!♡♅ƸӜƷ♅♡!",
HostmaskHelper.user("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord"))
assertEquals("Gin_!♡♅ƸӜƷ♅♡!",
HostmaskHelper.split("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord").second)
assertEquals("discord",
HostmaskHelper.host("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord"))
assertEquals("discord",
HostmaskHelper.split("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord").third)
assertEquals("Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord", HostmaskHelper.build(
"Gin_", "Gin_!♡♅ƸӜƷ♅♡!", "discord"
))
runTest(
source = "Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord",
nick = "Gin_",
user = "Gin_!♡♅ƸӜƷ♅♡!",
host = "discord"
)
assertEquals(
"Gin_!Gin_!♡♅ƸӜƷ♅♡!@discord",
HostmaskHelper.build(nick = "Gin_", user = "Gin_!♡♅ƸӜƷ♅♡!", host = "discord")
)
}
@Test
fun testDan() {
runTest(
source = "coolguy!ag@127.0.0.1",
nick = "coolguy",
user = "ag",
host = "127.0.0.1"
)
runTest(
source = "coolguy!~ag@localhost",
nick = "coolguy",
user = "~ag",
host = "localhost"
)
}
@Test
fun testDanMissingAtoms() {
runTest(
source = "!ag@127.0.0.1",
nick = "",
user = "ag",
host = "127.0.0.1"
)
runTest(
source = "coolguy!@127.0.0.1",
nick = "coolguy",
user = "",
host = "127.0.0.1"
)
runTest(
source = "coolguy@127.0.0.1",
nick = "coolguy",
user = "",
host = "127.0.0.1"
)
runTest(
source = "coolguy!ag@",
nick = "coolguy",
user = "ag",
host = ""
)
runTest(
source = "coolguy!ag",
nick = "coolguy",
user = "ag",
host = ""
)
}
@Test
fun testDanWeirdControlCodes() {
runTest(
source = "coolguy!ag@net\u00035w\u0003ork.admin",
nick = "coolguy",
user = "ag",
host = "net\u00035w\u0003ork.admin"
)
runTest(
source = "coolguy!~ag@n\u0002et\u000305w\u000fork.admin",
nick = "coolguy",
user = "~ag",
host = "n\u0002et\u000305w\u000fork.admin"
)
}
private fun runTest(source: String, nick: String, user: String, host: String) {
assertEquals(nick, HostmaskHelper.nick(source))
assertEquals(nick, HostmaskHelper.split(source).first)
assertEquals(user, HostmaskHelper.user(source))
assertEquals(user, HostmaskHelper.split(source).second)
assertEquals(host, HostmaskHelper.host(source))
assertEquals(host, HostmaskHelper.split(source).third)
}
}
......@@ -37,6 +37,7 @@ data class BufferProps(
val bufferActivity: Buffer_Activities = BufferInfo.Activity.of(
BufferInfo.Activity.NoActivity
),
val name: CharSequence = "",
val ircUser: IrcUser? = null,
val avatarUrls: List<Avatar> = emptyList(),
val fallbackDrawable: Drawable? = null,
......