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
10d6196c
Commit
10d6196c
authored
Jan 03, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assert nulls before setting user's details to local cache
parent
a4fb6a00
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
55 deletions
+66
-55
RocketChatCache.kt
app/src/main/java/chat/rocket/android/RocketChatCache.kt
+10
-2
CurrentUserObserver.java
.../rocket/android/service/observer/CurrentUserObserver.java
+56
-53
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.kt
View file @
10d6196c
...
...
@@ -408,7 +408,11 @@ object RocketChatCache {
},
BackpressureStrategy
.
LATEST
)
}
fun
setUserId
(
userId
:
String
)
=
setString
(
KEY_USER_ID
,
userId
)
fun
setUserId
(
userId
:
String
?)
{
userId
?.
let
{
setString
(
KEY_USER_ID
,
userId
)
}
}
fun
getUserId
():
String
?
=
getString
(
KEY_USER_ID
,
null
)
...
...
@@ -420,7 +424,11 @@ object RocketChatCache {
fun
getUserName
():
String
?
=
getString
(
KEY_USER_NAME
,
null
)
fun
setUserUsername
(
username
:
String
)
=
setString
(
KEY_USER_USERNAME
,
username
)
fun
setUserUsername
(
username
:
String
?)
{
username
?.
let
{
setString
(
KEY_USER_USERNAME
,
username
)
}
}
fun
getUserUsername
():
String
?
=
getString
(
KEY_USER_USERNAME
,
null
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/service/observer/CurrentUserObserver.java
View file @
10d6196c
...
...
@@ -20,68 +20,71 @@ import io.realm.RealmResults;
* observe the user with emails.
*/
public
class
CurrentUserObserver
extends
AbstractModelObserver
<
RealmUser
>
{
private
final
MethodCallHelper
methodCall
;
private
boolean
currentUserExists
;
private
ArrayList
<
Registrable
>
listeners
;
private
final
MethodCallHelper
methodCall
;
private
boolean
currentUserExists
;
private
ArrayList
<
Registrable
>
listeners
;
public
CurrentUserObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
)
{
super
(
context
,
hostname
,
realmHelper
);
methodCall
=
new
MethodCallHelper
(
realmHelper
);
currentUserExists
=
false
;
}
public
CurrentUserObserver
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
)
{
super
(
context
,
hostname
,
realmHelper
);
methodCall
=
new
MethodCallHelper
(
realmHelper
);
currentUserExists
=
false
;
}
@Override
public
RealmResults
<
RealmUser
>
queryItems
(
Realm
realm
)
{
return
RealmUser
.
queryCurrentUser
(
realm
).
findAll
();
}
@Override
public
RealmResults
<
RealmUser
>
queryItems
(
Realm
realm
)
{
return
RealmUser
.
queryCurrentUser
(
realm
).
findAll
();
}
@Override
public
void
onUpdateResults
(
List
<
RealmUser
>
results
)
{
boolean
exists
=
!
results
.
isEmpty
();
@Override
public
void
onUpdateResults
(
List
<
RealmUser
>
results
)
{
boolean
exists
=
!
results
.
isEmpty
();
if
(
currentUserExists
!=
exists
)
{
if
(
exists
)
{
onLogin
(
results
.
get
(
0
));
}
else
{
onLogout
();
}
currentUserExists
=
exists
;
if
(
currentUserExists
!=
exists
)
{
if
(
exists
)
{
onLogin
(
results
.
get
(
0
));
}
else
{
onLogout
();
}
currentUserExists
=
exists
;
}
}
}
@DebugLog
private
void
onLogin
(
RealmUser
user
)
{
if
(
listeners
!=
null
)
{
onLogout
();
}
listeners
=
new
ArrayList
<>();
@DebugLog
private
void
onLogin
(
RealmUser
user
)
{
if
(
listeners
!=
null
)
{
onLogout
();
}
listeners
=
new
ArrayList
<>();
RocketChatCache
.
INSTANCE
.
setUserId
(
user
.
getId
()
);
RocketChatCache
.
INSTANCE
.
setUserUsername
(
user
.
getUsername
()
);
RocketChatCache
.
INSTANCE
.
setUserName
(
user
.
getName
()
);
String
userId
=
user
.
getId
(
);
String
username
=
user
.
getUsername
(
);
String
name
=
user
.
getName
(
);
final
String
userId
=
user
.
getId
();
// get and observe Room subscriptions.
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
if
(
listeners
!=
null
)
{
Registrable
listener
=
new
StreamNotifyUserSubscriptionsChanged
(
context
,
hostname
,
realmHelper
,
userId
);
listener
.
register
();
listeners
.
add
(
listener
);
}
return
null
;
}).
continueWith
(
new
LogIfError
());
}
RocketChatCache
.
INSTANCE
.
setUserId
(
userId
);
RocketChatCache
.
INSTANCE
.
setUserUsername
(
username
);
RocketChatCache
.
INSTANCE
.
setUserName
(
name
);
// get and observe Room subscriptions.
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
if
(
listeners
!=
null
)
{
Registrable
listener
=
new
StreamNotifyUserSubscriptionsChanged
(
context
,
hostname
,
realmHelper
,
userId
);
listener
.
register
();
listeners
.
add
(
listener
);
}
return
null
;
}).
continueWith
(
new
LogIfError
());
}
@DebugLog
private
void
onLogout
()
{
if
(
listeners
!=
null
)
{
for
(
Registrable
listener
:
listeners
)
{
listener
.
unregister
();
}
@DebugLog
private
void
onLogout
()
{
if
(
listeners
!=
null
)
{
for
(
Registrable
listener
:
listeners
)
{
listener
.
unregister
();
}
}
listeners
=
null
;
}
listeners
=
null
;
}
}
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