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
65ebc5bc
Unverified
Commit
65ebc5bc
authored
Nov 23, 2018
by
Lucio Maciel
Committed by
GitHub
Nov 23, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1858 from RocketChat/retry-db
[FIX] Try to avoid locked database
parents
27e71c06
6a0c4051
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
226 additions
and
170 deletions
+226
-170
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+71
-65
ChatRoomsRepository.kt
...t/android/chatrooms/infrastructure/ChatRoomsRepository.kt
+7
-3
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+22
-1
ChatRoomsFragment.kt
...ava/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
+1
-2
DatabaseManager.kt
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
+43
-37
FavoriteMessagesPresenter.kt
...avoritemessages/presentation/FavoriteMessagesPresenter.kt
+2
-1
FilesPresenter.kt
.../chat/rocket/android/files/presentation/FilesPresenter.kt
+1
-0
MembersPresenter.kt
...t/rocket/android/members/presentation/MembersPresenter.kt
+2
-1
PinnedMessagesPresenter.kt
...id/pinnedmessages/presentation/PinnedMessagesPresenter.kt
+2
-1
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+2
-5
DatabaseMessageMapper.kt
...t/android/server/infraestructure/DatabaseMessageMapper.kt
+7
-34
DatabaseMessagesRepository.kt
...roid/server/infraestructure/DatabaseMessagesRepository.kt
+30
-17
IO.kt
app/src/main/java/chat/rocket/android/util/IO.kt
+29
-0
FirebaseMessagingService.kt
...java/chat/rocket/android/push/FirebaseMessagingService.kt
+7
-3
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
65ebc5bc
...
@@ -37,6 +37,8 @@ import chat.rocket.android.server.infraestructure.state
...
@@ -37,6 +37,8 @@ import chat.rocket.android.server.infraestructure.state
import
chat.rocket.android.util.extension.getByteArray
import
chat.rocket.android.util.extension.getByteArray
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extensions.avatarUrl
import
chat.rocket.android.util.extensions.avatarUrl
import
chat.rocket.android.util.extensions.exhaustive
import
chat.rocket.android.util.retryDB
import
chat.rocket.android.util.retryIO
import
chat.rocket.android.util.retryIO
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.RoomType
import
chat.rocket.common.model.RoomType
...
@@ -901,77 +903,81 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -901,77 +903,81 @@ class ChatRoomPresenter @Inject constructor(
// TODO: move this to new interactor or FetchChatRoomsInteractor?
// TODO: move this to new interactor or FetchChatRoomsInteractor?
private
suspend
fun
getChatRoomAsync
(
roomId
:
String
):
ChatRoom
?
=
withContext
(
CommonPool
)
{
private
suspend
fun
getChatRoomAsync
(
roomId
:
String
):
ChatRoom
?
=
withContext
(
CommonPool
)
{
return
@withContext
dbManager
.
chatRoomDao
().
get
(
roomId
)
?.
let
{
retryDB
(
"getRoom($roomId)"
)
{
with
(
it
.
chatRoom
)
{
dbManager
.
chatRoomDao
().
get
(
roomId
)
?.
let
{
ChatRoom
(
with
(
it
.
chatRoom
)
{
id
=
id
,
ChatRoom
(
subscriptionId
=
subscriptionId
,
id
=
id
,
type
=
roomTypeOf
(
type
),
subscriptionId
=
subscriptionId
,
unread
=
unread
,
type
=
roomTypeOf
(
type
),
broadcast
=
broadcast
?:
false
,
unread
=
unread
,
alert
=
alert
,
broadcast
=
broadcast
?:
false
,
fullName
=
fullname
,
alert
=
alert
,
name
=
name
,
fullName
=
fullname
,
favorite
=
favorite
?:
false
,
name
=
name
,
default
=
isDefault
?:
false
,
favorite
=
favorite
?:
false
,
readonly
=
readonly
,
default
=
isDefault
?:
false
,
open
=
open
,
readonly
=
readonly
,
lastMessage
=
null
,
open
=
open
,
archived
=
false
,
lastMessage
=
null
,
status
=
null
,
archived
=
false
,
user
=
null
,
status
=
null
,
userMentions
=
userMentions
,
user
=
null
,
client
=
client
,
userMentions
=
userMentions
,
announcement
=
null
,
client
=
client
,
description
=
null
,
announcement
=
null
,
groupMentions
=
groupMentions
,
description
=
null
,
roles
=
null
,
groupMentions
=
groupMentions
,
topic
=
null
,
roles
=
null
,
lastSeen
=
this
.
lastSeen
,
topic
=
null
,
timestamp
=
timestamp
,
lastSeen
=
this
.
lastSeen
,
updatedAt
=
updatedAt
timestamp
=
timestamp
,
)
updatedAt
=
updatedAt
)
}
}
}
}
}
}
}
// TODO: move this to new interactor or FetchChatRoomsInteractor?
// TODO: move this to new interactor or FetchChatRoomsInteractor?
private
suspend
fun
getChatRoomsAsync
(
name
:
String
?
=
null
):
List
<
ChatRoom
>
=
withContext
(
CommonPool
)
{
private
suspend
fun
getChatRoomsAsync
(
name
:
String
?
=
null
):
List
<
ChatRoom
>
=
withContext
(
CommonPool
)
{
return
@withContext
dbManager
.
chatRoomDao
().
getAllSync
().
filter
{
retryDB
(
"getAllSync()"
)
{
if
(
name
==
null
)
{
dbManager
.
chatRoomDao
().
getAllSync
().
filter
{
return
@filter
true
if
(
name
==
null
)
{
}
return
@filter
true
it
.
chatRoom
.
name
==
name
||
it
.
chatRoom
.
fullname
==
name
}
}.
map
{
it
.
chatRoom
.
name
==
name
||
it
.
chatRoom
.
fullname
==
name
with
(
it
.
chatRoom
)
{
}.
map
{
ChatRoom
(
with
(
it
.
chatRoom
)
{
id
=
id
,
ChatRoom
(
subscriptionId
=
subscriptionId
,
id
=
id
,
type
=
roomTypeOf
(
type
),
subscriptionId
=
subscriptionId
,
unread
=
unread
,
type
=
roomTypeOf
(
type
),
broadcast
=
broadcast
?:
false
,
unread
=
unread
,
alert
=
alert
,
broadcast
=
broadcast
?:
false
,
fullName
=
fullname
,
alert
=
alert
,
name
=
name
?:
""
,
fullName
=
fullname
,
favorite
=
favorite
?:
false
,
name
=
name
?:
""
,
default
=
isDefault
?:
false
,
favorite
=
favorite
?:
false
,
readonly
=
readonly
,
default
=
isDefault
?:
false
,
open
=
open
,
readonly
=
readonly
,
lastMessage
=
null
,
open
=
open
,
archived
=
false
,
lastMessage
=
null
,
status
=
null
,
archived
=
false
,
user
=
null
,
status
=
null
,
userMentions
=
userMentions
,
user
=
null
,
client
=
client
,
userMentions
=
userMentions
,
announcement
=
null
,
client
=
client
,
description
=
null
,
announcement
=
null
,
groupMentions
=
groupMentions
,
description
=
null
,
roles
=
null
,
groupMentions
=
groupMentions
,
topic
=
null
,
roles
=
null
,
lastSeen
=
this
.
lastSeen
,
topic
=
null
,
timestamp
=
timestamp
,
lastSeen
=
this
.
lastSeen
,
updatedAt
=
updatedAt
timestamp
=
timestamp
,
)
updatedAt
=
updatedAt
)
}
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/infrastructure/ChatRoomsRepository.kt
View file @
65ebc5bc
...
@@ -3,9 +3,12 @@ package chat.rocket.android.chatrooms.infrastructure
...
@@ -3,9 +3,12 @@ package chat.rocket.android.chatrooms.infrastructure
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.LiveData
import
chat.rocket.android.db.ChatRoomDao
import
chat.rocket.android.db.ChatRoomDao
import
chat.rocket.android.db.model.ChatRoom
import
chat.rocket.android.db.model.ChatRoom
import
chat.rocket.android.util.retryDB
import
javax.inject.Inject
import
javax.inject.Inject
class
ChatRoomsRepository
@Inject
constructor
(
private
val
dao
:
ChatRoomDao
){
class
ChatRoomsRepository
@Inject
constructor
(
private
val
dao
:
ChatRoomDao
)
{
// TODO - check how to use retryDB here - suspend
fun
getChatRooms
(
order
:
Order
):
LiveData
<
List
<
ChatRoom
>>
{
fun
getChatRooms
(
order
:
Order
):
LiveData
<
List
<
ChatRoom
>>
{
return
when
(
order
)
{
return
when
(
order
)
{
Order
.
ACTIVITY
->
dao
.
getAll
()
Order
.
ACTIVITY
->
dao
.
getAll
()
...
@@ -15,9 +18,10 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao){
...
@@ -15,9 +18,10 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao){
}
}
}
}
fun
search
(
query
:
String
)
=
dao
.
searchSync
(
query
)
suspend
fun
search
(
query
:
String
)
=
retryDB
(
"roomSearch($query)"
)
{
dao
.
searchSync
(
query
)
}
fun
count
()
=
dao
.
count
()
suspend
fun
count
()
=
retryDB
(
"roomsCount"
)
{
dao
.
count
()
}
enum
class
Order
{
enum
class
Order
{
ACTIVITY
,
ACTIVITY
,
...
...
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
65ebc5bc
...
@@ -13,6 +13,7 @@ import chat.rocket.android.server.domain.useRealName
...
@@ -13,6 +13,7 @@ import chat.rocket.android.server.domain.useRealName
import
chat.rocket.android.server.domain.useSpecialCharsOnRoom
import
chat.rocket.android.server.domain.useSpecialCharsOnRoom
import
chat.rocket.android.server.infraestructure.ConnectionManager
import
chat.rocket.android.server.infraestructure.ConnectionManager
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.android.util.retryIO
import
chat.rocket.android.util.retryIO
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.RoomType
import
chat.rocket.common.model.RoomType
...
@@ -41,11 +42,31 @@ class ChatRoomsPresenter @Inject constructor(
...
@@ -41,11 +42,31 @@ class ChatRoomsPresenter @Inject constructor(
private
val
client
=
manager
.
client
private
val
client
=
manager
.
client
private
val
settings
=
settingsRepository
.
get
(
currentServer
)
private
val
settings
=
settingsRepository
.
get
(
currentServer
)
fun
loadChatRoom
(
roomId
:
String
)
{
launchUI
(
strategy
)
{
view
.
showLoadingRoom
(
""
)
try
{
val
room
=
dbManager
.
getRoom
(
roomId
)
if
(
room
!=
null
)
{
loadChatRoom
(
room
.
chatRoom
,
true
)
}
else
{
Timber
.
d
(
"Error loading channel"
)
view
.
showGenericErrorMessage
()
}
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error loading channel"
)
view
.
showGenericErrorMessage
()
}
finally
{
view
.
hideLoadingRoom
()
}
}
}
fun
loadChatRoom
(
chatRoom
:
RoomUiModel
)
{
fun
loadChatRoom
(
chatRoom
:
RoomUiModel
)
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
showLoadingRoom
(
chatRoom
.
name
)
view
.
showLoadingRoom
(
chatRoom
.
name
)
try
{
try
{
val
room
=
dbManager
.
getRoom
(
chatRoom
.
id
)
val
room
=
retryDB
(
"getRoom(${chatRoom.id}"
)
{
dbManager
.
getRoom
(
chatRoom
.
id
)
}
if
(
room
!=
null
)
{
if
(
room
!=
null
)
{
loadChatRoom
(
room
.
chatRoom
,
true
)
loadChatRoom
(
room
.
chatRoom
,
true
)
}
else
{
}
else
{
...
...
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
View file @
65ebc5bc
...
@@ -84,8 +84,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
...
@@ -84,8 +84,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
if
(
bundle
!=
null
)
{
if
(
bundle
!=
null
)
{
chatRoomId
=
bundle
.
getString
(
BUNDLE_CHAT_ROOM_ID
)
chatRoomId
=
bundle
.
getString
(
BUNDLE_CHAT_ROOM_ID
)
chatRoomId
?.
let
{
chatRoomId
?.
let
{
// TODO - bring back support to load a room from id.
presenter
.
loadChatRoom
(
it
)
//presenter.goToChatRoomWithId(it)
chatRoomId
=
null
chatRoomId
=
null
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
View file @
65ebc5bc
...
@@ -19,6 +19,7 @@ import chat.rocket.android.util.extensions.exhaustive
...
@@ -19,6 +19,7 @@ import chat.rocket.android.util.extensions.exhaustive
import
chat.rocket.android.util.extensions.removeTrailingSlash
import
chat.rocket.android.util.extensions.removeTrailingSlash
import
chat.rocket.android.util.extensions.toEntity
import
chat.rocket.android.util.extensions.toEntity
import
chat.rocket.android.util.extensions.userId
import
chat.rocket.android.util.extensions.userId
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.model.BaseRoom
import
chat.rocket.common.model.BaseRoom
import
chat.rocket.common.model.RoomType
import
chat.rocket.common.model.RoomType
import
chat.rocket.common.model.SimpleUser
import
chat.rocket.common.model.SimpleUser
...
@@ -91,12 +92,14 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
...
@@ -91,12 +92,14 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
}
}
}
}
fun
logout
()
{
suspend
fun
logout
()
{
database
.
clearAllTables
()
retryDB
(
"clearAllTables"
)
{
database
.
clearAllTables
()
}
}
}
suspend
fun
getRoom
(
id
:
String
)
=
withContext
(
dbManagerContext
)
{
suspend
fun
getRoom
(
id
:
String
)
=
withContext
(
dbManagerContext
)
{
chatRoomDao
().
get
(
id
)
retryDB
(
"getRoom($id)"
)
{
chatRoomDao
().
get
(
id
)
}
}
}
fun
processUsersBatch
(
users
:
List
<
User
>)
{
fun
processUsersBatch
(
users
:
List
<
User
>)
{
...
@@ -151,7 +154,7 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
...
@@ -151,7 +154,7 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
fun
updateSelfUser
(
myself
:
Myself
)
{
fun
updateSelfUser
(
myself
:
Myself
)
{
launch
(
dbManagerContext
)
{
launch
(
dbManagerContext
)
{
val
user
=
userDao
().
getUser
(
myself
.
id
)
val
user
=
retryDB
(
"getUser(${myself.id})"
)
{
userDao
().
getUser
(
myself
.
id
)
}
val
entity
=
user
?.
copy
(
val
entity
=
user
?.
copy
(
name
=
myself
.
name
?:
user
.
name
,
name
=
myself
.
name
?:
user
.
name
,
username
=
myself
.
username
?:
user
.
username
,
username
=
myself
.
username
?:
user
.
username
,
...
@@ -335,7 +338,7 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
...
@@ -335,7 +338,7 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
}
}
private
suspend
fun
updateRoom
(
data
:
Room
):
ChatRoomEntity
?
{
private
suspend
fun
updateRoom
(
data
:
Room
):
ChatRoomEntity
?
{
return
chatRoomDao
().
get
(
data
.
id
)
?.
let
{
current
->
return
retryDB
(
"getChatRoom(${data.id})"
)
{
chatRoomDao
().
get
(
data
.
id
)
}
?.
let
{
current
->
with
(
data
)
{
with
(
data
)
{
val
chatRoom
=
current
.
chatRoom
val
chatRoom
=
current
.
chatRoom
...
@@ -373,7 +376,7 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
...
@@ -373,7 +376,7 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
context
.
getString
(
R
.
string
.
msg_sent_attachment
)
context
.
getString
(
R
.
string
.
msg_sent_attachment
)
private
suspend
fun
updateSubscription
(
data
:
Subscription
):
ChatRoomEntity
?
{
private
suspend
fun
updateSubscription
(
data
:
Subscription
):
ChatRoomEntity
?
{
return
chatRoomDao
().
get
(
data
.
roomId
)
?.
let
{
current
->
return
retryDB
(
"getRoom(${data.roomId}"
)
{
chatRoomDao
().
get
(
data
.
roomId
)
}
?.
let
{
current
->
with
(
data
)
{
with
(
data
)
{
val
userId
=
if
(
type
is
RoomType
.
DirectMessage
)
{
val
userId
=
if
(
type
is
RoomType
.
DirectMessage
)
{
...
@@ -539,39 +542,42 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
...
@@ -539,39 +542,42 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
}
}
}
}
private
fun
findUser
(
userId
:
String
):
String
?
=
userDao
().
findUser
(
userId
)
private
suspend
fun
findUser
(
userId
:
String
):
String
?
=
retryDB
(
"findUser($userId)"
)
{
userDao
().
findUser
(
userId
)
}
private
fun
doOperation
(
operation
:
Operation
)
{
private
suspend
fun
doOperation
(
operation
:
Operation
)
{
when
(
operation
)
{
retryDB
(
description
=
"doOperation($operation)"
)
{
is
Operation
.
ClearStatus
->
userDao
().
clearStatus
()
when
(
operation
)
{
is
Operation
.
UpdateRooms
->
{
is
Operation
.
ClearStatus
->
userDao
().
clearStatus
()
Timber
.
d
(
"Running ChatRooms transaction: remove: ${operation.toRemove} - insert: ${operation.toInsert} - update: ${operation.toUpdate}"
)
is
Operation
.
UpdateRooms
->
{
Timber
.
d
(
"Running ChatRooms transaction: remove: ${operation.toRemove} - insert: ${operation.toInsert} - update: ${operation.toUpdate}"
)
chatRoomDao
().
update
(
operation
.
toInsert
,
operation
.
toUpdate
,
operation
.
toRemove
)
chatRoomDao
().
update
(
operation
.
toInsert
,
operation
.
toUpdate
,
operation
.
toRemove
)
}
}
is
Operation
.
InsertRooms
->
{
is
Operation
.
InsertRooms
->
{
chatRoomDao
().
insertOrReplace
(
operation
.
chatRooms
)
chatRoomDao
().
insertOrReplace
(
operation
.
chatRooms
)
}
}
is
Operation
.
CleanInsertRooms
->
{
is
Operation
.
CleanInsertRooms
->
{
chatRoomDao
().
cleanInsert
(
operation
.
chatRooms
)
chatRoomDao
().
cleanInsert
(
operation
.
chatRooms
)
}
}
is
Operation
.
InsertUsers
->
{
is
Operation
.
InsertUsers
->
{
val
time
=
measureTimeMillis
{
userDao
().
upsert
(
operation
.
users
)
}
val
time
=
measureTimeMillis
{
userDao
().
upsert
(
operation
.
users
)
}
Timber
.
d
(
"Upserted users batch(${operation.users.size}) in $time MS"
)
Timber
.
d
(
"Upserted users batch(${operation.users.size}) in $time MS"
)
}
}
is
Operation
.
InsertUser
->
{
is
Operation
.
InsertUser
->
{
userDao
().
insert
(
operation
.
user
)
userDao
().
insert
(
operation
.
user
)
}
}
is
Operation
.
UpsertUser
->
{
is
Operation
.
UpsertUser
->
{
userDao
().
upsert
(
operation
.
user
)
userDao
().
upsert
(
operation
.
user
)
}
}
is
Operation
.
InsertMessages
->
{
is
Operation
.
InsertMessages
->
{
messageDao
().
insert
(
operation
.
list
)
messageDao
().
insert
(
operation
.
list
)
}
}
is
Operation
.
SaveLastSync
->
{
is
Operation
.
SaveLastSync
->
{
messageDao
().
saveLastSync
(
operation
.
sync
)
messageDao
().
saveLastSync
(
operation
.
sync
)
}
}
}.
exhaustive
}.
exhaustive
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/favoritemessages/presentation/FavoriteMessagesPresenter.kt
View file @
65ebc5bc
...
@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
...
@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
...
@@ -36,7 +37,7 @@ class FavoriteMessagesPresenter @Inject constructor(
...
@@ -36,7 +37,7 @@ class FavoriteMessagesPresenter @Inject constructor(
view
.
showLoading
()
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
favoriteMessages
=
val
favoriteMessages
=
client
.
getFavoriteMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
client
.
getFavoriteMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
messageList
=
mapper
.
map
(
favoriteMessages
.
result
,
asNotReversed
=
true
)
val
messageList
=
mapper
.
map
(
favoriteMessages
.
result
,
asNotReversed
=
true
)
view
.
showFavoriteMessages
(
messageList
)
view
.
showFavoriteMessages
(
messageList
)
offset
+=
1
*
30
offset
+=
1
*
30
...
...
app/src/main/java/chat/rocket/android/files/presentation/FilesPresenter.kt
View file @
65ebc5bc
...
@@ -7,6 +7,7 @@ import chat.rocket.android.files.uimodel.FileUiModel
...
@@ -7,6 +7,7 @@ import chat.rocket.android.files.uimodel.FileUiModel
import
chat.rocket.android.files.uimodel.FileUiModelMapper
import
chat.rocket.android.files.uimodel.FileUiModelMapper
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
...
...
app/src/main/java/chat/rocket/android/members/presentation/MembersPresenter.kt
View file @
65ebc5bc
...
@@ -6,6 +6,7 @@ import chat.rocket.android.members.uimodel.MemberUiModel
...
@@ -6,6 +6,7 @@ import chat.rocket.android.members.uimodel.MemberUiModel
import
chat.rocket.android.members.uimodel.MemberUiModelMapper
import
chat.rocket.android.members.uimodel.MemberUiModelMapper
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
...
@@ -38,7 +39,7 @@ class MembersPresenter @Inject constructor(
...
@@ -38,7 +39,7 @@ class MembersPresenter @Inject constructor(
view
.
showLoading
()
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
members
=
val
members
=
client
.
getMembers
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
,
60
)
client
.
getMembers
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
,
60
)
val
memberUiModels
=
mapper
.
mapToUiModelList
(
members
.
result
)
val
memberUiModels
=
mapper
.
mapToUiModelList
(
members
.
result
)
view
.
showMembers
(
memberUiModels
,
members
.
total
)
view
.
showMembers
(
memberUiModels
,
members
.
total
)
offset
+=
1
*
60L
offset
+=
1
*
60L
...
...
app/src/main/java/chat/rocket/android/pinnedmessages/presentation/PinnedMessagesPresenter.kt
View file @
65ebc5bc
...
@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
...
@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
...
@@ -36,7 +37,7 @@ class PinnedMessagesPresenter @Inject constructor(
...
@@ -36,7 +37,7 @@ class PinnedMessagesPresenter @Inject constructor(
view
.
showLoading
()
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
pinnedMessages
=
val
pinnedMessages
=
client
.
getPinnedMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
client
.
getPinnedMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
,
asNotReversed
=
true
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
,
asNotReversed
=
true
)
view
.
showPinnedMessages
(
messageList
)
view
.
showPinnedMessages
(
messageList
)
offset
+=
1
*
30
offset
+=
1
*
30
...
...
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
65ebc5bc
...
@@ -296,11 +296,8 @@ class PushManager @Inject constructor(
...
@@ -296,11 +296,8 @@ class PushManager @Inject constructor(
}
}
private
fun
getContentIntent
(
context
:
Context
,
notificationId
:
Int
,
pushMessage
:
PushMessage
,
grouped
:
Boolean
=
false
):
PendingIntent
{
private
fun
getContentIntent
(
context
:
Context
,
notificationId
:
Int
,
pushMessage
:
PushMessage
,
grouped
:
Boolean
=
false
):
PendingIntent
{
val
notificationIntent
=
context
.
changeServerIntent
(
pushMessage
.
info
.
host
,
chatRoomId
=
pushMessage
.
info
.
roomId
)
val
roomId
=
if
(!
grouped
)
pushMessage
.
info
.
roomId
else
null
// TODO - add support to go directly to the chatroom
val
notificationIntent
=
context
.
changeServerIntent
(
pushMessage
.
info
.
host
,
chatRoomId
=
roomId
)
/*if (!isGrouped) {
notificationIntent.putExtra(EXTRA_ROOM_ID, pushMessage.info.roomId)
}*/
return
PendingIntent
.
getActivity
(
context
,
random
.
nextInt
(),
notificationIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
return
PendingIntent
.
getActivity
(
context
,
random
.
nextInt
(),
notificationIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
}
}
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/DatabaseMessageMapper.kt
View file @
65ebc5bc
...
@@ -7,6 +7,7 @@ import chat.rocket.android.db.model.FullMessage
...
@@ -7,6 +7,7 @@ import chat.rocket.android.db.model.FullMessage
import
chat.rocket.android.db.model.ReactionEntity
import
chat.rocket.android.db.model.ReactionEntity
import
chat.rocket.android.db.model.UrlEntity
import
chat.rocket.android.db.model.UrlEntity
import
chat.rocket.android.db.model.UserEntity
import
chat.rocket.android.db.model.UserEntity
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.model.SimpleRoom
import
chat.rocket.common.model.SimpleRoom
import
chat.rocket.common.model.SimpleUser
import
chat.rocket.common.model.SimpleUser
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
...
@@ -135,14 +136,18 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
...
@@ -135,14 +136,18 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
with
(
attachment
)
{
with
(
attachment
)
{
val
fields
=
if
(
hasFields
)
{
val
fields
=
if
(
hasFields
)
{
withContext
(
CommonPool
)
{
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getAttachmentFields
(
attachment
.
_id
)
retryDB
(
"getAttachmentFields(${attachment._id})"
)
{
dbManager
.
messageDao
().
getAttachmentFields
(
attachment
.
_id
)
}
}.
map
{
Field
(
it
.
title
,
it
.
value
)
}
}.
map
{
Field
(
it
.
title
,
it
.
value
)
}
}
else
{
}
else
{
null
null
}
}
val
actions
=
if
(
hasActions
)
{
val
actions
=
if
(
hasActions
)
{
withContext
(
CommonPool
)
{
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getAttachmentActions
(
attachment
.
_id
)
retryDB
(
"getAttachmentActions(${attachment._id})"
)
{
dbManager
.
messageDao
().
getAttachmentActions
(
attachment
.
_id
)
}
}.
mapNotNull
{
mapAction
(
it
)
}
}.
mapNotNull
{
mapAction
(
it
)
}
}
else
{
}
else
{
null
null
...
@@ -183,29 +188,6 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
...
@@ -183,29 +188,6 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
return
list
return
list
}
}
/*private suspend fun mapColorAttachmentWithFields(entity: AttachmentEntity): ColorAttachment {
val fields = withContext(CommonPool) {
dbManager.messageDao().getAttachmentFields(entity._id)
}.map { Field(it.title, it.value) }
return with(entity) {
ColorAttachment(
color = Color.Custom(color ?: DEFAULT_COLOR_STR),
text = text ?: "",
fallback = fallback,
fields = fields)
}
}
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
?
{
private
fun
mapAction
(
action
:
AttachmentActionEntity
):
Action
?
{
return
when
(
action
.
type
)
{
return
when
(
action
.
type
)
{
"button"
->
ButtonAction
(
action
.
type
,
action
.
text
,
action
.
url
,
action
.
isWebView
,
"button"
->
ButtonAction
(
action
.
type
,
action
.
text
,
action
.
url
,
action
.
isWebView
,
...
@@ -214,13 +196,4 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
...
@@ -214,13 +196,4 @@ class DatabaseMessageMapper(private val dbManager: DatabaseManager) {
else
->
null
else
->
null
}
}
}
}
/*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
app/src/main/java/chat/rocket/android/server/infraestructure/DatabaseMessagesRepository.kt
View file @
65ebc5bc
...
@@ -4,6 +4,7 @@ import chat.rocket.android.db.DatabaseManager
...
@@ -4,6 +4,7 @@ import chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.Operation
import
chat.rocket.android.db.Operation
import
chat.rocket.android.db.model.MessagesSync
import
chat.rocket.android.db.model.MessagesSync
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.android.util.retryDB
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.withContext
import
kotlinx.coroutines.experimental.withContext
...
@@ -14,25 +15,31 @@ class DatabaseMessagesRepository(
...
@@ -14,25 +15,31 @@ class DatabaseMessagesRepository(
)
:
MessagesRepository
{
)
:
MessagesRepository
{
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getMessageById
(
id
)
?.
let
{
message
->
mapper
.
map
(
message
)
}
retryDB
(
"getMessageById($id)"
)
{
dbManager
.
messageDao
().
getMessageById
(
id
)
?.
let
{
message
->
mapper
.
map
(
message
)
}
}
}
}
override
suspend
fun
getByRoomId
(
roomId
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
getByRoomId
(
roomId
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
// FIXME - investigate how to avoid this distinctBy here, since DAO is returning a lot of
// FIXME - investigate how to avoid this distinctBy here, since DAO is returning a lot of
// duplicate rows (something related to our JOINS and relations on Room)
// duplicate rows (something related to our JOINS and relations on Room)
dbManager
.
messageDao
().
getMessagesByRoomId
(
roomId
)
retryDB
(
"getMessagesByRoomId($roomId)"
)
{
.
distinctBy
{
it
.
message
.
message
.
id
}
dbManager
.
messageDao
().
getMessagesByRoomId
(
roomId
)
.
let
{
messages
->
.
distinctBy
{
it
.
message
.
message
.
id
}
mapper
.
map
(
messages
)
.
let
{
messages
->
}
mapper
.
map
(
messages
)
}
}
}
}
override
suspend
fun
getRecentMessages
(
roomId
:
String
,
count
:
Long
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
getRecentMessages
(
roomId
:
String
,
count
:
Long
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getRecentMessagesByRoomId
(
roomId
,
count
)
retryDB
(
"getRecentMessagesByRoomId($roomId, $count)"
)
{
.
distinctBy
{
it
.
message
.
message
.
id
}
dbManager
.
messageDao
().
getRecentMessagesByRoomId
(
roomId
,
count
)
.
let
{
messages
->
.
distinctBy
{
it
.
message
.
message
.
id
}
mapper
.
map
(
messages
)
.
let
{
messages
->
}
mapper
.
map
(
messages
)
}
}
}
}
override
suspend
fun
save
(
message
:
Message
)
{
override
suspend
fun
save
(
message
:
Message
)
{
...
@@ -45,20 +52,24 @@ class DatabaseMessagesRepository(
...
@@ -45,20 +52,24 @@ class DatabaseMessagesRepository(
override
suspend
fun
removeById
(
id
:
String
)
{
override
suspend
fun
removeById
(
id
:
String
)
{
withContext
(
CommonPool
)
{
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
delete
(
id
)
retryDB
(
"delete($id)"
)
{
dbManager
.
messageDao
().
delete
(
id
)
}
}
}
}
}
override
suspend
fun
removeByRoomId
(
roomId
:
String
)
{
override
suspend
fun
removeByRoomId
(
roomId
:
String
)
{
withContext
(
CommonPool
)
{
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
deleteByRoomId
(
roomId
)
retryDB
(
"deleteByRoomId($roomId)"
)
{
dbManager
.
messageDao
().
deleteByRoomId
(
roomId
)
}
}
}
}
}
override
suspend
fun
getAllUnsent
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
override
suspend
fun
getAllUnsent
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getUnsentMessages
()
retryDB
(
"getUnsentMessages"
)
{
.
distinctBy
{
it
.
message
.
message
.
id
}
dbManager
.
messageDao
().
getUnsentMessages
()
.
let
{
mapper
.
map
(
it
)
}
.
distinctBy
{
it
.
message
.
message
.
id
}
.
let
{
mapper
.
map
(
it
)
}
}
}
}
override
suspend
fun
saveLastSyncDate
(
roomId
:
String
,
timeMillis
:
Long
)
{
override
suspend
fun
saveLastSyncDate
(
roomId
:
String
,
timeMillis
:
Long
)
{
...
@@ -66,6 +77,8 @@ class DatabaseMessagesRepository(
...
@@ -66,6 +77,8 @@ class DatabaseMessagesRepository(
}
}
override
suspend
fun
getLastSyncDate
(
roomId
:
String
):
Long
?
=
withContext
(
CommonPool
)
{
override
suspend
fun
getLastSyncDate
(
roomId
:
String
):
Long
?
=
withContext
(
CommonPool
)
{
dbManager
.
messageDao
().
getLastSync
(
roomId
)
?.
let
{
it
.
timestamp
}
retryDB
(
"getLastSync($roomId)"
)
{
dbManager
.
messageDao
().
getLastSync
(
roomId
)
?.
let
{
it
.
timestamp
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/IO.kt
View file @
65ebc5bc
package
chat.rocket.android.util
package
chat.rocket.android.util
import
android.database.sqlite.SQLiteDatabaseLockedException
import
chat.rocket.common.RocketChatNetworkErrorException
import
chat.rocket.common.RocketChatNetworkErrorException
import
kotlinx.coroutines.experimental.TimeoutCancellationException
import
kotlinx.coroutines.experimental.TimeoutCancellationException
import
kotlinx.coroutines.experimental.delay
import
kotlinx.coroutines.experimental.delay
...
@@ -8,6 +9,7 @@ import timber.log.Timber
...
@@ -8,6 +9,7 @@ import timber.log.Timber
import
kotlin.coroutines.experimental.coroutineContext
import
kotlin.coroutines.experimental.coroutineContext
const
val
DEFAULT_RETRY
=
3
const
val
DEFAULT_RETRY
=
3
private
const
val
DEFAULT_DB_RETRY
=
5
suspend
fun
<
T
>
retryIO
(
suspend
fun
<
T
>
retryIO
(
description
:
String
=
"<missing description>"
,
description
:
String
=
"<missing description>"
,
...
@@ -32,6 +34,33 @@ suspend fun <T> retryIO(
...
@@ -32,6 +34,33 @@ suspend fun <T> retryIO(
currentDelay
=
(
currentDelay
*
factor
).
toLong
().
coerceAtMost
(
maxDelay
)
currentDelay
=
(
currentDelay
*
factor
).
toLong
().
coerceAtMost
(
maxDelay
)
}
}
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
return
block
()
// last attempt
}
suspend
fun
<
T
>
retryDB
(
description
:
String
=
"<missing description>"
,
times
:
Int
=
DEFAULT_DB_RETRY
,
initialDelay
:
Long
=
100
,
// 0.1 second
maxDelay
:
Long
=
500
,
// 0.5 second
factor
:
Double
=
1.2
,
block
:
suspend
()
->
T
):
T
{
var
currentDelay
=
initialDelay
repeat
(
times
-
1
)
{
currentTry
->
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
try
{
return
block
()
}
catch
(
e
:
SQLiteDatabaseLockedException
)
{
Timber
.
d
(
e
,
"failed call($currentTry): $description"
)
e
.
printStackTrace
()
}
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
delay
(
currentDelay
)
currentDelay
=
(
currentDelay
*
factor
).
toLong
().
coerceAtMost
(
maxDelay
)
}
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
return
block
()
// last attempt
return
block
()
// last attempt
}
}
\ No newline at end of file
app/src/play/java/chat/rocket/android/push/FirebaseMessagingService.kt
View file @
65ebc5bc
package
chat.rocket.android.push
package
chat.rocket.android.push
import
android.os.Bundle
import
androidx.core.os.bundleOf
import
androidx.core.os.bundleOf
import
androidx.work.Constraints
import
androidx.work.Constraints
import
androidx.work.NetworkType
import
androidx.work.NetworkType
...
@@ -23,9 +24,12 @@ class FirebaseMessagingService : FirebaseMessagingService() {
...
@@ -23,9 +24,12 @@ class FirebaseMessagingService : FirebaseMessagingService() {
}
}
override
fun
onMessageReceived
(
message
:
RemoteMessage
)
{
override
fun
onMessageReceived
(
message
:
RemoteMessage
)
{
// XXX - for now this is ok, if we start to do network calls, use a Worker instead
message
.
data
?.
let
{
data
->
message
.
data
?.
let
{
val
bundle
=
Bundle
()
pushManager
.
handle
(
bundleOf
(*(
it
.
map
{
Pair
(
it
.
key
,
it
.
value
)
}).
toTypedArray
()))
data
.
entries
.
forEach
{
entry
->
bundle
.
putString
(
entry
.
key
,
entry
.
value
)
}
pushManager
.
handle
(
bundle
)
}
}
}
}
...
...
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