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
ac348b69
Commit
ac348b69
authored
Oct 02, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tentative Actions Attachment support on DB
parent
2c64b3f4
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1176 additions
and
6 deletions
+1176
-6
8.json
app/schemas/chat.rocket.android.db.RCDatabase/8.json
+1075
-0
MessageDao.kt
app/src/main/java/chat/rocket/android/db/MessageDao.kt
+4
-0
RCDatabase.kt
app/src/main/java/chat/rocket/android/db/RCDatabase.kt
+4
-3
Attachments.kt
...src/main/java/chat/rocket/android/db/model/Attachments.kt
+67
-3
DatabaseMessageMapper.kt
...t/android/server/infraestructure/DatabaseMessageMapper.kt
+26
-0
No files found.
app/schemas/chat.rocket.android.db.RCDatabase/8.json
0 → 100644
View file @
ac348b69
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/db/MessageDao.kt
View file @
ac348b69
...
@@ -5,6 +5,7 @@ import androidx.room.Insert
...
@@ -5,6 +5,7 @@ import androidx.room.Insert
import
androidx.room.OnConflictStrategy
import
androidx.room.OnConflictStrategy
import
androidx.room.Query
import
androidx.room.Query
import
androidx.room.Transaction
import
androidx.room.Transaction
import
chat.rocket.android.db.model.AttachmentActionEntity
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.AttachmentFieldEntity
import
chat.rocket.android.db.model.AttachmentFieldEntity
import
chat.rocket.android.db.model.BaseMessageEntity
import
chat.rocket.android.db.model.BaseMessageEntity
...
@@ -171,6 +172,9 @@ abstract class MessageDao {
...
@@ -171,6 +172,9 @@ abstract class MessageDao {
@Query
(
"SELECT * FROM attachment_fields WHERE attachmentId = :id"
)
@Query
(
"SELECT * FROM attachment_fields WHERE attachmentId = :id"
)
abstract
fun
getAttachmentFields
(
id
:
String
):
List
<
AttachmentFieldEntity
>
abstract
fun
getAttachmentFields
(
id
:
String
):
List
<
AttachmentFieldEntity
>
@Query
(
"SELECT * FROM attachment_action WHERE attachmentId = :id"
)
abstract
fun
getAttachmentActions
(
id
:
String
):
List
<
AttachmentActionEntity
>
companion
object
{
companion
object
{
const
val
BASE_MESSAGE_QUERY
=
"""
const
val
BASE_MESSAGE_QUERY
=
"""
SELECT
SELECT
...
...
app/src/main/java/chat/rocket/android/db/RCDatabase.kt
View file @
ac348b69
...
@@ -2,6 +2,7 @@ package chat.rocket.android.db
...
@@ -2,6 +2,7 @@ package chat.rocket.android.db
import
androidx.room.Database
import
androidx.room.Database
import
androidx.room.RoomDatabase
import
androidx.room.RoomDatabase
import
chat.rocket.android.db.model.AttachmentActionEntity
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.AttachmentFieldEntity
import
chat.rocket.android.db.model.AttachmentFieldEntity
import
chat.rocket.android.db.model.ChatRoomEntity
import
chat.rocket.android.db.model.ChatRoomEntity
...
@@ -19,10 +20,10 @@ import chat.rocket.android.db.model.UserEntity
...
@@ -19,10 +20,10 @@ import chat.rocket.android.db.model.UserEntity
UserEntity
::
class
,
ChatRoomEntity
::
class
,
MessageEntity
::
class
,
UserEntity
::
class
,
ChatRoomEntity
::
class
,
MessageEntity
::
class
,
MessageFavoritesRelation
::
class
,
MessageMentionsRelation
::
class
,
MessageFavoritesRelation
::
class
,
MessageMentionsRelation
::
class
,
MessageChannels
::
class
,
AttachmentEntity
::
class
,
MessageChannels
::
class
,
AttachmentEntity
::
class
,
AttachmentFieldEntity
::
class
,
UrlEntity
::
class
,
Reaction
Entity
::
class
,
AttachmentFieldEntity
::
class
,
AttachmentActionEntity
::
class
,
Url
Entity
::
class
,
MessagesSync
::
class
ReactionEntity
::
class
,
MessagesSync
::
class
],
],
version
=
7
,
version
=
8
,
exportSchema
=
true
exportSchema
=
true
)
)
abstract
class
RCDatabase
:
RoomDatabase
()
{
abstract
class
RCDatabase
:
RoomDatabase
()
{
...
...
app/src/main/java/chat/rocket/android/db/model/Attachments.kt
View file @
ac348b69
...
@@ -3,6 +3,7 @@ package chat.rocket.android.db.model
...
@@ -3,6 +3,7 @@ package chat.rocket.android.db.model
import
androidx.room.ColumnInfo
import
androidx.room.ColumnInfo
import
androidx.room.Entity
import
androidx.room.Entity
import
androidx.room.ForeignKey
import
androidx.room.ForeignKey
import
androidx.room.Index
import
androidx.room.PrimaryKey
import
androidx.room.PrimaryKey
import
chat.rocket.android.util.extension.orFalse
import
chat.rocket.android.util.extension.orFalse
import
chat.rocket.core.model.attachment.Attachment
import
chat.rocket.core.model.attachment.Attachment
...
@@ -13,6 +14,8 @@ import chat.rocket.core.model.attachment.GenericFileAttachment
...
@@ -13,6 +14,8 @@ import chat.rocket.core.model.attachment.GenericFileAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.MessageAttachment
import
chat.rocket.core.model.attachment.MessageAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
chat.rocket.core.model.attachment.actions.ActionsAttachment
import
chat.rocket.core.model.attachment.actions.ButtonAction
import
timber.log.Timber
import
timber.log.Timber
@Entity
(
tableName
=
"attachments"
,
@Entity
(
tableName
=
"attachments"
,
...
@@ -63,13 +66,20 @@ data class AttachmentEntity(
...
@@ -63,13 +66,20 @@ data class AttachmentEntity(
val
audioSize
:
Long
?
=
null
,
val
audioSize
:
Long
?
=
null
,
@ColumnInfo
(
name
=
"message_link"
)
@ColumnInfo
(
name
=
"message_link"
)
val
messageLink
:
String
?
=
null
,
val
messageLink
:
String
?
=
null
,
val
timestamp
:
Long
?
=
null
val
timestamp
:
Long
?
=
null
,
@ColumnInfo
(
name
=
"has_actions"
)
val
hasActions
:
Boolean
=
false
,
@ColumnInfo
(
name
=
"button_alignment"
)
val
buttonAlignment
:
String
?
=
null
)
:
BaseMessageEntity
)
:
BaseMessageEntity
@Entity
(
tableName
=
"attachment_fields"
,
@Entity
(
tableName
=
"attachment_fields"
,
foreignKeys
=
[
foreignKeys
=
[
ForeignKey
(
entity
=
AttachmentEntity
::
class
,
parentColumns
=
[
"_id"
],
ForeignKey
(
entity
=
AttachmentEntity
::
class
,
parentColumns
=
[
"_id"
],
childColumns
=
[
"attachmentId"
],
onDelete
=
ForeignKey
.
CASCADE
)
childColumns
=
[
"attachmentId"
],
onDelete
=
ForeignKey
.
CASCADE
)
],
indices
=
[
Index
(
value
=
[
"attachmentId"
])
])
])
data class
AttachmentFieldEntity
(
data class
AttachmentFieldEntity
(
val
attachmentId
:
String
,
val
attachmentId
:
String
,
...
@@ -80,6 +90,29 @@ data class AttachmentFieldEntity(
...
@@ -80,6 +90,29 @@ data class AttachmentFieldEntity(
var
id
:
Long
?
=
null
var
id
:
Long
?
=
null
}
}
@Entity
(
tableName
=
"attachment_action"
,
foreignKeys
=
[
ForeignKey
(
entity
=
AttachmentEntity
::
class
,
parentColumns
=
[
"_id"
],
childColumns
=
[
"attachmentId"
],
onDelete
=
ForeignKey
.
CASCADE
)
],
indices
=
[
Index
(
value
=
[
"attachmentId"
])
])
data class
AttachmentActionEntity
(
val
attachmentId
:
String
,
val
type
:
String
,
val
text
:
String
?
=
null
,
val
url
:
String
?
=
null
,
val
isWebView
:
Boolean
?
=
null
,
val
webViewHeightRatio
:
String
?
=
null
,
val
imageUrl
:
String
?
=
null
,
val
message
:
String
?
=
null
,
val
isMessageInChatWindow
:
Boolean
?
=
null
)
:
BaseMessageEntity
{
@PrimaryKey
(
autoGenerate
=
true
)
var
id
:
Long
?
=
null
}
fun
Attachment
.
asEntity
(
msgId
:
String
):
List
<
BaseMessageEntity
>
{
fun
Attachment
.
asEntity
(
msgId
:
String
):
List
<
BaseMessageEntity
>
{
return
when
(
this
)
{
return
when
(
this
)
{
is
ImageAttachment
->
listOf
(
asEntity
(
msgId
))
is
ImageAttachment
->
listOf
(
asEntity
(
msgId
))
...
@@ -89,7 +122,7 @@ fun Attachment.asEntity(msgId: String): List<BaseMessageEntity> {
...
@@ -89,7 +122,7 @@ fun Attachment.asEntity(msgId: String): List<BaseMessageEntity> {
is
ColorAttachment
->
listOf
(
asEntity
(
msgId
))
is
ColorAttachment
->
listOf
(
asEntity
(
msgId
))
is
MessageAttachment
->
listOf
(
asEntity
(
msgId
))
is
MessageAttachment
->
listOf
(
asEntity
(
msgId
))
is
GenericFileAttachment
->
listOf
(
asEntity
(
msgId
))
is
GenericFileAttachment
->
listOf
(
asEntity
(
msgId
))
// TODO - Action Attachments
is
ActionsAttachment
->
asEntity
(
msgId
)
else
->
{
else
->
{
Timber
.
d
(
"Missing conversion for: ${javaClass.canonicalName}"
)
Timber
.
d
(
"Missing conversion for: ${javaClass.canonicalName}"
)
emptyList
()
emptyList
()
...
@@ -193,4 +226,35 @@ fun GenericFileAttachment.asEntity(msgId: String): AttachmentEntity =
...
@@ -193,4 +226,35 @@ fun GenericFileAttachment.asEntity(msgId: String): AttachmentEntity =
text
=
text
,
text
=
text
,
titleLink
=
titleLink
,
titleLink
=
titleLink
,
titleLinkDownload
=
titleLinkDownload
?:
false
titleLinkDownload
=
titleLinkDownload
?:
false
)
)
\ No newline at end of file
fun
ActionsAttachment
.
asEntity
(
msgId
:
String
):
List
<
BaseMessageEntity
>
{
val
list
=
mutableListOf
<
BaseMessageEntity
>()
val
attachmentId
=
"${msgId}_${hashCode()}"
val
attachment
=
AttachmentEntity
(
_id
=
attachmentId
,
messageId
=
msgId
,
title
=
title
,
hasActions
=
true
,
buttonAlignment
=
buttonAlignment
)
list
.
add
(
attachment
)
actions
.
forEach
{
action
->
when
(
action
)
{
is
ButtonAction
->
AttachmentActionEntity
(
attachmentId
=
attachmentId
,
type
=
action
.
type
,
text
=
action
.
text
,
url
=
action
.
url
,
isWebView
=
action
.
isWebView
,
webViewHeightRatio
=
action
.
webViewHeightRatio
,
imageUrl
=
action
.
imageUrl
,
message
=
action
.
message
,
isMessageInChatWindow
=
action
.
isMessageInChatWindow
)
else
->
null
}
?.
let
{
list
.
add
(
it
)
}
}
return
list
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/DatabaseMessageMapper.kt
View file @
ac348b69
package
chat.rocket.android.server.infraestructure
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.model.AttachmentActionEntity
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.AttachmentEntity
import
chat.rocket.android.db.model.FullMessage
import
chat.rocket.android.db.model.FullMessage
import
chat.rocket.android.db.model.ReactionEntity
import
chat.rocket.android.db.model.ReactionEntity
...
@@ -20,6 +21,9 @@ import chat.rocket.core.model.attachment.GenericFileAttachment
...
@@ -20,6 +21,9 @@ import chat.rocket.core.model.attachment.GenericFileAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
import
chat.rocket.core.model.attachment.MessageAttachment
import
chat.rocket.core.model.attachment.MessageAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
chat.rocket.core.model.attachment.VideoAttachment
import
chat.rocket.core.model.attachment.actions.Action
import
chat.rocket.core.model.attachment.actions.ActionsAttachment
import
chat.rocket.core.model.attachment.actions.ButtonAction
import
chat.rocket.core.model.messageTypeOf
import
chat.rocket.core.model.messageTypeOf
import
chat.rocket.core.model.url.Meta
import
chat.rocket.core.model.url.Meta
import
chat.rocket.core.model.url.ParsedUrl
import
chat.rocket.core.model.url.ParsedUrl
...
@@ -160,6 +164,9 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
...
@@ -160,6 +164,9 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
authorLink
!=
null
->
{
authorLink
!=
null
->
{
mapAuthorAttachment
(
this
)
mapAuthorAttachment
(
this
)
}
}
hasActions
->
{
mapActionAttachment
(
this
)
}
else
->
null
else
->
null
}
?.
let
{
list
.
add
(
it
)
}
}
?.
let
{
list
.
add
(
it
)
}
}
}
...
@@ -167,6 +174,25 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
...
@@ -167,6 +174,25 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
return
list
return
list
}
}
private
suspend
fun
mapActionAttachment
(
attachment
:
AttachmentEntity
):
ActionsAttachment
{
val
actions
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getAttachmentActions
(
attachment
.
_id
)
}.
mapNotNull
{
mapAction
(
it
)
}
return
with
(
attachment
)
{
// TODO - remove the default "vertical" value from here...
ActionsAttachment
(
title
,
actions
,
buttonAlignment
?:
"vertical"
)
}
}
private
fun
mapAction
(
action
:
AttachmentActionEntity
):
Action
?
{
return
when
(
action
.
type
)
{
"button"
->
ButtonAction
(
action
.
type
,
action
.
text
,
action
.
url
,
action
.
isWebView
,
action
.
webViewHeightRatio
,
action
.
imageUrl
,
action
.
message
,
action
.
isMessageInChatWindow
)
else
->
null
}
}
private
suspend
fun
mapAuthorAttachment
(
attachment
:
AttachmentEntity
):
AuthorAttachment
{
private
suspend
fun
mapAuthorAttachment
(
attachment
:
AttachmentEntity
):
AuthorAttachment
{
val
fields
=
withContext
(
CommonPool
)
{
val
fields
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getAttachmentFields
(
attachment
.
_id
)
dbManager
.
messageDao
().
getAttachmentFields
(
attachment
.
_id
)
...
...
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