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
84156a84
Commit
84156a84
authored
Apr 10, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add listen to updates on own profile.
parent
032a72a0
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
46 deletions
+95
-46
MainPresenter.kt
...va/chat/rocket/android/main/presentation/MainPresenter.kt
+50
-28
MainActivity.kt
...src/main/java/chat/rocket/android/main/ui/MainActivity.kt
+17
-10
NavHeaderViewModel.kt
.../chat/rocket/android/main/viewmodel/NavHeaderViewModel.kt
+1
-1
NavHeaderViewModelMapper.kt
...rocket/android/main/viewmodel/NavHeaderViewModelMapper.kt
+2
-2
ProfilePresenter.kt
...t/rocket/android/profile/presentation/ProfilePresenter.kt
+1
-1
ConnectionManager.kt
...ocket/android/server/infraestructure/ConnectionManager.kt
+22
-2
PasswordPresenter.kt
...droid/settings/password/presentation/PasswordPresenter.kt
+1
-1
build.gradle
build.gradle
+1
-1
No files found.
app/src/main/java/chat/rocket/android/main/presentation/MainPresenter.kt
View file @
84156a84
...
...
@@ -22,6 +22,10 @@ import chat.rocket.core.internal.realtime.setDefaultStatus
import
chat.rocket.core.internal.rest.logout
import
chat.rocket.core.internal.rest.me
import
chat.rocket.core.internal.rest.unregisterPushToken
import
chat.rocket.core.model.Myself
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.channels.Channel
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
import
javax.inject.Inject
...
...
@@ -45,6 +49,8 @@ class MainPresenter @Inject constructor(
private
val
client
:
RocketChatClient
=
factory
.
create
(
currentServer
)
private
var
settings
:
PublicSettings
=
getSettingsInteractor
.
get
(
serverInteractor
.
get
()
!!
)
private
val
userDataChannel
=
Channel
<
Myself
>()
fun
toChatList
()
=
navigator
.
toChatList
()
fun
toUserProfile
()
=
navigator
.
toUserProfile
()
...
...
@@ -55,7 +61,9 @@ class MainPresenter @Inject constructor(
checkServerInfo
()
launchUI
(
strategy
)
{
try
{
val
me
=
retryIO
(
"me"
)
{
client
.
me
()
}
val
me
=
retryIO
(
"me"
)
{
client
.
me
()
}
val
model
=
navHeaderMapper
.
mapToViewModel
(
me
)
saveAccount
(
model
)
view
.
setupNavHeader
(
model
,
getAccountsInteractor
.
get
())
...
...
@@ -74,23 +82,10 @@ class MainPresenter @Inject constructor(
}
}
}
subscribeMyselfUpdates
()
}
}
private
suspend
fun
saveAccount
(
viewModel
:
NavHeaderViewModel
)
{
val
icon
=
settings
.
favicon
()
?.
let
{
currentServer
.
serverLogoUrl
(
it
)
}
val
account
=
Account
(
currentServer
,
icon
,
viewModel
.
serverLogo
,
viewModel
.
userDisplayName
,
viewModel
.
userAvatar
)
saveAccountInteractor
.
save
(
account
)
}
/**
* Logout from current server.
*/
...
...
@@ -121,24 +116,12 @@ class MainPresenter @Inject constructor(
}
}
private
suspend
fun
clearTokens
()
{
serverInteractor
.
clear
()
val
pushToken
=
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
if
(
pushToken
!=
null
)
{
try
{
retryIO
(
"unregisterPushToken"
)
{
client
.
unregisterPushToken
(
pushToken
)
}
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error unregistering push token"
)
}
}
localRepository
.
clearAllFromServer
(
currentServer
)
}
fun
connect
()
{
manager
.
connect
()
}
fun
disconnect
()
{
manager
.
removeUserDataChannel
(
userDataChannel
)
manager
.
disconnect
()
}
...
...
@@ -175,4 +158,43 @@ class MainPresenter @Inject constructor(
client
.
registerPushToken
(
token
,
getAccountsInteractor
.
get
(),
factory
)
}
}
private
suspend
fun
saveAccount
(
viewModel
:
NavHeaderViewModel
)
{
val
icon
=
settings
.
favicon
()
?.
let
{
currentServer
.
serverLogoUrl
(
it
)
}
val
account
=
Account
(
currentServer
,
icon
,
viewModel
.
serverLogo
,
viewModel
.
userDisplayName
!!
,
viewModel
.
userAvatar
)
saveAccountInteractor
.
save
(
account
)
}
private
suspend
fun
clearTokens
()
{
serverInteractor
.
clear
()
val
pushToken
=
localRepository
.
get
(
LocalRepository
.
KEY_PUSH_TOKEN
)
if
(
pushToken
!=
null
)
{
try
{
retryIO
(
"unregisterPushToken"
)
{
client
.
unregisterPushToken
(
pushToken
)
}
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error unregistering push token"
)
}
}
localRepository
.
clearAllFromServer
(
currentServer
)
}
private
suspend
fun
subscribeMyselfUpdates
()
{
manager
.
addUserDataChannel
(
userDataChannel
)
for
(
myself
in
userDataChannel
)
{
updateMyself
(
myself
)
}
}
private
suspend
fun
updateMyself
(
myself
:
Myself
)
{
val
model
=
navHeaderMapper
.
mapToViewModel
(
myself
)
view
.
setupNavHeader
(
model
,
getAccountsInteractor
.
get
())
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt
View file @
84156a84
...
...
@@ -95,16 +95,23 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector, HasSupp
override
fun
setupNavHeader
(
viewModel
:
NavHeaderViewModel
,
accounts
:
List
<
Account
>)
{
Timber
.
d
(
"Setting up nav header: $viewModel"
)
with
(
headerLayout
)
{
image_user_status
.
setImageDrawable
(
DrawableHelper
.
getUserStatusDrawable
(
viewModel
.
userStatus
!!
,
this
.
context
)
)
text_user_name
.
text
=
viewModel
.
userDisplayName
text_server_url
.
text
=
viewModel
.
serverUrl
image_avatar
.
setImageURI
(
viewModel
.
userAvatar
)
server_logo
.
setImageURI
(
viewModel
.
serverLogo
)
with
(
viewModel
)
{
if
(
userStatus
!=
null
)
{
image_user_status
.
setImageDrawable
(
DrawableHelper
.
getUserStatusDrawable
(
userStatus
,
context
)
)
}
if
(
userDisplayName
!=
null
)
{
text_user_name
.
text
=
userDisplayName
}
if
(
userAvatar
!=
null
)
{
image_avatar
.
setImageURI
(
userAvatar
)
}
if
(
serverLogo
!=
null
)
{
server_logo
.
setImageURI
(
serverLogo
)
}
text_server_url
.
text
=
viewModel
.
serverUrl
}
setupAccountsList
(
headerLayout
,
accounts
)
}
}
...
...
app/src/main/java/chat/rocket/android/main/viewmodel/NavHeaderViewModel.kt
View file @
84156a84
...
...
@@ -4,7 +4,7 @@ import chat.rocket.common.model.UserStatus
data class
NavHeaderViewModel
(
val
userDisplayName
:
String
,
val
userDisplayName
:
String
?
,
val
userStatus
:
UserStatus
?,
val
userAvatar
:
String
?,
val
serverUrl
:
String
,
...
...
app/src/main/java/chat/rocket/android/main/viewmodel/NavHeaderViewModelMapper.kt
View file @
84156a84
...
...
@@ -23,10 +23,10 @@ class NavHeaderViewModelMapper @Inject constructor(
return
NavHeaderViewModel
(
displayName
,
status
,
avatar
,
currentServer
,
logo
)
}
private
fun
mapDisplayName
(
me
:
Myself
):
String
{
private
fun
mapDisplayName
(
me
:
Myself
):
String
?
{
val
username
=
me
.
username
val
realName
=
me
.
name
val
senderName
=
if
(
settings
.
useRealName
())
realName
else
username
return
senderName
?:
username
.
toString
()
return
senderName
?:
username
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/profile/presentation/ProfilePresenter.kt
View file @
84156a84
...
...
@@ -27,7 +27,7 @@ class ProfilePresenter @Inject constructor(private val view: ProfileView,
view
.
showLoading
()
try
{
val
myself
=
retryIO
(
"me"
)
{
client
.
me
()
}
myselfId
=
myself
.
id
myselfId
=
myself
.
id
!!
val
avatarUrl
=
serverUrl
.
avatarUrl
(
myself
.
username
!!
)
view
.
showProfile
(
avatarUrl
,
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt
View file @
84156a84
...
...
@@ -5,6 +5,7 @@ import chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.realtime.*
import
chat.rocket.core.internal.rest.chatRooms
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Myself
import
kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.channels.Channel
import
kotlinx.coroutines.experimental.launch
...
...
@@ -19,14 +20,15 @@ class ConnectionManager(internal val client: RocketChatClient) {
private
val
roomAndSubscriptionChannels
=
ArrayList
<
Channel
<
StreamMessage
<
BaseRoom
>>>()
private
val
roomMessagesChannels
=
LinkedHashMap
<
String
,
Channel
<
Message
>>()
private
val
userDataChannels
=
ArrayList
<
Channel
<
Myself
>>()
private
val
subscriptionIdMap
=
HashMap
<
String
,
String
>()
private
var
subscriptionId
:
String
?
=
null
private
var
roomsId
:
String
?
=
null
private
var
userId
:
String
?
=
null
fun
connect
()
{
if
(
connectJob
?.
isActive
==
true
&&
(
state
!
is
State
.
Disconnected
))
{
if
(
connectJob
?.
isActive
==
true
&&
(
state
!
is
State
.
Disconnected
))
{
Timber
.
d
(
"Already connected, just returning..."
)
return
}
...
...
@@ -52,6 +54,11 @@ class ConnectionManager(internal val client: RocketChatClient) {
roomsId
=
id
}
client
.
subscribeUserDataChanges
{
_
,
id
->
Timber
.
d
(
"Subscribed to the user: $id"
)
userId
=
id
}
resubscribeRooms
()
}
is
State
.
Waiting
->
{
...
...
@@ -92,6 +99,15 @@ class ConnectionManager(internal val client: RocketChatClient) {
}
}
launch
(
parent
=
connectJob
)
{
for
(
myself
in
client
.
userDataChannel
)
{
Timber
.
d
(
"Got userData"
)
for
(
channel
in
userDataChannels
)
{
channel
.
send
(
myself
)
}
}
}
client
.
connect
()
// Broadcast initial state...
...
...
@@ -125,6 +141,10 @@ class ConnectionManager(internal val client: RocketChatClient) {
fun
removeRoomsAndSubscriptionsChannel
(
channel
:
Channel
<
StreamMessage
<
BaseRoom
>>)
=
roomAndSubscriptionChannels
.
remove
(
channel
)
fun
addUserDataChannel
(
channel
:
Channel
<
Myself
>)
=
userDataChannels
.
add
(
channel
)
fun
removeUserDataChannel
(
channel
:
Channel
<
Myself
>)
=
userDataChannels
.
remove
(
channel
)
fun
subscribeRoomMessages
(
roomId
:
String
,
channel
:
Channel
<
Message
>)
{
val
oldSub
=
roomMessagesChannels
.
put
(
roomId
,
channel
)
if
(
oldSub
!=
null
)
{
...
...
app/src/main/java/chat/rocket/android/settings/password/presentation/PasswordPresenter.kt
View file @
84156a84
...
...
@@ -25,7 +25,7 @@ class PasswordPresenter @Inject constructor (private val view: PasswordView,
val
me
=
retryIO
(
"me"
)
{
client
.
me
()
}
retryIO
(
"updateProfile(${me.id})"
)
{
client
.
updateProfile
(
me
.
id
,
null
,
null
,
password
,
null
)
client
.
updateProfile
(
me
.
id
!!
,
null
,
null
,
password
,
null
)
}
view
.
showPasswordSuccessfullyUpdatedMessage
()
...
...
build.gradle
View file @
84156a84
...
...
@@ -10,7 +10,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.1.
0
'
classpath
'com.android.tools.build:gradle:3.1.
1
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath
"org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}"
classpath
'com.google.gms:google-services:3.2.0'
...
...
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