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
7c2544e3
Commit
7c2544e3
authored
Mar 13, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use internal functions for getting attachments info
parent
009cade1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
29 deletions
+35
-29
ViewModelMapper.kt
...chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
+35
-29
No files found.
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
View file @
7c2544e3
...
...
@@ -96,13 +96,9 @@ class ViewModelMapper @Inject constructor(private val context: Context,
}
private
fun
mapFileAttachment
(
message
:
Message
,
attachment
:
FileAttachment
):
BaseViewModel
<
*
>?
{
val
attachmentUrl
=
if
(
attachment
.
url
.
startsWith
(
"http"
))
{
attachment
.
url
}
else
{
attachmentUrl
(
"$baseUrl${attachment.url}"
)
}
val
attachmentTitle
=
attachment
.
attachmentTitle
val
id
=
"${message.id}_${attachment.url}"
.
hashCode
().
toLong
()
val
attachmentUrl
=
attachmentUrl
(
attachment
)
val
attachmentTitle
=
attachmentTitle
(
attachment
)
val
id
=
attachmentId
(
message
,
attachment
)
return
when
(
attachment
)
{
is
ImageAttachment
->
ImageAttachmentViewModel
(
message
,
attachment
,
message
.
id
,
attachmentUrl
,
attachmentTitle
,
id
,
getReactions
(
message
))
...
...
@@ -114,17 +110,39 @@ class ViewModelMapper @Inject constructor(private val context: Context,
}
}
private
fun
attachmentUrl
(
url
:
String
):
String
{
var
response
=
url
val
httpUrl
=
HttpUrl
.
parse
(
url
)
private
fun
attachmentId
(
message
:
Message
,
attachment
:
FileAttachment
):
Long
{
return
"${message.id}_${attachment.url}"
.
hashCode
().
toLong
()
}
private
fun
attachmentTitle
(
attachment
:
FileAttachment
):
CharSequence
{
return
with
(
attachment
)
{
title
?.
let
{
return
@with
it
}
val
fileUrl
=
HttpUrl
.
parse
(
url
)
fileUrl
?.
let
{
return
@with
it
.
pathSegments
().
last
()
}
return
@with
""
}
}
private
fun
attachmentUrl
(
attachment
:
FileAttachment
):
String
{
return
with
(
attachment
)
{
if
(
url
.
startsWith
(
"http"
))
return
@with
url
val
fullUrl
=
"$baseUrl$url"
val
httpUrl
=
HttpUrl
.
parse
(
fullUrl
)
httpUrl
?.
let
{
response
=
it
.
newBuilder
().
apply
{
return
@with
it
.
newBuilder
().
apply
{
addQueryParameter
(
"rc_uid"
,
token
?.
userId
)
addQueryParameter
(
"rc_token"
,
token
?.
authToken
)
}.
build
().
toString
()
}
return
response
// Fallback to baseUrl + url
return
@with
fullUrl
}
}
private
suspend
fun
mapMessage
(
message
:
Message
):
MessageViewModel
=
withContext
(
CommonPool
)
{
...
...
@@ -308,15 +326,3 @@ class ViewModelMapper @Inject constructor(private val context: Context,
}
}
}
\ No newline at end of file
internal
val
FileAttachment
.
attachmentTitle
:
String
get
()
{
title
?.
let
{
return
it
}
val
fileUrl
=
HttpUrl
.
parse
(
url
)
fileUrl
?.
let
{
return
it
.
pathSegments
().
last
()
}
return
""
}
\ 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