Commit 64762358 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Extract room name from permalink

parent a2d07ad9
...@@ -123,7 +123,8 @@ class ChatRoomPresenter @Inject constructor( ...@@ -123,7 +123,8 @@ class ChatRoomPresenter @Inject constructor(
view.onRoomUpdated(canPost, chatIsBroadcast) view.onRoomUpdated(canPost, chatIsBroadcast)
loadMessages(roomId, roomType) loadMessages(roomId, roomType)
chatRoomMessage?.let { messageHelper.messageIdFromPermalink(it) }?.let { messageId -> chatRoomMessage?.let { messageHelper.messageIdFromPermalink(it) }?.let { messageId ->
citeMessage(roomName, messageHelper.roomTypeFromPermalink(chatRoomMessage)!!, messageId, true) val name = messageHelper.roomNameFromPermalink(chatRoomMessage)
citeMessage(name!!, messageHelper.roomTypeFromPermalink(chatRoomMessage)!!, messageId, true)
} }
} }
} }
......
...@@ -30,8 +30,17 @@ class MessageHelper @Inject constructor( ...@@ -30,8 +30,17 @@ class MessageHelper @Inject constructor(
fun messageIdFromPermalink(permalink: String): String? { fun messageIdFromPermalink(permalink: String): String? {
PERMALINK_REGEX.find(permalink.trim())?.let { PERMALINK_REGEX.find(permalink.trim())?.let {
if (it.groupValues.size == 4) { if (it.groupValues.size == 5) {
return it.groupValues[3] return it.groupValues[MESSAGE_ID]
}
}
return null
}
fun roomNameFromPermalink(permalink: String): String? {
PERMALINK_REGEX.find(permalink.trim())?.let {
if (it.groupValues.size == 5) {
return it.groupValues[ROOM_NAME]
} }
} }
return null return null
...@@ -39,8 +48,8 @@ class MessageHelper @Inject constructor( ...@@ -39,8 +48,8 @@ class MessageHelper @Inject constructor(
fun roomTypeFromPermalink(permalink: String): String? { fun roomTypeFromPermalink(permalink: String): String? {
PERMALINK_REGEX.find(permalink.trim())?.let { PERMALINK_REGEX.find(permalink.trim())?.let {
if (it.groupValues.size == 4) { if (it.groupValues.size == 5) {
val type = it.groupValues[2] val type = it.groupValues[ROOM_TYPE]
return when(type) { return when(type) {
"group" -> "p" "group" -> "p"
"channel" -> "c" "channel" -> "c"
...@@ -54,6 +63,9 @@ class MessageHelper @Inject constructor( ...@@ -54,6 +63,9 @@ class MessageHelper @Inject constructor(
} }
companion object { companion object {
val PERMALINK_REGEX = "(?:__|[*#])|\\[(.+?)\\]\\(.+?//.+?/(.+)/.+\\?.*=(.*)\\)".toRegex() private const val ROOM_TYPE = 2
private const val ROOM_NAME = 3
private const val MESSAGE_ID = 4
val PERMALINK_REGEX = "(?:__|[*#])|\\[(.+?)\\]\\(.+?//.+?/(.+)/(.+)\\?.*=(.*)\\)".toRegex()
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment