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
afb2033e
Commit
afb2033e
authored
Oct 01, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Attachments mapping.
parent
ac7a6e1e
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1033 additions
and
9 deletions
+1033
-9
7.json
app/schemas/chat.rocket.android.db.RCDatabase/7.json
+959
-0
MessageService.kt
...va/chat/rocket/android/chatroom/service/MessageService.kt
+1
-1
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+1
-1
MessageDao.kt
app/src/main/java/chat/rocket/android/db/MessageDao.kt
+3
-0
Attachments.kt
...src/main/java/chat/rocket/android/db/model/Attachments.kt
+16
-1
DatabaseMessageMapper.kt
...t/android/server/infraestructure/DatabaseMessageMapper.kt
+53
-6
No files found.
app/schemas/chat.rocket.android.db.RCDatabase/7.json
0 → 100644
View file @
afb2033e
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/chatroom/service/MessageService.kt
View file @
afb2033e
...
...
@@ -44,7 +44,7 @@ class MessageService : JobService() {
private
suspend
fun
retrySendingMessages
(
params
:
JobParameters
?,
serverUrl
:
String
)
{
val
dbManager
=
dbFactory
.
create
(
serverUrl
)
val
messageRepository
=
DatabaseMessagesRepository
(
dbManager
,
DatabaseMessageMapper
())
val
messageRepository
=
DatabaseMessagesRepository
(
dbManager
,
DatabaseMessageMapper
(
dbManager
))
val
temporaryMessages
=
messageRepository
.
getAllUnsent
()
.
sortedWith
(
compareBy
(
Message
::
timestamp
))
if
(
temporaryMessages
.
isNotEmpty
())
{
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
afb2033e
...
...
@@ -267,7 +267,7 @@ class AppModule {
@Provides
fun
provideMessageRepository
(
databaseManager
:
DatabaseManager
):
MessagesRepository
{
return
DatabaseMessagesRepository
(
databaseManager
,
DatabaseMessageMapper
())
return
DatabaseMessagesRepository
(
databaseManager
,
DatabaseMessageMapper
(
databaseManager
))
}
@Provides
...
...
app/src/main/java/chat/rocket/android/db/MessageDao.kt
View file @
afb2033e
...
...
@@ -168,6 +168,9 @@ abstract class MessageDao {
@Insert
(
onConflict
=
OnConflictStrategy
.
REPLACE
)
abstract
fun
saveLastSync
(
entity
:
MessagesSync
)
@Query
(
"SELECT * FROM attachment_fields WHERE attachmentId = :id"
)
abstract
fun
getAttachmentFields
(
id
:
String
):
List
<
AttachmentFieldEntity
>
companion
object
{
const
val
BASE_MESSAGE_QUERY
=
"""
SELECT
...
...
app/src/main/java/chat/rocket/android/db/model/Attachments.kt
View file @
afb2033e
...
...
@@ -9,6 +9,7 @@ import chat.rocket.core.model.attachment.Attachment
import
chat.rocket.core.model.attachment.AudioAttachment
import
chat.rocket.core.model.attachment.AuthorAttachment
import
chat.rocket.core.model.attachment.ColorAttachment
import
chat.rocket.core.model.attachment.GenericFileAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.MessageAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
...
...
@@ -37,6 +38,7 @@ data class AttachmentEntity(
@ColumnInfo
(
name
=
"thumb_url"
)
val
thumbUrl
:
String
?
=
null
,
val
color
:
String
?
=
null
,
val
fallback
:
String
?
=
null
,
@ColumnInfo
(
name
=
"title_link"
)
val
titleLink
:
String
?
=
null
,
@ColumnInfo
(
name
=
"title_link_download"
)
...
...
@@ -86,6 +88,7 @@ fun Attachment.asEntity(msgId: String): List<BaseMessageEntity> {
is
AuthorAttachment
->
asEntity
(
msgId
)
is
ColorAttachment
->
listOf
(
asEntity
(
msgId
))
is
MessageAttachment
->
listOf
(
asEntity
(
msgId
))
is
GenericFileAttachment
->
listOf
(
asEntity
(
msgId
))
// TODO - Action Attachments
else
->
{
Timber
.
d
(
"Missing conversion for: ${javaClass.canonicalName}"
)
...
...
@@ -163,7 +166,8 @@ fun ColorAttachment.asEntity(msgId: String): AttachmentEntity =
AttachmentEntity
(
_id
=
"${msgId}_${hashCode()}"
,
messageId
=
msgId
,
color
=
color
.
rawColor
color
=
color
.
rawColor
,
fallback
=
fallback
)
// TODO - how to model An message attachment with attachments???
...
...
@@ -179,3 +183,14 @@ fun MessageAttachment.asEntity(msgId: String): AttachmentEntity =
messageLink
=
url
,
timestamp
=
timestamp
)
fun
GenericFileAttachment
.
asEntity
(
msgId
:
String
):
AttachmentEntity
=
AttachmentEntity
(
_id
=
"${msgId}_${hashCode()}"
,
messageId
=
msgId
,
title
=
title
,
description
=
description
,
text
=
text
,
titleLink
=
titleLink
,
titleLinkDownload
=
titleLinkDownload
?:
false
)
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/DatabaseMessageMapper.kt
View file @
afb2033e
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.FullMessage
import
chat.rocket.android.db.model.ReactionEntity
...
...
@@ -10,15 +11,26 @@ import chat.rocket.common.model.SimpleUser
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Reactions
import
chat.rocket.core.model.attachment.Attachment
import
chat.rocket.core.model.attachment.AudioAttachment
import
chat.rocket.core.model.attachment.AuthorAttachment
import
chat.rocket.core.model.attachment.Color
import
chat.rocket.core.model.attachment.ColorAttachment
import
chat.rocket.core.model.attachment.Field
import
chat.rocket.core.model.attachment.GenericFileAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.MessageAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
chat.rocket.core.model.messageTypeOf
import
chat.rocket.core.model.url.Meta
import
chat.rocket.core.model.url.ParsedUrl
import
chat.rocket.core.model.url.Url
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.withContext
class
DatabaseMessageMapper
{
fun
map
(
message
:
FullMessage
):
Message
?
=
map
(
listOf
(
message
)).
firstOrNull
()
class
DatabaseMessageMapper
(
private
val
dbManager
:
DatabaseManager
)
{
suspend
fun
map
(
message
:
FullMessage
):
Message
?
=
map
(
listOf
(
message
)).
firstOrNull
()
fun
map
(
messages
:
List
<
FullMessage
>):
List
<
Message
>
{
suspend
fun
map
(
messages
:
List
<
FullMessage
>):
List
<
Message
>
{
val
list
=
mutableListOf
<
Message
>()
messages
.
forEach
{
message
->
val
favorites
=
mutableListOf
<
SimpleUser
>()
...
...
@@ -120,12 +132,47 @@ class DatabaseMessageMapper {
}
}
private
fun
mapAttachments
(
attachments
:
List
<
AttachmentEntity
>):
List
<
Attachment
>
{
private
suspend
fun
mapAttachments
(
attachments
:
List
<
AttachmentEntity
>):
List
<
Attachment
>
{
val
list
=
mutableListOf
<
Attachment
>()
attachments
.
forEach
{
attachment
->
with
(
attachment
)
{
when
{
imageUrl
!=
null
->
{
ImageAttachment
(
title
,
description
,
text
,
titleLink
,
titleLinkDownload
,
imageUrl
,
type
,
imageSize
)
}
videoUrl
!=
null
->
{
VideoAttachment
(
title
,
description
,
text
,
titleLink
,
titleLinkDownload
,
videoUrl
,
type
,
videoSize
)
}
audioUrl
!=
null
->
{
AudioAttachment
(
title
,
description
,
text
,
titleLink
,
titleLinkDownload
,
audioUrl
,
type
,
audioSize
)
}
titleLink
!=
null
->
{
GenericFileAttachment
(
title
,
description
,
text
,
titleLink
,
titleLink
,
titleLinkDownload
)
}
text
!=
null
&&
color
!=
null
&&
fallback
!=
null
->
{
ColorAttachment
(
Color
.
Custom
(
color
),
text
,
fallback
)
}
text
!=
null
->
{
// TODO how to model message with attachments
MessageAttachment
(
authorName
,
authorIcon
,
text
,
thumbUrl
,
color
?.
let
{
Color
.
Custom
(
it
)
},
messageLink
,
null
,
timestamp
)
}
authorLink
!=
null
->
{
mapAuthorAttachment
(
this
)
}
else
->
null
}
?.
let
{
list
.
add
(
it
)
}
}
}
// TODO - implement mapping
return
list
}
private
suspend
fun
mapAuthorAttachment
(
attachment
:
AttachmentEntity
):
AuthorAttachment
{
val
fields
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getAttachmentFields
(
attachment
.
_id
)
}.
map
{
Field
(
it
.
title
,
it
.
value
)
}
return
with
(
attachment
)
{
AuthorAttachment
(
authorLink
!!
,
authorIcon
,
authorName
,
fields
)
}
}
}
\ 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