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
7ec6d60b
Commit
7ec6d60b
authored
May 03, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a UserHelper class to assist on getting relevant and correctly formatted user information
parent
c419e7b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
21 deletions
+76
-21
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+4
-3
UserHelper.kt
app/src/main/java/chat/rocket/android/helper/UserHelper.kt
+63
-0
PermissionsInteractor.kt
...hat/rocket/android/server/domain/PermissionsInteractor.kt
+9
-18
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
7ec6d60b
...
...
@@ -12,8 +12,8 @@ import chat.rocket.android.chatroom.viewmodel.suggestion.CommandSuggestionViewMo
import
chat.rocket.android.chatroom.viewmodel.suggestion.PeopleSuggestionViewModel
import
chat.rocket.android.core.behaviours.showMessage
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.helper.UserHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.username
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import
chat.rocket.android.server.infraestructure.state
...
...
@@ -54,6 +54,7 @@ class ChatRoomPresenter @Inject constructor(
private
val
usersRepository
:
UsersRepository
,
private
val
roomsRepository
:
RoomRepository
,
private
val
localRepository
:
LocalRepository
,
private
val
userHelper
:
UserHelper
,
factory
:
ConnectionManagerFactory
,
private
val
mapper
:
ViewModelMapper
,
private
val
jobSchedulerInteractor
:
JobSchedulerInteractor
...
...
@@ -134,7 +135,7 @@ class ChatRoomPresenter @Inject constructor(
// ignore message for now, will receive it on the stream
val
id
=
UUID
.
randomUUID
().
toString
()
val
message
=
if
(
messageId
==
null
)
{
val
username
=
localRepository
.
username
()
val
username
=
userHelper
.
username
()
val
newMessage
=
Message
(
id
=
id
,
roomId
=
chatRoomId
,
...
...
@@ -553,7 +554,7 @@ class ChatRoomPresenter @Inject constructor(
fun
react
(
messageId
:
String
,
emoji
:
String
)
{
launchUI
(
strategy
)
{
try
{
retryIO
(
"to
o
gleEmoji($messageId, $emoji)"
)
{
retryIO
(
"to
g
gleEmoji($messageId, $emoji)"
)
{
client
.
toggleReaction
(
messageId
,
emoji
.
removeSurrounding
(
":"
))
}
}
catch
(
ex
:
RocketChatException
)
{
...
...
app/src/main/java/chat/rocket/android/helper/UserHelper.kt
0 → 100644
View file @
7ec6d60b
package
chat.rocket.android.helper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.PublicSettings
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.android.server.domain.useRealName
import
chat.rocket.common.model.User
import
javax.inject.Inject
class
UserHelper
@Inject
constructor
(
private
val
localRepository
:
LocalRepository
,
private
val
getCurrentServerInteractor
:
GetCurrentServerInteractor
,
settingsRepository
:
SettingsRepository
)
{
private
val
settings
:
PublicSettings
=
settingsRepository
.
get
(
getCurrentServerInteractor
.
get
()
!!
)
/**
* Return the display name for the given [user].
* If setting 'Use_Real_Name' is true then the real name will be given, or else
* the username without the '@' is yielded. The fallback for any case is the username, which
* could be null.
*/
fun
displayName
(
user
:
User
):
String
?
{
return
if
(
settings
.
useRealName
())
user
.
name
?:
user
.
username
else
user
.
username
}
/**
* Return current logged user's display name.
*
* @see displayName
*/
fun
displayName
():
String
?
{
user
()
?.
let
{
return
displayName
(
it
)
}
return
null
}
/**
* Return current logged [User].
*/
fun
user
():
User
?
{
return
localRepository
.
getCurrentUser
(
serverUrl
())
}
/**
* Return the username for the current logged [User].
*/
fun
username
():
String
?
=
user
()
?.
username
/**
* Whether current [User] is admin on the current server.
*/
fun
isAdmin
():
Boolean
{
return
user
()
?.
roles
?.
find
{
it
.
equals
(
"admin"
,
ignoreCase
=
true
)
}
!=
null
}
private
fun
serverUrl
():
String
{
return
getCurrentServerInteractor
.
get
()
!!
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/PermissionsInteractor.kt
View file @
7ec6d60b
package
chat.rocket.android.server.domain
import
chat.rocket.android.helper.UserHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.common.model.User
import
chat.rocket.core.model.Permission
import
javax.inject.Inject
...
...
@@ -20,14 +20,14 @@ const val POST_READONLY = "post-readonly"
class
PermissionsInteractor
@Inject
constructor
(
private
val
settingsRepository
:
SettingsRepository
,
private
val
permissionsRepository
:
PermissionsRepository
,
private
val
localRepository
:
LocalRepository
,
private
val
getCurrentServerInteractor
:
GetCurrentServerInteracto
r
private
val
getCurrentServerInteractor
:
GetCurrentServerInteractor
,
private
val
userHelper
:
UserHelpe
r
)
{
private
fun
publicSettings
():
PublicSettings
?
=
settingsRepository
.
get
(
getC
urrentServerUrl
()
!!
)
private
fun
publicSettings
():
PublicSettings
?
=
settingsRepository
.
get
(
c
urrentServerUrl
()
!!
)
fun
saveAll
(
permissions
:
List
<
Permission
>)
{
val
url
=
getC
urrentServerUrl
()
!!
val
url
=
c
urrentServerUrl
()
!!
permissions
.
forEach
{
permissionsRepository
.
save
(
url
,
it
)
}
}
...
...
@@ -57,25 +57,16 @@ class PermissionsInteractor @Inject constructor(
fun
showEditedStatus
()
=
publicSettings
()
?.
showEditedStatus
()
?:
false
fun
canPostToReadOnlyChannels
():
Boolean
{
val
url
=
getCurrentServer
Url
()
!!
val
currentUserRoles
=
currentU
ser
()
?.
roles
val
url
=
getCurrentServer
Interactor
.
get
()
!!
val
currentUserRoles
=
userHelper
.
u
ser
()
?.
roles
return
permissionsRepository
.
get
(
url
,
POST_READONLY
)
?.
let
{
permission
->
currentUserRoles
?.
isNotEmpty
()
==
true
&&
permission
.
roles
.
any
{
currentUserRoles
.
contains
(
it
)
}
}
==
true
||
isAdmin
()
}
==
true
||
userHelper
.
isAdmin
()
}
private
fun
currentUser
():
User
?
{
val
url
=
getCurrentServerUrl
()
!!
return
localRepository
.
getCurrentUser
(
url
)
}
private
fun
isAdmin
():
Boolean
{
return
currentUser
()
?.
roles
?.
find
{
it
.
equals
(
"admin"
,
ignoreCase
=
true
)
}
!=
null
}
private
fun
getCurrentServerUrl
():
String
?
{
private
fun
currentServerUrl
():
String
?
{
return
getCurrentServerInteractor
.
get
()
}
}
\ No newline at end of file
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