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 {
...
@@ -93,8 +93,7 @@ public class MainActivity extends AbstractAuthedActivity {
sessionObserver
=
realmHelper
sessionObserver
=
realmHelper
.
createObjectObserver
(
realm
->
.
createObjectObserver
(
realm
->
realm
.
where
(
Session
.
class
)
Session
.
queryDefaultSession
(
realm
)
.
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
)
.
isNotNull
(
"token"
)
.
isNotNull
(
"token"
)
.
equalTo
(
"tokenVerified"
,
true
)
.
equalTo
(
"tokenVerified"
,
true
)
.
isNull
(
"error"
))
.
isNull
(
"error"
))
...
...
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
7c464ecc
...
@@ -42,8 +42,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
...
@@ -42,8 +42,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
}
}
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
.
createObjectObserver
(
realm
->
.
createObjectObserver
(
Session:
:
queryDefaultSession
)
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
))
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
setContentView
(
R
.
layout
.
simple_screen
);
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
...
@@ -86,7 +86,7 @@ public class RoomFragment extends AbstractChatRoomFragment
userId
=
realmHelper
.
executeTransactionForRead
(
realm
->
userId
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
()).
get_id
();
User
.
queryCurrentUser
(
realm
).
findFirst
()).
get_id
();
token
=
realmHelper
.
executeTransactionForRead
(
realm
->
token
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
).
findFirst
()).
getToken
();
Session
.
queryDefaultSession
(
realm
).
findFirst
()).
getToken
();
roomObserver
=
realmHelper
roomObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
))
.
createObjectObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
))
.
setOnUpdateListener
(
this
::
onRenderRoom
);
.
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 {
...
@@ -24,8 +24,7 @@ public class RetryLoginFragment extends AbstractServerConfigFragment {
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
.
createObjectObserver
(
realm
->
.
createObjectObserver
(
Session:
:
queryDefaultSession
)
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
))
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
.
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;
...
@@ -4,7 +4,9 @@ import chat.rocket.android.helper.LogcatIfError;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
hugo.weaving.DebugLog
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.RealmObject
;
import
io.realm.RealmObject
;
import
io.realm.RealmQuery
;
import
io.realm.annotations.PrimaryKey
;
import
io.realm.annotations.PrimaryKey
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -50,6 +52,10 @@ public class Session extends RealmObject {
...
@@ -50,6 +52,10 @@ public class Session extends RealmObject {
this
.
error
=
error
;
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.
* 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 {
...
@@ -91,8 +91,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
void
forceInvalidateTokens
()
{
private
void
forceInvalidateTokens
()
{
serverConfigRealm
.
executeTransaction
(
realm
->
{
serverConfigRealm
.
executeTransaction
(
realm
->
{
Session
session
=
realm
.
where
(
Session
.
class
)
Session
session
=
Session
.
queryDefaultSession
(
realm
).
findFirst
();
.
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
).
findFirst
();
if
(
session
!=
null
if
(
session
!=
null
&&
!
TextUtils
.
isEmpty
(
session
.
getToken
())
&&
!
TextUtils
.
isEmpty
(
session
.
getToken
())
&&
(
session
.
isTokenVerified
()
||
!
TextUtils
.
isEmpty
(
session
.
getError
())))
{
&&
(
session
.
isTokenVerified
()
||
!
TextUtils
.
isEmpty
(
session
.
getError
())))
{
...
@@ -159,9 +158,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -159,9 +158,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
.
put
(
"serverConfigId"
,
serverConfigId
)
.
put
(
"serverConfigId"
,
serverConfigId
)
.
put
(
"session"
,
session
))
.
put
(
"session"
,
session
))
).
onSuccess
(
_task
->
serverConfigRealm
.
executeTransaction
(
realm
->
{
).
onSuccess
(
_task
->
serverConfigRealm
.
executeTransaction
(
realm
->
{
Session
sessionObj
=
realm
.
where
(
Session
.
class
)
Session
sessionObj
=
Session
.
queryDefaultSession
(
realm
).
findFirst
();
.
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
)
.
findFirst
();
if
(
sessionObj
==
null
)
{
if
(
sessionObj
==
null
)
{
realm
.
createOrUpdateObjectFromJson
(
Session
.
class
,
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