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
ccec99f5
Commit
ccec99f5
authored
May 14, 2019
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix coding issues.
parent
42c34407
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
82 deletions
+104
-82
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+104
-82
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
ccec99f5
...
@@ -118,7 +118,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -118,7 +118,7 @@ class ChatRoomPresenter @Inject constructor(
private
var
chatRoomId
:
String
?
=
null
private
var
chatRoomId
:
String
?
=
null
private
lateinit
var
chatRoomType
:
String
private
lateinit
var
chatRoomType
:
String
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomName
:
String
private
var
chatI
sBroadcast
:
Boolean
=
false
private
var
i
sBroadcast
:
Boolean
=
false
private
var
chatRoles
=
emptyList
<
ChatRoomRole
>()
private
var
chatRoles
=
emptyList
<
ChatRoomRole
>()
private
val
stateChannel
=
Channel
<
State
>()
private
val
stateChannel
=
Channel
<
State
>()
private
var
typingStatusSubscriptionId
:
String
?
=
null
private
var
typingStatusSubscriptionId
:
String
?
=
null
...
@@ -145,14 +145,16 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -145,14 +145,16 @@ class ChatRoomPresenter @Inject constructor(
// Can post anyway if has the 'post-readonly' permission on server.
// Can post anyway if has the 'post-readonly' permission on server.
val
room
=
dbManager
.
getRoom
(
roomId
)
val
room
=
dbManager
.
getRoom
(
roomId
)
room
?.
let
{
room
?.
let
{
chatI
sBroadcast
=
it
.
chatRoom
.
broadcast
?:
false
i
sBroadcast
=
it
.
chatRoom
.
broadcast
?:
false
val
roomUiModel
=
roomMapper
.
map
(
it
,
true
)
val
roomUiModel
=
roomMapper
.
map
(
it
,
true
)
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
onRoomUpdated
(
roomUiModel
=
roomUiModel
.
copy
(
view
.
onRoomUpdated
(
broadcast
=
chatIsBroadcast
,
roomUiModel
=
roomUiModel
.
copy
(
broadcast
=
isBroadcast
,
canModerate
=
canModerate
,
canModerate
=
canModerate
,
writable
=
roomUiModel
.
writable
||
canModerate
writable
=
roomUiModel
.
writable
||
canModerate
))
)
)
}
}
}
}
...
@@ -188,14 +190,16 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -188,14 +190,16 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
}
private
suspend
fun
getChatRole
()
:
Boolean
{
private
suspend
fun
getChatRole
():
Boolean
{
var
returnVal
=
false
try
{
try
{
if
(
roomTypeOf
(
chatRoomType
)
!
is
RoomType
.
DirectMessage
)
{
if
(
roomTypeOf
(
chatRoomType
)
!
is
RoomType
.
DirectMessage
)
{
chatRoles
=
withContext
(
Dispatchers
.
IO
+
strategy
.
jobs
)
{
chatRoles
=
withContext
(
Dispatchers
.
IO
+
strategy
.
jobs
)
{
client
.
chatRoomRoles
(
roomType
=
roomTypeOf
(
chatRoomType
),
roomName
=
chatRoomName
)
client
.
chatRoomRoles
(
roomType
=
roomTypeOf
(
chatRoomType
),
roomName
=
chatRoomName
)
}
}
return
Val
=
true
return
true
}
else
{
}
else
{
chatRoles
=
emptyList
()
chatRoles
=
emptyList
()
}
}
...
@@ -203,7 +207,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -203,7 +207,7 @@ class ChatRoomPresenter @Inject constructor(
Timber
.
e
(
ex
)
Timber
.
e
(
ex
)
chatRoles
=
emptyList
()
chatRoles
=
emptyList
()
}
}
return
returnVal
return
false
}
}
private
suspend
fun
subscribeRoomChanges
()
{
private
suspend
fun
subscribeRoomChanges
()
{
...
@@ -212,7 +216,12 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -212,7 +216,12 @@ class ChatRoomPresenter @Inject constructor(
manager
.
addRoomChannel
(
it
,
roomChangesChannel
)
manager
.
addRoomChannel
(
it
,
roomChangesChannel
)
for
(
room
in
roomChangesChannel
)
{
for
(
room
in
roomChangesChannel
)
{
dbManager
.
getRoom
(
room
.
id
)
?.
let
{
chatRoom
->
dbManager
.
getRoom
(
room
.
id
)
?.
let
{
chatRoom
->
view
.
onRoomUpdated
(
roomMapper
.
map
(
chatRoom
=
chatRoom
,
showLastMessage
=
true
))
view
.
onRoomUpdated
(
roomMapper
.
map
(
chatRoom
=
chatRoom
,
showLastMessage
=
true
)
)
}
}
}
}
}
}
...
@@ -248,7 +257,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -248,7 +257,7 @@ class ChatRoomPresenter @Inject constructor(
localMessages
,
RoomUiModel
(
localMessages
,
RoomUiModel
(
roles
=
chatRoles
,
roles
=
chatRoles
,
// FIXME: Why are we fixing isRoom attribute to true here?
// FIXME: Why are we fixing isRoom attribute to true here?
isBroadcast
=
chatI
sBroadcast
,
isRoom
=
true
isBroadcast
=
i
sBroadcast
,
isRoom
=
true
)
)
)
)
lastMessageId
=
localMessages
.
firstOrNull
()
?.
id
lastMessageId
=
localMessages
.
firstOrNull
()
?.
id
...
@@ -309,7 +318,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -309,7 +318,7 @@ class ChatRoomPresenter @Inject constructor(
view
.
showMessages
(
view
.
showMessages
(
mapper
.
map
(
mapper
.
map
(
messages
,
messages
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatI
sBroadcast
,
isRoom
=
true
)
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
i
sBroadcast
,
isRoom
=
true
)
),
),
clearDataSet
clearDataSet
)
)
...
@@ -325,7 +334,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -325,7 +334,7 @@ class ChatRoomPresenter @Inject constructor(
view
.
showSearchedMessages
(
view
.
showSearchedMessages
(
mapper
.
map
(
mapper
.
map
(
messages
,
messages
,
RoomUiModel
(
chatRoles
,
chatI
sBroadcast
,
true
)
RoomUiModel
(
chatRoles
,
i
sBroadcast
,
true
)
)
)
)
)
}
catch
(
ex
:
Exception
)
{
}
catch
(
ex
:
Exception
)
{
...
@@ -357,7 +366,11 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -357,7 +366,11 @@ class ChatRoomPresenter @Inject constructor(
timestamp
=
Instant
.
now
().
toEpochMilli
(),
timestamp
=
Instant
.
now
().
toEpochMilli
(),
sender
=
SimpleUser
(
user
?.
id
,
user
?.
username
?:
username
,
user
?.
name
),
sender
=
SimpleUser
(
user
?.
id
,
user
?.
username
?:
username
,
user
?.
name
),
attachments
=
null
,
attachments
=
null
,
avatar
=
currentServer
.
avatarUrl
(
username
!!
,
token
?.
userId
,
token
?.
authToken
),
avatar
=
currentServer
.
avatarUrl
(
username
!!
,
token
?.
userId
,
token
?.
authToken
),
channels
=
null
,
channels
=
null
,
editedAt
=
null
,
editedAt
=
null
,
editedBy
=
null
,
editedBy
=
null
,
...
@@ -379,7 +392,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -379,7 +392,7 @@ class ChatRoomPresenter @Inject constructor(
view
.
showNewMessage
(
view
.
showNewMessage
(
mapper
.
map
(
mapper
.
map
(
newMessage
,
newMessage
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatI
sBroadcast
)
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
i
sBroadcast
)
),
false
),
false
)
)
client
.
sendMessage
(
id
,
chatRoomId
,
text
)
client
.
sendMessage
(
id
,
chatRoomId
,
text
)
...
@@ -630,16 +643,21 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -630,16 +643,21 @@ class ChatRoomPresenter @Inject constructor(
Timber
.
d
(
"History: $messages"
)
Timber
.
d
(
"History: $messages"
)
if
(
messages
.
result
.
isNotEmpty
())
{
if
(
messages
.
result
.
isNotEmpty
())
{
val
models
=
mapper
.
map
(
messages
.
result
,
RoomUiModel
(
val
models
=
mapper
.
map
(
messages
.
result
,
RoomUiModel
(
roles
=
chatRoles
,
roles
=
chatRoles
,
isBroadcast
=
chatI
sBroadcast
,
isBroadcast
=
i
sBroadcast
,
// FIXME: Why are we fixing isRoom attribute to true here?
// FIXME: Why are we fixing isRoom attribute to true here?
isRoom
=
true
isRoom
=
true
))
)
)
messagesRepository
.
saveAll
(
messages
.
result
)
messagesRepository
.
saveAll
(
messages
.
result
)
//if success - saving last synced time
//if success - saving last synced time
//assume that BE returns ordered messages, the first message is the latest one
//assume that BE returns ordered messages, the first message is the latest one
messagesRepository
.
saveLastSyncDate
(
chatRoomId
,
messages
.
result
.
first
().
timestamp
)
messagesRepository
.
saveLastSyncDate
(
chatRoomId
,
messages
.
result
.
first
().
timestamp
)
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
showNewMessage
(
models
,
true
)
view
.
showNewMessage
(
models
,
true
)
...
@@ -717,7 +735,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -717,7 +735,7 @@ class ChatRoomPresenter @Inject constructor(
quotedMessage
=
mapper
.
map
(
quotedMessage
=
mapper
.
map
(
message
,
RoomUiModel
(
message
,
RoomUiModel
(
roles
=
chatRoles
,
roles
=
chatRoles
,
isBroadcast
=
chatI
sBroadcast
isBroadcast
=
i
sBroadcast
)
)
).
last
().
preview
?.
message
?:
""
).
last
().
preview
?.
message
?:
""
)
)
...
@@ -844,7 +862,8 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -844,7 +862,8 @@ class ChatRoomPresenter @Inject constructor(
val
sender
=
it
.
sender
val
sender
=
it
.
sender
val
username
=
sender
?.
username
?:
""
val
username
=
sender
?.
username
?:
""
val
name
=
sender
?.
name
?:
""
val
name
=
sender
?.
name
?:
""
val
avatarUrl
=
currentServer
.
avatarUrl
(
username
,
token
?.
userId
,
token
?.
authToken
)
val
avatarUrl
=
currentServer
.
avatarUrl
(
username
,
token
?.
userId
,
token
?.
authToken
)
val
found
=
members
.
firstOrNull
{
member
->
member
.
username
==
username
}
val
found
=
members
.
firstOrNull
{
member
->
member
.
username
==
username
}
val
status
=
if
(
found
!=
null
)
found
.
status
else
UserStatus
.
Offline
()
val
status
=
if
(
found
!=
null
)
found
.
status
else
UserStatus
.
Offline
()
val
searchList
=
mutableListOf
(
username
,
name
)
val
searchList
=
mutableListOf
(
username
,
name
)
...
@@ -865,7 +884,8 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -865,7 +884,8 @@ class ChatRoomPresenter @Inject constructor(
activeUsers
.
addAll
(
others
.
map
{
activeUsers
.
addAll
(
others
.
map
{
val
username
=
it
.
username
?:
""
val
username
=
it
.
username
?:
""
val
name
=
it
.
name
?:
""
val
name
=
it
.
name
?:
""
val
avatarUrl
=
currentServer
.
avatarUrl
(
username
,
token
?.
userId
,
token
?.
authToken
)
val
avatarUrl
=
currentServer
.
avatarUrl
(
username
,
token
?.
userId
,
token
?.
authToken
)
val
searchList
=
mutableListOf
(
username
,
name
)
val
searchList
=
mutableListOf
(
username
,
name
)
PeopleSuggestionUiModel
(
PeopleSuggestionUiModel
(
avatarUrl
,
avatarUrl
,
...
@@ -997,7 +1017,8 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -997,7 +1017,8 @@ class ChatRoomPresenter @Inject constructor(
}
}
// 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
(
Dispatchers
.
IO
)
{
private
suspend
fun
getChatRoomsAsync
(
name
:
String
?
=
null
):
List
<
ChatRoom
>
=
withContext
(
Dispatchers
.
IO
)
{
retryDB
(
"getAllSync()"
)
{
retryDB
(
"getAllSync()"
)
{
dbManager
.
chatRoomDao
().
getAllSync
().
filter
{
dbManager
.
chatRoomDao
().
getAllSync
().
filter
{
if
(
name
==
null
)
{
if
(
name
==
null
)
{
...
@@ -1047,7 +1068,8 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -1047,7 +1068,8 @@ class ChatRoomPresenter @Inject constructor(
val
canPost
=
permissions
.
canPostToReadOnlyChannels
()
val
canPost
=
permissions
.
canPostToReadOnlyChannels
()
dbManager
.
getRoom
(
chatRoomId
)
?.
let
{
dbManager
.
getRoom
(
chatRoomId
)
?.
let
{
val
roomUiModel
=
roomMapper
.
map
(
it
,
true
).
copy
(
val
roomUiModel
=
roomMapper
.
map
(
it
,
true
).
copy
(
writable
=
canPost
)
writable
=
canPost
)
view
.
onJoined
(
roomUiModel
=
roomUiModel
)
view
.
onJoined
(
roomUiModel
=
roomUiModel
)
view
.
onRoomUpdated
(
roomUiModel
=
roomUiModel
)
view
.
onRoomUpdated
(
roomUiModel
=
roomUiModel
)
}
}
...
@@ -1308,7 +1330,7 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -1308,7 +1330,7 @@ class ChatRoomPresenter @Inject constructor(
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
val
viewModelStreamedMessage
=
mapper
.
map
(
val
viewModelStreamedMessage
=
mapper
.
map
(
streamedMessage
,
RoomUiModel
(
streamedMessage
,
RoomUiModel
(
roles
=
chatRoles
,
isBroadcast
=
chatI
sBroadcast
,
isRoom
=
true
roles
=
chatRoles
,
isBroadcast
=
i
sBroadcast
,
isRoom
=
true
)
)
)
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
...
...
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