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
8e9506c0
Commit
8e9506c0
authored
Oct 19, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache the Site_Url public setting value for each hostname
parent
5b476274
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
3 deletions
+55
-3
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+33
-0
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+3
-1
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+18
-1
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+1
-1
No files found.
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
8e9506c0
...
@@ -28,6 +28,7 @@ import io.reactivex.annotations.Nullable;
...
@@ -28,6 +28,7 @@ import io.reactivex.annotations.Nullable;
*/
*/
public
class
RocketChatCache
{
public
class
RocketChatCache
{
private
static
final
String
KEY_SELECTED_SERVER_HOSTNAME
=
"KEY_SELECTED_SERVER_HOSTNAME"
;
private
static
final
String
KEY_SELECTED_SERVER_HOSTNAME
=
"KEY_SELECTED_SERVER_HOSTNAME"
;
private
static
final
String
KEY_SELECTED_SITE_URL
=
"KEY_SELECTED_SITE_URL"
;
private
static
final
String
KEY_SELECTED_ROOM_ID
=
"KEY_SELECTED_ROOM_ID"
;
private
static
final
String
KEY_SELECTED_ROOM_ID
=
"KEY_SELECTED_ROOM_ID"
;
private
static
final
String
KEY_PUSH_ID
=
"KEY_PUSH_ID"
;
private
static
final
String
KEY_PUSH_ID
=
"KEY_PUSH_ID"
;
private
static
final
String
KEY_HOSTNAME_LIST
=
"KEY_HOSTNAME_LIST"
;
private
static
final
String
KEY_HOSTNAME_LIST
=
"KEY_HOSTNAME_LIST"
;
...
@@ -50,6 +51,38 @@ public class RocketChatCache {
...
@@ -50,6 +51,38 @@ public class RocketChatCache {
setString
(
KEY_SELECTED_SERVER_HOSTNAME
,
newHostname
);
setString
(
KEY_SELECTED_SERVER_HOSTNAME
,
newHostname
);
}
}
public
void
setSelectedServerHostnameAlias
(
@Nullable
String
hostnameAlias
)
{
String
alias
=
null
;
if
(
hostnameAlias
!=
null
)
{
alias
=
hostnameAlias
.
toLowerCase
();
}
try
{
String
selectedHostnameAliasJson
=
getLoginHostnamesJson
();
JSONObject
jsonObject
=
selectedHostnameAliasJson
==
null
?
new
JSONObject
()
:
new
JSONObject
(
selectedHostnameAliasJson
);
String
selectedServerHostname
=
getSelectedServerHostname
();
jsonObject
.
put
(
alias
,
selectedServerHostname
);
setString
(
KEY_SELECTED_SITE_URL
,
jsonObject
.
toString
());
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
}
}
public
@NonNull
String
getLoginHostnameFrom
(
String
hostname
)
{
try
{
String
selectedServerHostname
=
getSelectedServerHostname
();
return
new
JSONObject
(
getLoginHostnamesJson
())
.
optString
(
hostname
,
selectedServerHostname
);
}
catch
(
JSONException
e
)
{
RCLog
.
e
(
e
);
}
return
null
;
}
private
@Nullable
String
getLoginHostnamesJson
()
{
return
getString
(
KEY_SELECTED_SITE_URL
,
null
);
}
public
void
addHostname
(
@NonNull
String
hostname
,
@Nullable
String
hostnameAvatarUri
,
String
siteName
)
{
public
void
addHostname
(
@NonNull
String
hostname
,
@Nullable
String
hostnameAvatarUri
,
String
siteName
)
{
String
hostnameList
=
getString
(
KEY_HOSTNAME_LIST
,
null
);
String
hostnameList
=
getString
(
KEY_HOSTNAME_LIST
,
null
);
try
{
try
{
...
...
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
8e9506c0
...
@@ -61,7 +61,9 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
...
@@ -61,7 +61,9 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
String
hostname
=
intent
.
getStringExtra
(
PushConstants
.
HOSTNAME
);
String
hostname
=
intent
.
getStringExtra
(
PushConstants
.
HOSTNAME
);
HttpUrl
url
=
HttpUrl
.
parse
(
hostname
);
HttpUrl
url
=
HttpUrl
.
parse
(
hostname
);
if
(
url
!=
null
)
{
if
(
url
!=
null
)
{
rocketChatCache
.
setSelectedServerHostname
(
url
.
host
());
String
hostnameFromPush
=
url
.
host
();
String
loginHostname
=
rocketChatCache
.
getLoginHostnameFrom
(
hostnameFromPush
);
rocketChatCache
.
setSelectedServerHostname
(
loginHostname
);
if
(
intent
.
hasExtra
(
PushConstants
.
ROOM_ID
))
{
if
(
intent
.
hasExtra
(
PushConstants
.
ROOM_ID
))
{
rocketChatCache
.
setSelectedRoomId
(
intent
.
getStringExtra
(
PushConstants
.
ROOM_ID
));
rocketChatCache
.
setSelectedRoomId
(
intent
.
getStringExtra
(
PushConstants
.
ROOM_ID
));
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
8e9506c0
...
@@ -11,11 +11,13 @@ import java.util.UUID;
...
@@ -11,11 +11,13 @@ import java.util.UUID;
import
bolts.Continuation
;
import
bolts.Continuation
;
import
bolts.Task
;
import
bolts.Task
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.helper.CheckSum
;
import
chat.rocket.android.helper.CheckSum
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.DDPClientRef
;
import
chat.rocket.android.service.DDPClientRef
;
import
chat.rocket.android_ddp.DDPClientCallback
;
import
chat.rocket.android_ddp.DDPClientCallback
;
import
chat.rocket.core.PublicSettingsConstants
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.core.SyncState
;
import
chat.rocket.persistence.realm.RealmHelper
;
import
chat.rocket.persistence.realm.RealmHelper
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.persistence.realm.RealmStore
;
...
@@ -30,6 +32,7 @@ import chat.rocket.persistence.realm.models.ddp.RealmSpotlightUser;
...
@@ -30,6 +32,7 @@ import chat.rocket.persistence.realm.models.ddp.RealmSpotlightUser;
import
chat.rocket.persistence.realm.models.internal.MethodCall
;
import
chat.rocket.persistence.realm.models.internal.MethodCall
;
import
chat.rocket.persistence.realm.models.internal.RealmSession
;
import
chat.rocket.persistence.realm.models.internal.RealmSession
;
import
hugo.weaving.DebugLog
;
import
hugo.weaving.DebugLog
;
import
okhttp3.HttpUrl
;
/**
/**
* Utility class for creating/handling MethodCall or RPC.
* Utility class for creating/handling MethodCall or RPC.
...
@@ -65,6 +68,12 @@ public class MethodCallHelper {
...
@@ -65,6 +68,12 @@ public class MethodCallHelper {
this
.
ddpClientRef
=
ddpClientRef
;
this
.
ddpClientRef
=
ddpClientRef
;
}
}
public
MethodCallHelper
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientRef
ddpClientRef
)
{
this
.
context
=
context
.
getApplicationContext
();
this
.
realmHelper
=
realmHelper
;
this
.
ddpClientRef
=
ddpClientRef
;
}
@DebugLog
@DebugLog
private
Task
<
String
>
executeMethodCall
(
String
methodName
,
String
param
,
long
timeout
)
{
private
Task
<
String
>
executeMethodCall
(
String
methodName
,
String
param
,
long
timeout
)
{
if
(
ddpClientRef
!=
null
)
{
if
(
ddpClientRef
!=
null
)
{
...
@@ -412,7 +421,15 @@ public class MethodCallHelper {
...
@@ -412,7 +421,15 @@ public class MethodCallHelper {
.
onSuccessTask
(
task
->
{
.
onSuccessTask
(
task
->
{
final
JSONArray
settings
=
task
.
getResult
();
final
JSONArray
settings
=
task
.
getResult
();
for
(
int
i
=
0
;
i
<
settings
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
settings
.
length
();
i
++)
{
RealmPublicSetting
.
customizeJson
(
settings
.
getJSONObject
(
i
));
JSONObject
jsonObject
=
settings
.
getJSONObject
(
i
);
RealmPublicSetting
.
customizeJson
(
jsonObject
);
if
(
jsonObject
.
getString
(
RealmPublicSetting
.
ID
).
equalsIgnoreCase
(
PublicSettingsConstants
.
General
.
SITE_URL
))
{
String
siteUrl
=
jsonObject
.
getString
(
RealmPublicSetting
.
VALUE
);
HttpUrl
httpUrl
=
HttpUrl
.
parse
(
siteUrl
);
if
(
httpUrl
!=
null
)
{
new
RocketChatCache
(
context
).
setSelectedServerHostnameAlias
(
httpUrl
.
host
());
}
}
}
}
return
realmHelper
.
executeTransaction
(
realm
->
{
return
realmHelper
.
executeTransaction
(
realm
->
{
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
8e9506c0
...
@@ -343,7 +343,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -343,7 +343,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
}
private
Task
<
Void
>
fetchPublicSettings
()
{
private
Task
<
Void
>
fetchPublicSettings
()
{
return
new
MethodCallHelper
(
realmHelper
,
ddpClientRef
).
getPublicSettings
();
return
new
MethodCallHelper
(
appContext
,
realmHelper
,
ddpClientRef
).
getPublicSettings
();
}
}
private
Task
<
Void
>
fetchPermissions
()
{
private
Task
<
Void
>
fetchPermissions
()
{
...
...
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