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
7c464ecc
Commit
7c464ecc
authored
Dec 11, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor querying default session.
parent
1a19e91d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
12 additions
and
12 deletions
+12
-12
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+1
-2
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+1
-2
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+1
-1
RetryLoginFragment.java
...et/android/fragment/server_config/RetryLoginFragment.java
+1
-2
Session.java
...main/java/chat/rocket/android/model/internal/Session.java
+6
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+2
-5
No files found.
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
7c464ecc
...
...
@@ -93,8 +93,7 @@ public class MainActivity extends AbstractAuthedActivity {
sessionObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
Session
.
class
)
.
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
)
Session
.
queryDefaultSession
(
realm
)
.
isNotNull
(
"token"
)
.
equalTo
(
"tokenVerified"
,
true
)
.
isNull
(
"error"
))
...
...
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
7c464ecc
...
...
@@ -42,8 +42,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
}
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
.
createObjectObserver
(
realm
->
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
))
.
createObjectObserver
(
Session:
:
queryDefaultSession
)
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
setContentView
(
R
.
layout
.
simple_screen
);
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
7c464ecc
...
...
@@ -86,7 +86,7 @@ public class RoomFragment extends AbstractChatRoomFragment
userId
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
()).
get_id
();
token
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
).
findFirst
()).
getToken
();
Session
.
queryDefaultSession
(
realm
).
findFirst
()).
getToken
();
roomObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
))
.
setOnUpdateListener
(
this
::
onRenderRoom
);
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/RetryLoginFragment.java
View file @
7c464ecc
...
...
@@ -24,8 +24,7 @@ public class RetryLoginFragment extends AbstractServerConfigFragment {
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
.
createObjectObserver
(
realm
->
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
))
.
createObjectObserver
(
Session:
:
queryDefaultSession
)
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
}
...
...
app/src/main/java/chat/rocket/android/model/internal/Session.java
View file @
7c464ecc
...
...
@@ -4,7 +4,9 @@ import chat.rocket.android.helper.LogcatIfError;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.RealmObject
;
import
io.realm.RealmQuery
;
import
io.realm.annotations.PrimaryKey
;
import
org.json.JSONObject
;
...
...
@@ -50,6 +52,10 @@ public class Session extends RealmObject {
this
.
error
=
error
;
}
public
static
RealmQuery
<
Session
>
queryDefaultSession
(
Realm
realm
)
{
return
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
);
}
/**
* Log the server connection is lost due to soem exception.
*/
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
7c464ecc
...
...
@@ -91,8 +91,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
void
forceInvalidateTokens
()
{
serverConfigRealm
.
executeTransaction
(
realm
->
{
Session
session
=
realm
.
where
(
Session
.
class
)
.
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
).
findFirst
();
Session
session
=
Session
.
queryDefaultSession
(
realm
).
findFirst
();
if
(
session
!=
null
&&
!
TextUtils
.
isEmpty
(
session
.
getToken
())
&&
(
session
.
isTokenVerified
()
||
!
TextUtils
.
isEmpty
(
session
.
getError
())))
{
...
...
@@ -159,9 +158,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
.
put
(
"serverConfigId"
,
serverConfigId
)
.
put
(
"session"
,
session
))
).
onSuccess
(
_task
->
serverConfigRealm
.
executeTransaction
(
realm
->
{
Session
sessionObj
=
realm
.
where
(
Session
.
class
)
.
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
)
.
findFirst
();
Session
sessionObj
=
Session
.
queryDefaultSession
(
realm
).
findFirst
();
if
(
sessionObj
==
null
)
{
realm
.
createOrUpdateObjectFromJson
(
Session
.
class
,
...
...
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