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
540cc085
Commit
540cc085
authored
Nov 19, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More retryDB
parent
c3037e3e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
100 deletions
+118
-100
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+71
-66
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+2
-1
DatabaseManager.kt
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
+2
-2
FavoriteMessagesPresenter.kt
...avoritemessages/presentation/FavoriteMessagesPresenter.kt
+11
-8
FilesPresenter.kt
.../chat/rocket/android/files/presentation/FilesPresenter.kt
+10
-7
MembersPresenter.kt
...t/rocket/android/members/presentation/MembersPresenter.kt
+11
-8
PinnedMessagesPresenter.kt
...id/pinnedmessages/presentation/PinnedMessagesPresenter.kt
+11
-8
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
540cc085
...
...
@@ -39,6 +39,7 @@ import chat.rocket.android.util.extension.getByteArray
import
chat.rocket.android.util.extension.launchUI
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.common.RocketChatException
import
chat.rocket.common.model.RoomType
...
...
@@ -138,7 +139,7 @@ class ChatRoomPresenter @Inject constructor(
}
finally
{
// User has at least an 'owner' or 'moderator' role.
val
userCanMod
=
isOwnerOrMod
()
val
chatRoom
=
dbManager
.
getRoom
(
roomId
)
val
chatRoom
=
retryDB
(
"getRoom($roomId)"
)
{
dbManager
.
getRoom
(
roomId
)
}
val
muted
=
chatRoom
?.
chatRoom
?.
muted
?:
emptyList
()
// Can post anyway if has the 'post-readonly' permission on server.
val
userCanPost
=
userCanMod
||
permissions
.
canPostToReadOnlyChannels
()
||
...
...
@@ -904,77 +905,81 @@ class ChatRoomPresenter @Inject constructor(
// TODO: move this to new interactor or FetchChatRoomsInteractor?
private
suspend
fun
getChatRoomAsync
(
roomId
:
String
):
ChatRoom
?
=
withContext
(
CommonPool
)
{
return
@withContext
dbManager
.
chatRoomDao
().
get
(
roomId
)
?.
let
{
with
(
it
.
chatRoom
)
{
ChatRoom
(
id
=
id
,
subscriptionId
=
subscriptionId
,
type
=
roomTypeOf
(
type
),
unread
=
unread
,
broadcast
=
broadcast
?:
false
,
alert
=
alert
,
fullName
=
fullname
,
name
=
name
,
favorite
=
favorite
?:
false
,
default
=
isDefault
?:
false
,
readonly
=
readonly
,
open
=
open
,
lastMessage
=
null
,
archived
=
false
,
status
=
null
,
user
=
null
,
userMentions
=
userMentions
,
client
=
client
,
announcement
=
null
,
description
=
null
,
groupMentions
=
groupMentions
,
roles
=
null
,
topic
=
null
,
lastSeen
=
this
.
lastSeen
,
timestamp
=
timestamp
,
updatedAt
=
updatedAt
)
retryDB
(
"getRoom($roomId)"
)
{
dbManager
.
chatRoomDao
().
get
(
roomId
)
?.
let
{
with
(
it
.
chatRoom
)
{
ChatRoom
(
id
=
id
,
subscriptionId
=
subscriptionId
,
type
=
roomTypeOf
(
type
),
unread
=
unread
,
broadcast
=
broadcast
?:
false
,
alert
=
alert
,
fullName
=
fullname
,
name
=
name
,
favorite
=
favorite
?:
false
,
default
=
isDefault
?:
false
,
readonly
=
readonly
,
open
=
open
,
lastMessage
=
null
,
archived
=
false
,
status
=
null
,
user
=
null
,
userMentions
=
userMentions
,
client
=
client
,
announcement
=
null
,
description
=
null
,
groupMentions
=
groupMentions
,
roles
=
null
,
topic
=
null
,
lastSeen
=
this
.
lastSeen
,
timestamp
=
timestamp
,
updatedAt
=
updatedAt
)
}
}
}
}
// TODO: move this to new interactor or FetchChatRoomsInteractor?
private
suspend
fun
getChatRoomsAsync
(
name
:
String
?
=
null
):
List
<
ChatRoom
>
=
withContext
(
CommonPool
)
{
return
@withContext
dbManager
.
chatRoomDao
().
getAllSync
().
filter
{
if
(
name
==
null
)
{
return
@filter
true
}
it
.
chatRoom
.
name
==
name
||
it
.
chatRoom
.
fullname
==
name
}.
map
{
with
(
it
.
chatRoom
)
{
ChatRoom
(
id
=
id
,
subscriptionId
=
subscriptionId
,
type
=
roomTypeOf
(
type
),
unread
=
unread
,
broadcast
=
broadcast
?:
false
,
alert
=
alert
,
fullName
=
fullname
,
name
=
name
?:
""
,
favorite
=
favorite
?:
false
,
default
=
isDefault
?:
false
,
readonly
=
readonly
,
open
=
open
,
lastMessage
=
null
,
archived
=
false
,
status
=
null
,
user
=
null
,
userMentions
=
userMentions
,
client
=
client
,
announcement
=
null
,
description
=
null
,
groupMentions
=
groupMentions
,
roles
=
null
,
topic
=
null
,
lastSeen
=
this
.
lastSeen
,
timestamp
=
timestamp
,
updatedAt
=
updatedAt
)
retryDB
(
"getAllSync()"
)
{
dbManager
.
chatRoomDao
().
getAllSync
().
filter
{
if
(
name
==
null
)
{
return
@filter
true
}
it
.
chatRoom
.
name
==
name
||
it
.
chatRoom
.
fullname
==
name
}.
map
{
with
(
it
.
chatRoom
)
{
ChatRoom
(
id
=
id
,
subscriptionId
=
subscriptionId
,
type
=
roomTypeOf
(
type
),
unread
=
unread
,
broadcast
=
broadcast
?:
false
,
alert
=
alert
,
fullName
=
fullname
,
name
=
name
?:
""
,
favorite
=
favorite
?:
false
,
default
=
isDefault
?:
false
,
readonly
=
readonly
,
open
=
open
,
lastMessage
=
null
,
archived
=
false
,
status
=
null
,
user
=
null
,
userMentions
=
userMentions
,
client
=
client
,
announcement
=
null
,
description
=
null
,
groupMentions
=
groupMentions
,
roles
=
null
,
topic
=
null
,
lastSeen
=
this
.
lastSeen
,
timestamp
=
timestamp
,
updatedAt
=
updatedAt
)
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
540cc085
...
...
@@ -13,6 +13,7 @@ import chat.rocket.android.server.domain.useRealName
import
chat.rocket.android.server.domain.useSpecialCharsOnRoom
import
chat.rocket.android.server.infraestructure.ConnectionManager
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.android.util.retryIO
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.RoomType
...
...
@@ -45,7 +46,7 @@ class ChatRoomsPresenter @Inject constructor(
launchUI
(
strategy
)
{
view
.
showLoadingRoom
(
chatRoom
.
name
)
try
{
val
room
=
dbManager
.
getRoom
(
chatRoom
.
id
)
val
room
=
retryDB
(
"getRoom(${chatRoom.id}"
)
{
dbManager
.
getRoom
(
chatRoom
.
id
)
}
if
(
room
!=
null
)
{
loadChatRoom
(
room
.
chatRoom
,
true
)
}
else
{
...
...
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
View file @
540cc085
...
...
@@ -92,8 +92,8 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
}
}
fun
logout
()
{
database
.
clearAllTables
()
suspend
fun
logout
()
{
retryDB
(
"clearAllTables"
)
{
database
.
clearAllTables
()
}
}
suspend
fun
getRoom
(
id
:
String
)
=
withContext
(
dbManagerContext
)
{
...
...
app/src/main/java/chat/rocket/android/favoritemessages/presentation/FavoriteMessagesPresenter.kt
View file @
540cc085
...
...
@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
...
...
@@ -34,14 +35,16 @@ class FavoriteMessagesPresenter @Inject constructor(
launchUI
(
strategy
)
{
try
{
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
favoriteMessages
=
client
.
getFavoriteMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
messageList
=
mapper
.
map
(
favoriteMessages
.
result
,
asNotReversed
=
true
)
view
.
showFavoriteMessages
(
messageList
)
offset
+=
1
*
30
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
retryDB
(
"getRoom($roomId)"
)
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
favoriteMessages
=
client
.
getFavoriteMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
messageList
=
mapper
.
map
(
favoriteMessages
.
result
,
asNotReversed
=
true
)
view
.
showFavoriteMessages
(
messageList
)
offset
+=
1
*
30
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
}
}
}
catch
(
exception
:
RocketChatException
)
{
Timber
.
e
(
exception
)
...
...
app/src/main/java/chat/rocket/android/files/presentation/FilesPresenter.kt
View file @
540cc085
...
...
@@ -7,6 +7,7 @@ import chat.rocket.android.files.uimodel.FileUiModel
import
chat.rocket.android.files.uimodel.FileUiModelMapper
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
...
...
@@ -36,13 +37,15 @@ class FilesPresenter @Inject constructor(
launchUI
(
strategy
)
{
try
{
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
files
=
client
.
getFiles
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
filesUiModel
=
mapper
.
mapToUiModelList
(
files
.
result
)
view
.
showFiles
(
filesUiModel
,
files
.
total
)
offset
+=
1
*
30
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
retryDB
(
"getRoom($roomId)"
)
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
files
=
client
.
getFiles
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
filesUiModel
=
mapper
.
mapToUiModelList
(
files
.
result
)
view
.
showFiles
(
filesUiModel
,
files
.
total
)
offset
+=
1
*
30
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
}
}
}
catch
(
exception
:
RocketChatException
)
{
exception
.
message
?.
let
{
...
...
app/src/main/java/chat/rocket/android/members/presentation/MembersPresenter.kt
View file @
540cc085
...
...
@@ -6,6 +6,7 @@ import chat.rocket.android.members.uimodel.MemberUiModel
import
chat.rocket.android.members.uimodel.MemberUiModelMapper
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
...
...
@@ -36,14 +37,16 @@ class MembersPresenter @Inject constructor(
launchUI
(
strategy
)
{
try
{
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
members
=
client
.
getMembers
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
,
60
)
val
memberUiModels
=
mapper
.
mapToUiModelList
(
members
.
result
)
view
.
showMembers
(
memberUiModels
,
members
.
total
)
offset
+=
1
*
60L
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
retryDB
(
"getRoom($roomId)"
)
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
members
=
client
.
getMembers
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
,
60
)
val
memberUiModels
=
mapper
.
mapToUiModelList
(
members
.
result
)
view
.
showMembers
(
memberUiModels
,
members
.
total
)
offset
+=
1
*
60L
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
}
}
}
catch
(
exception
:
RocketChatException
)
{
exception
.
message
?.
let
{
...
...
app/src/main/java/chat/rocket/android/pinnedmessages/presentation/PinnedMessagesPresenter.kt
View file @
540cc085
...
...
@@ -5,6 +5,7 @@ import chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extension.launchUI
import
chat.rocket.android.util.retryDB
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
...
...
@@ -34,14 +35,16 @@ class PinnedMessagesPresenter @Inject constructor(
launchUI
(
strategy
)
{
try
{
view
.
showLoading
()
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
pinnedMessages
=
client
.
getPinnedMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
,
asNotReversed
=
true
)
view
.
showPinnedMessages
(
messageList
)
offset
+=
1
*
30
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
retryDB
(
"getRoom($roomId)"
)
{
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
pinnedMessages
=
client
.
getPinnedMessages
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
,
asNotReversed
=
true
)
view
.
showPinnedMessages
(
messageList
)
offset
+=
1
*
30
}.
ifNull
{
Timber
.
e
(
"Couldn't find a room with id: $roomId at current server."
)
}
}
}
catch
(
exception
:
RocketChatException
)
{
Timber
.
e
(
exception
)
...
...
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