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
857c8cf2
Commit
857c8cf2
authored
Jan 31, 2017
by
Tiago Cunha
Committed by
GitHub
Jan 31, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into fix/sync-failure-error
parents
da5320f3
d6380c71
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
15 deletions
+47
-15
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+28
-13
PushNotificationHandler.java
...ava/chat/rocket/android/push/PushNotificationHandler.java
+19
-2
No files found.
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
857c8cf2
...
...
@@ -5,13 +5,15 @@ import android.content.SharedPreferences;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.push.PushConstants
;
import
chat.rocket.android.push.PushNotificationHandler
;
import
chat.rocket.android.realm_helper.RealmListObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ServerInfo
;
import
icepick.State
;
abstract
class
AbstractAuthedActivity
extends
AbstractFragmentActivity
{
...
...
@@ -66,25 +68,22 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
private
void
updateHostnameIfNeeded
(
SharedPreferences
prefs
)
{
String
newHostname
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
,
null
);
if
(
hostname
==
null
)
{
if
(
newHostname
!=
null
&&
assertServerRealmStoreExists
(
newHostname
,
prefs
))
{
if
(
newHostname
!=
null
&&
assertServerRealmStoreExists
(
newHostname
))
{
updateHostname
(
newHostname
);
}
else
{
recoverFromHostnameError
(
prefs
);
}
}
else
{
if
(!
hostname
.
equals
(
newHostname
)
&&
assertServerRealmStoreExists
(
newHostname
,
prefs
))
{
if
(!
hostname
.
equals
(
newHostname
)
&&
assertServerRealmStoreExists
(
newHostname
))
{
updateHostname
(
newHostname
);
}
else
{
recoverFromHostnameError
(
prefs
);
}
}
}
private
boolean
assertServerRealmStoreExists
(
String
hostname
,
SharedPreferences
prefs
)
{
if
(
RealmStore
.
get
(
hostname
)
==
null
)
{
prefs
.
edit
()
.
remove
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
)
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
.
apply
();
return
false
;
}
return
true
;
private
boolean
assertServerRealmStoreExists
(
String
hostname
)
{
return
RealmStore
.
get
(
hostname
)
!=
null
;
}
private
void
updateHostname
(
String
hostname
)
{
...
...
@@ -92,6 +91,22 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
onHostnameUpdated
();
}
private
void
recoverFromHostnameError
(
SharedPreferences
prefs
)
{
final
List
<
ServerInfo
>
serverInfoList
=
ConnectivityManager
.
getInstance
(
getApplicationContext
()).
getServerList
();
if
(
serverInfoList
==
null
||
serverInfoList
.
size
()
==
0
)
{
LaunchUtil
.
showAddServerActivity
(
this
);
return
;
}
// just connect to the first available
final
ServerInfo
serverInfo
=
serverInfoList
.
get
(
0
);
prefs
.
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_HOSTNAME
,
serverInfo
.
hostname
)
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
.
apply
();
}
private
void
updateRoomIdIfNeeded
(
SharedPreferences
prefs
)
{
String
newRoomId
=
prefs
.
getString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
null
);
if
(
roomId
==
null
)
{
...
...
@@ -106,7 +121,7 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
}
private
boolean
assertRoomSubscriptionExists
(
String
roomId
,
SharedPreferences
prefs
)
{
if
(!
assertServerRealmStoreExists
(
hostname
,
prefs
))
{
if
(!
assertServerRealmStoreExists
(
hostname
))
{
return
false
;
}
...
...
app/src/main/java/chat/rocket/android/push/PushNotificationHandler.java
View file @
857c8cf2
...
...
@@ -29,8 +29,12 @@ import java.io.InputStream;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Random
;
import
chat.rocket.android.activity.MainActivity
;
import
chat.rocket.android.helper.ServerPolicyHelper
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.service.ServerInfo
;
public
class
PushNotificationHandler
implements
PushConstants
{
...
...
@@ -98,7 +102,7 @@ public class PushNotificationHandler implements PushConstants {
String
hostname
=
getHostname
(
extras
);
String
roomId
=
getRoomId
(
extras
);
if
(
hostname
==
null
||
roomId
==
null
)
{
if
(
hostname
==
null
||
roomId
==
null
||
!
isValidHostname
(
context
,
hostname
)
)
{
return
;
}
...
...
@@ -633,7 +637,7 @@ public class PushNotificationHandler implements PushConstants {
return
null
;
}
return
jsonObject
.
getString
(
"host"
);
return
ServerPolicyHelper
.
enforceHostname
(
jsonObject
.
getString
(
"host"
)
);
}
catch
(
Exception
e
)
{
return
null
;
}
...
...
@@ -651,4 +655,17 @@ public class PushNotificationHandler implements PushConstants {
return
null
;
}
}
private
boolean
isValidHostname
(
Context
context
,
String
hostname
)
{
final
List
<
ServerInfo
>
serverInfoList
=
ConnectivityManager
.
getInstance
(
context
.
getApplicationContext
()).
getServerList
();
for
(
ServerInfo
serverInfo
:
serverInfoList
)
{
if
(
serverInfo
.
hostname
.
equals
(
hostname
))
{
return
true
;
}
}
return
false
;
}
}
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