Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
0d819ab8
Commit
0d819ab8
authored
Feb 02, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt MessageViewModel class to accept quotes/replies
parent
2f850b62
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
10 deletions
+61
-10
MessageViewModel.kt
...hat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
+52
-7
MessageViewModelMapper.kt
...cket/android/chatroom/viewmodel/MessageViewModelMapper.kt
+9
-3
No files found.
app/src/main/java/chat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
View file @
0d819ab8
...
@@ -8,40 +8,64 @@ import android.text.SpannableString
...
@@ -8,40 +8,64 @@ import android.text.SpannableString
import
android.text.style.ForegroundColorSpan
import
android.text.style.ForegroundColorSpan
import
android.text.style.StyleSpan
import
android.text.style.StyleSpan
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.android.server.domain.SITE_URL
import
chat.rocket.android.server.domain.SITE_URL
import
chat.rocket.android.server.domain.USE_REALNAME
import
chat.rocket.android.server.domain.USE_REALNAME
import
chat.rocket.common.model.Token
import
chat.rocket.common.model.Token
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.MessageType.*
import
chat.rocket.core.model.MessageType.*
import
chat.rocket.core.model.Url
import
chat.rocket.core.model.Value
import
chat.rocket.core.model.Value
import
chat.rocket.core.model.attachment.AudioAttachment
import
chat.rocket.core.model.attachment.AudioAttachment
import
chat.rocket.core.model.attachment.FileAttachment
import
chat.rocket.core.model.attachment.FileAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
okhttp3.HttpUrl
import
okhttp3.HttpUrl
import
timber.log.Timber
data class
MessageViewModel
(
val
context
:
Context
,
data class
MessageViewModel
(
val
context
:
Context
,
private
val
token
:
Token
?,
private
val
token
:
Token
?,
private
val
message
:
Message
,
private
val
message
:
Message
,
private
val
settings
:
Map
<
String
,
Value
<
Any
>>?)
{
private
val
settings
:
Map
<
String
,
Value
<
Any
>>?,
private
val
parser
:
MessageParser
,
private
val
messagesRepository
:
MessagesRepository
)
{
val
id
:
String
=
message
.
id
val
id
:
String
=
message
.
id
val
time
:
CharSequence
val
time
:
CharSequence
val
sender
:
CharSequence
val
sender
:
CharSequence
val
content
:
CharSequence
val
content
:
CharSequence
var
quote
:
Message
?
=
null
var
urlsWithMeta
=
arrayListOf
<
Url
>()
var
attachmentUrl
:
String
?
=
null
var
attachmentUrl
:
String
?
=
null
var
attachmentTitle
:
CharSequence
?
=
null
var
attachmentTitle
:
CharSequence
?
=
null
var
attachmentType
:
AttachmentType
?
=
null
var
attachmentType
:
AttachmentType
?
=
null
init
{
init
{
sender
=
getSenderName
()
sender
=
getSenderName
()
content
=
getContent
(
context
)
time
=
getTime
()
time
=
getTime
()
val
baseUrl
=
settings
?.
get
(
SITE_URL
)
message
.
urls
?.
let
{
// println(message.urls)
if
(
it
.
isEmpty
())
return
@let
for
(
url
in
it
)
{
if
(
url
.
meta
!=
null
)
{
urlsWithMeta
.
add
(
url
)
}
baseUrl
?.
let
{
val
quoteUrl
=
HttpUrl
.
parse
(
url
.
url
)
val
serverUrl
=
HttpUrl
.
parse
(
baseUrl
.
value
.
toString
())
if
(
quoteUrl
!=
null
&&
serverUrl
!=
null
)
{
makeQuote
(
quoteUrl
,
serverUrl
)
}
}
}
}
message
.
attachments
?.
let
{
message
.
attachments
?.
let
{
if
(
it
.
isEmpty
()
||
it
[
0
]
==
null
)
return
@let
if
(
it
.
isEmpty
()
||
it
[
0
]
==
null
)
return
@let
val
attachment
=
it
[
0
]
as
FileAttachment
val
attachment
=
it
[
0
]
as
FileAttachment
val
baseUrl
=
settings
?.
get
(
SITE_URL
)
baseUrl
?.
let
{
baseUrl
?.
let
{
attachmentUrl
=
attachmentUrl
(
"${baseUrl.value}${attachment.url}"
)
attachmentUrl
=
attachmentUrl
(
"${baseUrl.value}${attachment.url}"
)
attachmentTitle
=
attachment
.
title
attachmentTitle
=
attachment
.
title
...
@@ -54,6 +78,18 @@ data class MessageViewModel(val context: Context,
...
@@ -54,6 +78,18 @@ data class MessageViewModel(val context: Context,
}
}
}
}
}
}
content
=
getContent
(
context
)
}
private
fun
makeQuote
(
quoteUrl
:
HttpUrl
,
serverUrl
:
HttpUrl
)
{
if
(
quoteUrl
.
host
()
==
serverUrl
.
host
())
{
val
msgIdToQuote
=
quoteUrl
.
queryParameter
(
"msg"
)
Timber
.
d
(
"Will quote message Id: $msgIdToQuote"
)
if
(
msgIdToQuote
!=
null
)
{
quote
=
messagesRepository
.
getById
(
msgIdToQuote
)
}
}
}
}
fun
getAvatarUrl
(
serverUrl
:
String
):
String
?
{
fun
getAvatarUrl
(
serverUrl
:
String
):
String
?
{
...
@@ -62,9 +98,11 @@ data class MessageViewModel(val context: Context,
...
@@ -62,9 +98,11 @@ data class MessageViewModel(val context: Context,
}
}
}
}
fun
get
Time
()
=
DateTimeHelper
.
getTime
(
DateTimeHelper
.
getLocalDateTime
(
message
.
timestamp
))
fun
get
OriginalMessage
()
=
message
.
message
fun
getSenderName
():
CharSequence
{
private
fun
getTime
()
=
DateTimeHelper
.
getTime
(
DateTimeHelper
.
getLocalDateTime
(
message
.
timestamp
))
private
fun
getSenderName
():
CharSequence
{
val
useRealName
=
settings
?.
get
(
USE_REALNAME
)
?.
value
as
Boolean
val
useRealName
=
settings
?.
get
(
USE_REALNAME
)
?.
value
as
Boolean
val
username
=
message
.
sender
?.
username
val
username
=
message
.
sender
?.
username
val
realName
=
message
.
sender
?.
name
val
realName
=
message
.
sender
?.
name
...
@@ -72,7 +110,7 @@ data class MessageViewModel(val context: Context,
...
@@ -72,7 +110,7 @@ data class MessageViewModel(val context: Context,
return
senderName
?:
username
.
toString
()
return
senderName
?:
username
.
toString
()
}
}
fun
getContent
(
context
:
Context
):
CharSequence
{
private
fun
getContent
(
context
:
Context
):
CharSequence
{
val
contentMessage
:
CharSequence
val
contentMessage
:
CharSequence
when
(
message
.
type
)
{
when
(
message
.
type
)
{
//TODO: Add implementation for Welcome type.
//TODO: Add implementation for Welcome type.
...
@@ -90,7 +128,14 @@ data class MessageViewModel(val context: Context,
...
@@ -90,7 +128,14 @@ data class MessageViewModel(val context: Context,
return
contentMessage
return
contentMessage
}
}
private
fun
getNormalMessage
()
=
message
.
message
private
fun
getNormalMessage
():
CharSequence
{
var
quoteViewModel
:
MessageViewModel
?
=
null
if
(
quote
!=
null
)
{
val
quoteMessage
:
Message
=
quote
!!
quoteViewModel
=
MessageViewModel
(
context
,
token
,
quoteMessage
,
settings
,
parser
,
messagesRepository
)
}
return
parser
.
renderMarkdown
(
message
.
message
,
quoteViewModel
,
urlsWithMeta
)
}
private
fun
getSystemMessage
(
content
:
String
):
CharSequence
{
private
fun
getSystemMessage
(
content
:
String
):
CharSequence
{
val
spannableMsg
=
SpannableString
(
content
)
val
spannableMsg
=
SpannableString
(
content
)
...
...
app/src/main/java/chat/rocket/android/chatroom/viewmodel/MessageViewModelMapper.kt
View file @
0d819ab8
package
chat.rocket.android.chatroom.viewmodel
package
chat.rocket.android.chatroom.viewmodel
import
android.content.Context
import
android.content.Context
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.core.TokenRepository
import
chat.rocket.core.TokenRepository
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
chat.rocket.core.model.Value
import
javax.inject.Inject
import
javax.inject.Inject
class
MessageViewModelMapper
@Inject
constructor
(
private
val
context
:
Context
,
private
val
tokenRepository
:
TokenRepository
)
{
class
MessageViewModelMapper
@Inject
constructor
(
private
val
context
:
Context
,
private
val
tokenRepository
:
TokenRepository
,
private
val
messageParser
:
MessageParser
,
private
val
messagesRepository
:
MessagesRepository
)
{
suspend
fun
mapToViewModel
(
message
:
Message
,
settings
:
Map
<
String
,
Value
<
Any
>>?)
=
MessageViewModel
(
context
,
tokenRepository
.
get
(),
message
,
settings
)
suspend
fun
mapToViewModel
(
message
:
Message
,
settings
:
Map
<
String
,
Value
<
Any
>>?)
=
MessageViewModel
(
context
,
tokenRepository
.
get
(),
message
,
settings
,
messageParser
,
messagesRepository
)
suspend
fun
mapToViewModelList
(
messageList
:
List
<
Message
>,
settings
:
Map
<
String
,
Value
<
Any
>>?):
List
<
MessageViewModel
>
{
suspend
fun
mapToViewModelList
(
messageList
:
List
<
Message
>,
settings
:
Map
<
String
,
Value
<
Any
>>?):
List
<
MessageViewModel
>
{
return
messageList
.
map
{
MessageViewModel
(
context
,
tokenRepository
.
get
(),
it
,
settings
)
}
return
messageList
.
map
{
MessageViewModel
(
context
,
tokenRepository
.
get
(),
it
,
settings
,
messageParser
,
messagesRepository
)
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment