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
d0e879cd
Commit
d0e879cd
authored
Jul 18, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide hidden (open = false) rooms and clear status on new connection
parent
b49598d9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
32 deletions
+77
-32
RoomUiModelMapper.kt
...hat/rocket/android/chatrooms/adapter/RoomUiModelMapper.kt
+2
-1
RoomUiModel.kt
...hat/rocket/android/chatrooms/adapter/model/RoomUiModel.kt
+1
-0
ChatRoomsFragmentModule.kt
...at/rocket/android/chatrooms/di/ChatRoomsFragmentModule.kt
+1
-3
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+46
-25
ChatRoomDao.kt
app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt
+14
-3
DatabaseManager.kt
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
+6
-0
UserDao.kt
app/src/main/java/chat/rocket/android/db/UserDao.kt
+6
-0
ConnectionManager.kt
...ocket/android/server/infraestructure/ConnectionManager.kt
+1
-0
No files found.
app/src/main/java/chat/rocket/android/chatrooms/adapter/RoomUiModelMapper.kt
View file @
d0e879cd
...
...
@@ -28,7 +28,6 @@ import chat.rocket.core.model.SpotlightResult
class
RoomUiModelMapper
(
private
val
context
:
Application
,
private
val
settings
:
PublicSettings
,
private
val
localRepository
:
LocalRepository
,
private
val
userInteractor
:
GetCurrentUserInteractor
,
private
val
serverUrl
:
String
)
{
...
...
@@ -117,12 +116,14 @@ class RoomUiModelMapper(
val
lastMessage
=
mapLastMessage
(
lastMessageUserId
,
chatRoom
.
lastMessageUserName
,
chatRoom
.
lastMessageUserFullName
,
lastMessageText
,
isUnread
,
type
is
RoomType
.
DirectMessage
)
val
open
=
open
RoomUiModel
(
id
=
id
,
name
=
roomName
,
type
=
type
,
avatar
=
avatar
,
open
=
open
,
date
=
timestamp
,
unread
=
unread
,
alert
=
isUnread
,
...
...
app/src/main/java/chat/rocket/android/chatrooms/adapter/model/RoomUiModel.kt
View file @
d0e879cd
...
...
@@ -8,6 +8,7 @@ data class RoomUiModel(
val
type
:
RoomType
,
val
name
:
CharSequence
,
val
avatar
:
String
,
val
open
:
Boolean
=
false
,
val
date
:
CharSequence
?
=
null
,
val
unread
:
String
?
=
null
,
val
alert
:
Boolean
=
false
,
...
...
app/src/main/java/chat/rocket/android/chatrooms/di/ChatRoomsFragmentModule.kt
View file @
d0e879cd
...
...
@@ -87,12 +87,10 @@ class ChatRoomsFragmentModule {
fun
provideRoomMapper
(
context
:
Application
,
repository
:
SettingsRepository
,
localRepository
:
LocalRepository
,
userInteractor
:
GetCurrentUserInteractor
,
@Named
(
"currentServer"
)
serverUrl
:
String
):
RoomUiModelMapper
{
return
RoomUiModelMapper
(
context
,
repository
.
get
(
serverUrl
),
localRepository
,
userInteractor
,
serverUrl
)
return
RoomUiModelMapper
(
context
,
repository
.
get
(
serverUrl
),
userInteractor
,
serverUrl
)
}
@Provides
...
...
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
d0e879cd
...
...
@@ -9,8 +9,8 @@ import chat.rocket.android.helper.UserHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.main.presentation.MainNavigator
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.android.server.domain.useSpecialCharsOnRoom
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.retryIO
...
...
@@ -20,9 +20,12 @@ import chat.rocket.common.model.User
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.core.internal.realtime.createDirectMessage
import
chat.rocket.core.internal.rest.me
import
chat.rocket.core.internal.rest.show
import
kotlinx.coroutines.experimental.withTimeout
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Named
import
kotlin.coroutines.experimental.suspendCoroutine
class
ChatRoomsPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomsView
,
...
...
@@ -44,7 +47,7 @@ class ChatRoomsPresenter @Inject constructor(
try
{
val
room
=
dbManager
.
getRoom
(
chatRoom
.
id
)
if
(
room
!=
null
)
{
loadChatRoom
(
room
.
chatRoom
)
loadChatRoom
(
room
.
chatRoom
,
true
)
}
else
{
with
(
chatRoom
)
{
val
entity
=
ChatRoomEntity
(
...
...
@@ -53,44 +56,57 @@ class ChatRoomsPresenter @Inject constructor(
type
=
type
.
toString
(),
name
=
username
?:
name
.
toString
(),
fullname
=
name
.
toString
(),
open
=
false
open
=
open
)
loadChatRoom
(
entity
)
loadChatRoom
(
entity
,
false
)
}
}
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error loading channel"
)
view
.
showGenericErrorMessage
()
}
finally
{
view
.
hideLoadingRoom
()
}
}
}
fun
loadChatRoom
(
chatRoom
:
ChatRoomEntity
)
{
suspend
fun
loadChatRoom
(
chatRoom
:
ChatRoomEntity
,
local
:
Boolean
=
false
)
{
with
(
chatRoom
)
{
val
isDirectMessage
=
roomTypeOf
(
type
)
is
RoomType
.
DirectMessage
val
roomName
=
if
(
settings
.
useSpecialCharsOnRoom
()
||
(
isDirectMessage
&&
settings
.
useRealName
()))
{
fullname
?:
name
}
else
{
name
}
fullname
?:
name
}
else
{
name
}
launchUI
(
strategy
)
{
val
myself
=
getCurrentUser
()
if
(
myself
?.
username
==
null
)
{
view
.
showMessage
(
R
.
string
.
msg_generic_error
)
}
else
{
val
id
=
if
(
isDirectMessage
&&
!
open
)
{
retryIO
(
"createDirectMessage($name)"
)
{
client
.
createDirectMessage
(
name
)
}
val
fromTo
=
mutableListOf
(
myself
.
id
,
id
).
apply
{
sort
()
val
myself
=
getCurrentUser
()
if
(
myself
?.
username
==
null
)
{
view
.
showMessage
(
R
.
string
.
msg_generic_error
)
}
else
{
val
id
=
if
(
isDirectMessage
&&
!
open
)
{
val
fromTo
=
mutableListOf
(
myself
.
id
,
id
).
apply
{
sort
()
}
val
roomId
=
fromTo
.
joinToString
(
""
)
if
(
local
)
{
retryIO
{
client
.
show
(
id
,
roomTypeOf
(
RoomType
.
DIRECT_MESSAGE
))
}
fromTo
.
joinToString
(
""
)
}
else
{
id
}
else
{
retryIO
(
"createDirectMessage($name)"
)
{
withTimeout
(
10000
)
{
createDirectMessage
(
name
)
}
}
roomId
}
}
else
{
id
}
navigator
.
toChatRoom
(
navigator
.
toChatRoom
(
chatRoomId
=
id
,
chatRoomName
=
roomName
,
chatRoomType
=
type
,
...
...
@@ -99,8 +115,7 @@ class ChatRoomsPresenter @Inject constructor(
isSubscribed
=
open
,
isCreator
=
ownerId
==
myself
.
id
||
isDirectMessage
,
isFavorite
=
favorite
?:
false
)
}
)
}
}
}
...
...
@@ -126,4 +141,10 @@ class ChatRoomsPresenter @Inject constructor(
}
return
null
}
private
suspend
fun
createDirectMessage
(
name
:
String
):
Boolean
=
suspendCoroutine
{
cont
->
client
.
createDirectMessage
(
name
)
{
success
,
_
->
cont
.
resume
(
success
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt
View file @
d0e879cd
...
...
@@ -21,19 +21,23 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
abstract
fun
get
(
id
:
String
):
ChatRoom
?
@Transaction
@Query
(
"$BASE_QUERY"
)
@Query
(
"$BASE_QUERY
$FILTER_NOT_OPENED
"
)
abstract
fun
getAllSync
():
List
<
ChatRoom
>
@Transaction
@Query
(
"""$BASE_QUERY WHERE chatrooms.name LIKE '%' || :query || '%' OR users.name LIKE '%' || :query || '%'"""
)
@Query
(
"""$BASE_QUERY
WHERE chatrooms.name LIKE '%' || :query || '%'
OR users.name LIKE '%' || :query || '%'
"""
)
abstract
fun
searchSync
(
query
:
String
):
List
<
ChatRoom
>
@Query
(
"SELECT COUNT(id) FROM chatrooms"
)
@Query
(
"SELECT COUNT(id) FROM chatrooms
WHERE open = 1
"
)
abstract
fun
count
():
Long
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
CASE
WHEN lastMessageTimeStamp IS NOT NULL THEN lastMessageTimeStamp
...
...
@@ -45,6 +49,7 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
$TYPE_ORDER,
CASE
...
...
@@ -57,6 +62,7 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY name
"""
)
abstract
fun
getAllAlphabetically
():
LiveData
<
List
<
ChatRoom
>>
...
...
@@ -64,6 +70,7 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
$TYPE_ORDER,
name
...
...
@@ -113,6 +120,10 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
LEFT JOIN users AS lmUsers ON chatrooms.lastMessageUserId = lmUsers.id
"""
const
val
FILTER_NOT_OPENED
=
"""
WHERE chatrooms.open = 1
"""
const
val
TYPE_ORDER
=
"""
CASE
WHEN type = 'c' THEN 1
...
...
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
View file @
d0e879cd
...
...
@@ -45,6 +45,12 @@ class DatabaseManager(val context: Application,
fun
chatRoomDao
():
ChatRoomDao
=
database
.
chatRoomDao
()
fun
userDao
():
UserDao
=
database
.
userDao
()
fun
clearUsersStatus
()
{
launch
(
dbContext
)
{
userDao
().
clearStatus
()
}
}
fun
logout
()
{
database
.
clearAllTables
()
}
...
...
app/src/main/java/chat/rocket/android/db/UserDao.kt
View file @
d0e879cd
...
...
@@ -13,6 +13,12 @@ import timber.log.Timber
@Dao
abstract
class
UserDao
:
BaseDao
<
UserEntity
>
{
@Query
(
"""
UPDATE users set STATUS = "offline"
"""
)
abstract
fun
clearStatus
()
@Update
(
onConflict
=
OnConflictStrategy
.
IGNORE
)
abstract
fun
update
(
user
:
UserEntity
):
Int
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt
View file @
d0e879cd
...
...
@@ -71,6 +71,7 @@ class ConnectionManager(
Timber
.
d
(
"Changing status to: $status"
)
when
(
status
)
{
is
State
.
Connected
->
{
dbManager
.
clearUsersStatus
()
client
.
subscribeSubscriptions
{
_
,
id
->
Timber
.
d
(
"Subscribed to subscriptions: $id"
)
subscriptionId
=
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