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
6ccb8ad4
Commit
6ccb8ad4
authored
Dec 28, 2016
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
From string to constants
parent
7db4b7cf
Changes
41
Hide whitespace changes
Inline
Side-by-side
Showing
41 changed files
with
367 additions
and
215 deletions
+367
-215
RocketChatApplication.java
.../main/java/chat/rocket/android/RocketChatApplication.java
+1
-1
RocketChatCache.java
app/src/main/java/chat/rocket/android/RocketChatCache.java
+17
-0
AbstractAuthedActivity.java
.../chat/rocket/android/activity/AbstractAuthedActivity.java
+4
-4
AddServerActivity.java
.../java/chat/rocket/android/activity/AddServerActivity.java
+6
-5
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+3
-3
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+4
-4
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+18
-2
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+24
-23
AbstractOAuthFragment.java
.../rocket/android/fragment/oauth/AbstractOAuthFragment.java
+2
-2
InputHostnameFragment.java
...android/fragment/server_config/InputHostnameFragment.java
+7
-6
RetryConnectFragment.java
.../android/fragment/server_config/RetryConnectFragment.java
+2
-2
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+2
-2
AddDirectMessageDialogFragment.java
...agment/sidebar/dialog/AddDirectMessageDialogFragment.java
+2
-2
CheckSum.java
app/src/main/java/chat/rocket/android/helper/CheckSum.java
+1
-1
FileUploadHelper.java
...ain/java/chat/rocket/android/helper/FileUploadHelper.java
+11
-11
RoomUserAdapter.java
...android/layouthelper/chatroom/dialog/RoomUserAdapter.java
+1
-1
ServerConfig.java
...src/main/java/chat/rocket/android/model/ServerConfig.java
+23
-6
Message.java
app/src/main/java/chat/rocket/android/model/ddp/Message.java
+17
-5
MeteorLoginServiceConfiguration.java
...et/android/model/ddp/MeteorLoginServiceConfiguration.java
+7
-0
PublicSetting.java
...ain/java/chat/rocket/android/model/ddp/PublicSetting.java
+20
-14
RoomSubscription.java
.../java/chat/rocket/android/model/ddp/RoomSubscription.java
+21
-8
User.java
app/src/main/java/chat/rocket/android/model/ddp/User.java
+9
-1
FileUploading.java
...ava/chat/rocket/android/model/internal/FileUploading.java
+12
-0
GetUsersOfRoomsProcedure.java
...cket/android/model/internal/GetUsersOfRoomsProcedure.java
+7
-0
LoadMessageProcedure.java
...t/rocket/android/model/internal/LoadMessageProcedure.java
+8
-1
MethodCall.java
...n/java/chat/rocket/android/model/internal/MethodCall.java
+13
-6
NotificationItem.java
.../chat/rocket/android/model/internal/NotificationItem.java
+9
-0
Session.java
...main/java/chat/rocket/android/model/internal/Session.java
+14
-6
RocketChatService.java
...n/java/chat/rocket/android/service/RocketChatService.java
+7
-7
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+3
-3
NotificationDismissalCallbackService.java
...ce/notification/NotificationDismissalCallbackService.java
+1
-1
FileUploadingToS3Observer.java
...t/android/service/observer/FileUploadingToS3Observer.java
+19
-18
FileUploadingWithUfsObserver.java
...ndroid/service/observer/FileUploadingWithUfsObserver.java
+22
-21
GetUsersOfRoomsProcedureObserver.java
...id/service/observer/GetUsersOfRoomsProcedureObserver.java
+5
-5
LoadMessageProcedureObserver.java
...ndroid/service/observer/LoadMessageProcedureObserver.java
+13
-13
MethodCallObserver.java
...t/rocket/android/service/observer/MethodCallObserver.java
+13
-13
NewMessageObserver.java
...t/rocket/android/service/observer/NewMessageObserver.java
+7
-7
NotificationItemObserver.java
...et/android/service/observer/NotificationItemObserver.java
+2
-2
ReactiveNotificationManager.java
...android/service/observer/ReactiveNotificationManager.java
+4
-3
SessionObserver.java
...chat/rocket/android/service/observer/SessionObserver.java
+3
-3
TokenLoginObserver.java
...t/rocket/android/service/observer/TokenLoginObserver.java
+3
-3
No files found.
app/src/main/java/chat/rocket/android/RocketChatApplication.java
View file @
6ccb8ad4
...
...
@@ -24,7 +24,7 @@ public class RocketChatApplication extends MultiDexApplication {
new
RealmConfiguration
.
Builder
().
deleteRealmIfMigrationNeeded
().
build
());
List
<
ServerConfig
>
configs
=
RealmStore
.
getDefault
().
executeTransactionForReadResults
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
isNotNull
(
"session"
).
findAll
());
realm
.
where
(
ServerConfig
.
class
).
isNotNull
(
ServerConfig
.
SESSION
).
findAll
());
for
(
ServerConfig
config
:
configs
)
{
RealmStore
.
put
(
config
.
getServerConfigId
());
}
...
...
app/src/main/java/chat/rocket/android/RocketChatCache.java
View file @
6ccb8ad4
...
...
@@ -3,6 +3,8 @@ package chat.rocket.android;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
java.util.UUID
;
/**
* sharedpreference-based cache.
*/
...
...
@@ -10,10 +12,25 @@ public class RocketChatCache {
public
static
final
String
KEY_SELECTED_SERVER_CONFIG_ID
=
"selectedServerConfigId"
;
public
static
final
String
KEY_SELECTED_ROOM_ID
=
"selectedRoomId"
;
private
static
final
String
PUSH_ID
=
"pushId"
;
/**
* get SharedPreference instance for RocketChat application cache.
*/
public
static
SharedPreferences
get
(
Context
context
)
{
return
context
.
getSharedPreferences
(
"cache"
,
Context
.
MODE_PRIVATE
);
}
public
static
String
getPushId
(
Context
context
)
{
SharedPreferences
preferences
=
get
(
context
);
String
id
=
null
;
if
(!
preferences
.
contains
(
PUSH_ID
))
{
// generates one and save
id
=
UUID
.
randomUUID
().
toString
();
SharedPreferences
.
Editor
editor
=
preferences
.
edit
();
editor
.
putString
(
PUSH_ID
,
id
);
editor
.
apply
();
}
return
preferences
.
getString
(
PUSH_ID
,
id
);
}
}
app/src/main/java/chat/rocket/android/activity/AbstractAuthedActivity.java
View file @
6ccb8ad4
...
...
@@ -28,7 +28,7 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
private
RealmListObserver
<
ServerConfig
>
unconfiguredServersObserver
=
RealmStore
.
getDefault
()
.
createListObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
isNotNull
(
"session"
).
findAll
())
realm
.
where
(
ServerConfig
.
class
).
isNotNull
(
ServerConfig
.
SESSION
).
findAll
())
.
setOnUpdateListener
(
results
->
{
if
(
results
.
isEmpty
())
{
LaunchUtil
.
showAddServerActivity
(
this
);
...
...
@@ -41,10 +41,10 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
if
(
savedInstanceState
==
null
)
{
Intent
intent
=
getIntent
();
if
(
intent
!=
null
)
{
if
(
intent
.
hasExtra
(
"serverConfigId"
))
{
if
(
intent
.
hasExtra
(
ServerConfig
.
ID
))
{
SharedPreferences
.
Editor
editor
=
RocketChatCache
.
get
(
this
).
edit
();
editor
.
putString
(
RocketChatCache
.
KEY_SELECTED_SERVER_CONFIG_ID
,
intent
.
getStringExtra
(
"serverConfigId"
));
intent
.
getStringExtra
(
ServerConfig
.
ID
));
if
(
intent
.
hasExtra
(
"roomId"
))
{
editor
.
putString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
intent
.
getStringExtra
(
"roomId"
));
...
...
@@ -104,7 +104,7 @@ abstract class AbstractAuthedActivity extends AbstractFragmentActivity {
}
RoomSubscription
room
=
RealmStore
.
get
(
serverConfigId
).
executeTransactionForRead
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
).
findFirst
());
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
).
findFirst
());
if
(
room
==
null
)
{
prefs
.
edit
()
.
remove
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
)
...
...
app/src/main/java/chat/rocket/android/activity/AddServerActivity.java
View file @
6ccb8ad4
...
...
@@ -19,7 +19,8 @@ public class AddServerActivity extends AbstractFragmentActivity {
private
String
serverConfigId
;
private
RealmListObserver
<
ServerConfig
>
configuredServersObserver
=
RealmStore
.
getDefault
()
.
createListObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
isNotNull
(
"session"
).
findAll
())
.
createListObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
isNotNull
(
ServerConfig
.
SESSION
).
findAll
())
.
setOnUpdateListener
(
results
->
{
if
(!
results
.
isEmpty
())
{
RocketChatCache
.
get
(
this
).
edit
()
...
...
@@ -32,7 +33,7 @@ public class AddServerActivity extends AbstractFragmentActivity {
private
RealmObjectObserver
<
ServerConfig
>
targetServerConfigObserver
=
RealmStore
.
getDefault
()
.
createObjectObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
))
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
))
.
setOnUpdateListener
(
config
->
{
if
(
config
==
null
||
config
.
getState
()
==
ServerConfig
.
STATE_CONNECTION_ERROR
)
{
showFragment
(
new
InputHostnameFragment
());
...
...
@@ -52,7 +53,7 @@ public class AddServerActivity extends AbstractFragmentActivity {
private
void
setupServerConfigId
()
{
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
isNull
(
"hostname"
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
isNull
(
ServerConfig
.
HOSTNAME
).
findFirst
());
if
(
config
!=
null
)
{
serverConfigId
=
config
.
getServerConfigId
();
return
;
...
...
@@ -60,7 +61,7 @@ public class AddServerActivity extends AbstractFragmentActivity {
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"state"
,
ServerConfig
.
STATE_CONNECTION_ERROR
).
findFirst
());
.
equalTo
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_CONNECTION_ERROR
).
findFirst
());
if
(
config
!=
null
)
{
serverConfigId
=
config
.
getServerConfigId
();
return
;
...
...
@@ -105,7 +106,7 @@ public class AddServerActivity extends AbstractFragmentActivity {
if
(
args
==
null
)
{
args
=
new
Bundle
();
}
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
args
.
putString
(
ServerConfig
.
ID
,
serverConfigId
);
fragment
.
setArguments
(
args
);
}
...
...
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
6ccb8ad4
...
...
@@ -143,9 +143,9 @@ public class MainActivity extends AbstractAuthedActivity {
sessionObserver
=
realmHelper
.
createObjectObserver
(
realm
->
Session
.
queryDefaultSession
(
realm
)
.
isNotNull
(
"token"
)
.
equalTo
(
"tokenVerified"
,
true
)
.
isNull
(
"error"
))
.
isNotNull
(
Session
.
TOKEN
)
.
equalTo
(
Session
.
TOKEN_VERIFIED
,
true
)
.
isNull
(
Session
.
ERROR
))
.
setOnUpdateListener
(
session
->
{
if
(
session
==
null
&&
isForeground
)
{
LaunchUtil
.
showServerConfigActivity
(
this
,
serverConfigId
);
...
...
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
6ccb8ad4
...
...
@@ -41,7 +41,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return
;
}
serverConfigId
=
intent
.
getStringExtra
(
"serverConfigId"
);
serverConfigId
=
intent
.
getStringExtra
(
ServerConfig
.
ID
);
if
(
TextUtils
.
isEmpty
(
serverConfigId
))
{
finish
();
return
;
...
...
@@ -50,8 +50,8 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
serverConfigErrorObserver
=
RealmStore
.
getDefault
()
.
createObjectObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"serverConfigId"
,
serverConfigId
)
.
equalTo
(
"state"
,
ServerConfig
.
STATE_CONNECTION_ERROR
))
.
equalTo
(
ServerConfig
.
ID
,
serverConfigId
)
.
equalTo
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_CONNECTION_ERROR
))
.
setOnUpdateListener
(
this
::
onRenderServerConfigError
);
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
...
...
@@ -128,7 +128,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
if
(
args
==
null
)
{
args
=
new
Bundle
();
}
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
args
.
putString
(
ServerConfig
.
ID
,
serverConfigId
);
fragment
.
setArguments
(
args
);
}
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
6ccb8ad4
package
chat
.
rocket
.
android
.
api
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.Patterns
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
...
...
@@ -17,6 +19,7 @@ import chat.rocket.android.model.ddp.PublicSetting;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.model.internal.MethodCall
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.model.params.PushUpdate
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android_ddp.DDPClientCallback
;
...
...
@@ -24,6 +27,7 @@ import hugo.weaving.DebugLog;
/**
* Utility class for creating/handling MethodCall or RPC.
*
* TODO: separate method into several manager classes (SubscriptionManager, MessageManager, ...).
*/
public
class
MethodCallHelper
{
...
...
@@ -37,9 +41,8 @@ public class MethodCallHelper {
protected
final
RealmHelper
realmHelper
;
protected
final
DDPClientWrapper
ddpClient
;
@Deprecated
/**
*
Deprecated. use MethodCall(Context, String) instea
d.
*
initialize with ServerConfigI
d.
*/
public
MethodCallHelper
(
String
serverConfigId
)
{
this
(
null
,
serverConfigId
);
...
...
@@ -304,6 +307,19 @@ public class MethodCallHelper {
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
pushUpdate
(
@NonNull
String
pushId
,
@NonNull
String
token
,
@Nullable
String
userId
)
{
return
call
(
"raix:push-update"
,
TIMEOUT_MS
,
()
->
{
JSONObject
param
=
new
PushUpdate
(
pushId
,
token
,
userId
).
toJson
();
return
new
JSONArray
().
put
(
param
);
}).
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
pushSetUser
(
String
pushId
)
{
return
call
(
"raix:push-setuser"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
pushId
))
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
/**
* send message.
*/
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
6ccb8ad4
...
...
@@ -104,20 +104,21 @@ public class RoomFragment extends AbstractChatRoomFragment
roomId
=
args
.
getString
(
"roomId"
);
hostname
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"serverConfigId"
,
serverConfigId
)
.
isNotNull
(
"hostname"
)
.
equalTo
(
ServerConfig
.
ID
,
serverConfigId
)
.
isNotNull
(
ServerConfig
.
HOSTNAME
)
.
findFirst
()).
getHostname
();
userId
=
realmHelper
.
executeTransactionForRead
(
realm
->
User
.
queryCurrentUser
(
realm
).
findFirst
()).
getId
();
token
=
realmHelper
.
executeTransactionForRead
(
realm
->
Session
.
queryDefaultSession
(
realm
).
findFirst
()).
getToken
();
roomObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
))
.
createObjectObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
))
.
setOnUpdateListener
(
this
::
onRenderRoom
);
procedureObserver
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
LoadMessageProcedure
.
class
).
equalTo
(
"roomId"
,
roomId
))
realm
.
where
(
LoadMessageProcedure
.
class
).
equalTo
(
LoadMessageProcedure
.
ID
,
roomId
))
.
setOnUpdateListener
(
this
::
onUpdateLoadMessageProcedure
);
if
(
savedInstanceState
==
null
)
{
initialRequest
();
...
...
@@ -134,8 +135,8 @@ public class RoomFragment extends AbstractChatRoomFragment
RecyclerView
listView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
recyclerview
);
MessageListAdapter
adapter
=
(
MessageListAdapter
)
realmHelper
.
createListAdapter
(
getContext
(),
realm
->
realm
.
where
(
Message
.
class
)
.
equalTo
(
"rid"
,
roomId
)
.
findAllSorted
(
"ts"
,
Sort
.
DESCENDING
),
.
equalTo
(
Message
.
ROOM_ID
,
roomId
)
.
findAllSorted
(
Message
.
TIMESTAMP
,
Sort
.
DESCENDING
),
context
->
new
MessageListAdapter
(
context
,
hostname
,
userId
,
token
)
);
listView
.
setAdapter
(
adapter
);
...
...
@@ -167,15 +168,15 @@ public class RoomFragment extends AbstractChatRoomFragment
.
setPositiveButton
(
R
.
string
.
resend
,
(
dialog
,
which
)
->
{
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
"_id"
,
messageId
)
.
put
(
"syncstate"
,
SyncState
.
NOT_SYNCED
))
.
put
(
Message
.
ID
,
messageId
)
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
))
).
continueWith
(
new
LogcatIfError
());
})
.
setNegativeButton
(
android
.
R
.
string
.
cancel
,
null
)
.
setNeutralButton
(
R
.
string
.
discard
,
(
dialog
,
which
)
->
{
realmHelper
.
executeTransaction
(
realm
->
realm
.
where
(
Message
.
class
)
.
equalTo
(
"_id"
,
messageId
).
findAll
().
deleteAllFromRealm
()
.
equalTo
(
Message
.
ID
,
messageId
).
findAll
().
deleteAllFromRealm
()
).
continueWith
(
new
LogcatIfError
());
})
.
show
();
...
...
@@ -225,11 +226,11 @@ public class RoomFragment extends AbstractChatRoomFragment
messageFormManager
.
setSendMessageCallback
(
messageText
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
"_id"
,
UUID
.
randomUUID
().
toString
())
.
put
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
put
(
"ts"
,
System
.
currentTimeMillis
())
.
put
(
"rid"
,
roomId
)
.
put
(
"msg"
,
messageText
))));
.
put
(
Message
.
ID
,
UUID
.
randomUUID
().
toString
())
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
Message
.
TIMESTAMP
,
System
.
currentTimeMillis
())
.
put
(
Message
.
ROOM_ID
,
roomId
)
.
put
(
Message
.
MESSAGE
,
messageText
))));
messageFormManager
.
registerExtraActionItem
(
new
ImageUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
AudioUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
VideoUploadActionItem
());
...
...
@@ -298,10 +299,10 @@ public class RoomFragment extends AbstractChatRoomFragment
private
void
initialRequest
()
{
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
createOrUpdateObjectFromJson
(
LoadMessageProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
put
(
"count"
,
100
)
.
put
(
"reset"
,
true
));
.
put
(
LoadMessageProcedure
.
ID
,
roomId
)
.
put
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
LoadMessageProcedure
.
COUNT
,
100
)
.
put
(
LoadMessageProcedure
.
RESET
,
true
));
return
null
;
}).
onSuccessTask
(
task
->
{
RocketChatService
.
keepAlive
(
getContext
());
...
...
@@ -312,13 +313,13 @@ public class RoomFragment extends AbstractChatRoomFragment
private
void
loadMoreRequest
()
{
realmHelper
.
executeTransaction
(
realm
->
{
LoadMessageProcedure
procedure
=
realm
.
where
(
LoadMessageProcedure
.
class
)
.
equalTo
(
"roomId"
,
roomId
)
.
equalTo
(
LoadMessageProcedure
.
ID
,
roomId
)
.
beginGroup
()
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
equalTo
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
or
()
.
equalTo
(
"syncstate"
,
SyncState
.
FAILED
)
.
equalTo
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
endGroup
()
.
equalTo
(
"hasNext"
,
true
)
.
equalTo
(
LoadMessageProcedure
.
HAS_NEXT
,
true
)
.
findFirst
();
if
(
procedure
!=
null
)
{
procedure
.
setSyncState
(
SyncState
.
NOT_SYNCED
);
...
...
@@ -332,7 +333,7 @@ public class RoomFragment extends AbstractChatRoomFragment
private
void
markAsReadIfNeeded
()
{
RoomSubscription
room
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"rid"
,
roomId
).
findFirst
());
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
).
findFirst
());
if
(
room
!=
null
&&
room
.
isAlert
())
{
new
MethodCallHelper
(
getContext
(),
serverConfigId
).
readMessages
(
roomId
)
.
continueWith
(
new
LogcatIfError
());
...
...
app/src/main/java/chat/rocket/android/fragment/oauth/AbstractOAuthFragment.java
View file @
6ccb8ad4
...
...
@@ -57,11 +57,11 @@ public abstract class AbstractOAuthFragment extends AbstractWebViewFragment {
serverConfigId
=
args
.
getString
(
"serverConfigId"
);
ServerConfig
serverConfig
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
());
MeteorLoginServiceConfiguration
oauthConfig
=
RealmStore
.
get
(
serverConfigId
).
executeTransactionForRead
(
realm
->
realm
.
where
(
MeteorLoginServiceConfiguration
.
class
)
.
equalTo
(
"service"
,
getOAuthServiceName
())
.
equalTo
(
MeteorLoginServiceConfiguration
.
SERVICE
,
getOAuthServiceName
())
.
findFirst
());
if
(
serverConfig
==
null
||
oauthConfig
==
null
)
{
throw
new
IllegalArgumentException
(
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/InputHostnameFragment.java
View file @
6ccb8ad4
...
...
@@ -21,7 +21,7 @@ import chat.rocket.android.realm_helper.RealmStore;
public
class
InputHostnameFragment
extends
AbstractServerConfigFragment
{
RealmObjectObserver
<
ServerConfig
>
serverConfigObserver
=
RealmStore
.
getDefault
()
.
createObjectObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
))
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
))
.
setOnUpdateListener
(
this
::
onRenderServerConfig
);
public
InputHostnameFragment
()
{
...
...
@@ -82,11 +82,12 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
RealmStore
.
getDefault
().
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
().
put
(
"serverConfigId"
,
serverConfigId
)
.
put
(
"hostname"
,
hostname
)
.
put
(
"error"
,
JSONObject
.
NULL
)
.
put
(
"session"
,
JSONObject
.
NULL
)
.
put
(
"state"
,
ServerConfig
.
STATE_READY
))).
continueWith
(
new
LogcatIfError
());
new
JSONObject
().
put
(
ServerConfig
.
ID
,
serverConfigId
)
.
put
(
ServerConfig
.
HOSTNAME
,
hostname
)
.
put
(
ServerConfig
.
ERROR
,
JSONObject
.
NULL
)
.
put
(
ServerConfig
.
SESSION
,
JSONObject
.
NULL
)
.
put
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_READY
)))
.
continueWith
(
new
LogcatIfError
());
}
private
void
showError
(
String
errString
)
{
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/RetryConnectFragment.java
View file @
6ccb8ad4
...
...
@@ -28,7 +28,7 @@ public class RetryConnectFragment extends AbstractServerConfigFragment {
super
.
onCreate
(
savedInstanceState
);
serverConfigObserver
=
RealmStore
.
getDefault
()
.
createObjectObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
))
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
))
.
setOnUpdateListener
(
this
::
onRenderServerConfig
);
}
...
...
@@ -41,7 +41,7 @@ public class RetryConnectFragment extends AbstractServerConfigFragment {
RealmStore
.
getDefault
()
.
executeTransaction
(
realm
->
{
ServerConfig
config
=
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
();
.
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
();
if
(
config
!=
null
&&
config
.
getState
()
==
ServerConfig
.
STATE_CONNECTION_ERROR
)
{
config
.
setState
(
ServerConfig
.
STATE_READY
);
}
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
6ccb8ad4
...
...
@@ -62,7 +62,7 @@ public class SidebarMainFragment extends AbstractFragment {
serverConfigId
=
args
==
null
?
null
:
args
.
getString
(
"serverConfigId"
);
if
(!
TextUtils
.
isEmpty
(
serverConfigId
))
{
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
());
if
(
config
!=
null
)
{
hostname
=
config
.
getHostname
();
}
...
...
@@ -71,7 +71,7 @@ public class SidebarMainFragment extends AbstractFragment {
if
(
realmHelper
!=
null
)
{
roomsObserver
=
realmHelper
.
createListObserver
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
"open"
,
true
).
findAll
())
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
RoomSubscription
.
OPEN
,
true
).
findAll
())
.
setOnUpdateListener
(
list
->
roomListManager
.
setRooms
(
list
));
currentUserObserver
=
realmHelper
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AddDirectMessageDialogFragment.java
View file @
6ccb8ad4
...
...
@@ -34,8 +34,8 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen
RealmAutoCompleteAdapter
<
User
>
adapter
=
realmHelper
.
createAutoCompleteAdapter
(
getContext
(),
(
realm
,
text
)
->
realm
.
where
(
User
.
class
)
.
contains
(
"username"
,
text
,
Case
.
INSENSITIVE
)
.
findAllSorted
(
"username"
),
.
contains
(
User
.
USERNAME
,
text
,
Case
.
INSENSITIVE
)
.
findAllSorted
(
User
.
USERNAME
),
context
->
new
SuggestUserAdapter
(
context
,
hostname
));
autoCompleteTextView
.
setAdapter
(
adapter
);
...
...
app/src/main/java/chat/rocket/android/helper/CheckSum.java
View file @
6ccb8ad4
...
...
@@ -12,7 +12,7 @@ public class CheckSum {
* SHA-256.
*/
public
static
String
sha256
(
String
orig
)
{
MessageDigest
messageDigest
=
null
;
MessageDigest
messageDigest
;
try
{
messageDigest
=
MessageDigest
.
getInstance
(
"SHA-256"
);
}
catch
(
NoSuchAlgorithmException
exception
)
{
...
...
app/src/main/java/chat/rocket/android/helper/FileUploadHelper.java
View file @
6ccb8ad4
...
...
@@ -33,8 +33,7 @@ public class FileUploadHelper {
}
/**
* requestUploading file.
* returns id for observing progress.
* requestUploading file. returns id for observing progress.
*/
public
@Nullable
...
...
@@ -64,15 +63,16 @@ public class FileUploadHelper {
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
put
(
"storageType"
,
TextUtils
.
isEmpty
(
storageType
)
?
JSONObject
.
NULL
:
storageType
)
.
put
(
"uri"
,
uri
.
toString
())
.
put
(
"filename"
,
filename
)
.
put
(
"filesize"
,
filesize
)
.
put
(
"mimeType"
,
mimeType
)
.
put
(
"roomId"
,
roomId
)
.
put
(
"error"
,
JSONObject
.
NULL
)
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
FileUploading
.
STORAGE_TYPE
,
TextUtils
.
isEmpty
(
storageType
)
?
JSONObject
.
NULL
:
storageType
)
.
put
(
FileUploading
.
URI
,
uri
.
toString
())
.
put
(
FileUploading
.
FILENAME
,
filename
)
.
put
(
FileUploading
.
FILE_SIZE
,
filesize
)
.
put
(
FileUploading
.
MIME_TYPE
,
mimeType
)
.
put
(
FileUploading
.
ROOM_ID
,
roomId
)
.
put
(
FileUploading
.
ERROR
,
JSONObject
.
NULL
)
)
).
continueWith
(
new
LogcatIfError
());
return
uplId
;
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/dialog/RoomUserAdapter.java
View file @
6ccb8ad4
...
...
@@ -48,7 +48,7 @@ public class RoomUserAdapter extends RecyclerView.Adapter<RoomUserViewHolder> {
}
User
user
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
User
.
class
).
equalTo
(
"username"
,
username
).
findFirst
());
realm
.
where
(
User
.
class
).
equalTo
(
User
.
USERNAME
,
username
).
findFirst
());
if
(
user
==
null
)
{
user
=
new
User
();
user
.
setUsername
(
username
);
...
...
app/src/main/java/chat/rocket/android/model/ServerConfig.java
View file @
6ccb8ad4
...
...
@@ -13,6 +13,14 @@ import hugo.weaving.DebugLog;
* Server configuration.
*/
public
class
ServerConfig
extends
RealmObject
{
public
static
final
String
ID
=
"serverConfigId"
;
public
static
final
String
HOSTNAME
=
"hostname"
;
public
static
final
String
STATE
=
"state"
;
public
static
final
String
SESSION
=
"session"
;
public
static
final
String
ERROR
=
"error"
;
public
static
final
String
SYNC_PUSH_TOKEN
=
"syncPushToken"
;
public
static
final
int
STATE_READY
=
0
;
public
static
final
int
STATE_CONNECTING
=
1
;
public
static
final
int
STATE_CONNECTED
=
2
;
...
...
@@ -23,6 +31,7 @@ public class ServerConfig extends RealmObject {
private
int
state
;
private
String
session
;
private
String
error
;
private
boolean
syncPushToken
;
/**
* Log the server connection is lost due to some exception.
...
...
@@ -31,9 +40,9 @@ public class ServerConfig extends RealmObject {
public
static
void
logConnectionError
(
String
serverConfigId
,
Exception
exception
)
{
RealmStore
.
getDefault
().
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
()
.
put
(
"serverConfigId"
,
serverConfigId
)
.
put
(
"state"
,
STATE_CONNECTION_ERROR
)
.
put
(
"error"
,
exception
.
getMessage
())))
.
put
(
ID
,
serverConfigId
)
.
put
(
STATE
,
STATE_CONNECTION_ERROR
)
.
put
(
ERROR
,
exception
.
getMessage
())))
.
continueWith
(
new
LogcatIfError
());
}
...
...
@@ -43,11 +52,11 @@ public class ServerConfig extends RealmObject {
public
static
Task
<
Void
>
updateState
(
final
String
serverConfigId
,
int
state
)
{
return
RealmStore
.
getDefault
().
executeTransaction
(
realm
->
{
ServerConfig
config
=
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
();
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ID
,
serverConfigId
).
findFirst
();
if
(
config
==
null
||
config
.
getState
()
!=
state
)
{
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
()
.
put
(
"serverConfigId"
,
serverConfigId
)
.
put
(
"state"
,
state
));
.
put
(
ID
,
serverConfigId
)
.
put
(
STATE
,
state
));
}
return
null
;
});
...
...
@@ -92,4 +101,12 @@ public class ServerConfig extends RealmObject {
public
void
setError
(
String
error
)
{
this
.
error
=
error
;
}
public
boolean
shouldSyncPushToken
()
{
return
syncPushToken
;
}
public
void
setSyncPushToken
(
boolean
syncPushToken
)
{
this
.
syncPushToken
=
syncPushToken
;
}
}
app/src/main/java/chat/rocket/android/model/ddp/Message.java
View file @
6ccb8ad4
...
...
@@ -5,6 +5,7 @@ import io.realm.annotations.PrimaryKey;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
chat.rocket.android.model.JsonConstants
;
import
chat.rocket.android.model.SyncState
;
/**
...
...
@@ -15,6 +16,17 @@ import chat.rocket.android.model.SyncState;
public
class
Message
extends
RealmObject
{
//ref: Rocket.Chat:packages/rocketchat-lib/lib/MessageTypes.coffee
public
static
final
String
ID
=
"_id"
;
public
static
final
String
TYPE
=
"t"
;
public
static
final
String
ROOM_ID
=
"rid"
;
public
static
final
String
SYNC_STATE
=
"syncstate"
;
public
static
final
String
TIMESTAMP
=
"ts"
;
public
static
final
String
MESSAGE
=
"msg"
;
public
static
final
String
USER
=
"u"
;
public
static
final
String
GROUPABLE
=
"groupable"
;
public
static
final
String
ATTACHMENTS
=
"attachments"
;
public
static
final
String
URLS
=
"urls"
;
@PrimaryKey
private
String
_id
;
private
String
t
;
//type:
private
String
rid
;
//roomId.
...
...
@@ -27,12 +39,12 @@ public class Message extends RealmObject {
private
String
urls
;
//JSONArray.
public
static
JSONObject
customizeJson
(
JSONObject
messageJson
)
throws
JSONException
{
long
ts
=
messageJson
.
getJSONObject
(
"ts"
).
getLong
(
"$date"
);
messageJson
.
remove
(
"ts"
);
messageJson
.
put
(
"ts"
,
ts
).
put
(
"syncstate"
,
SyncState
.
SYNCED
);
long
ts
=
messageJson
.
getJSONObject
(
TIMESTAMP
).
getLong
(
JsonConstants
.
DATE
);
messageJson
.
remove
(
TIMESTAMP
);
messageJson
.
put
(
TIMESTAMP
,
ts
).
put
(
SYNC_STATE
,
SyncState
.
SYNCED
);
if
(
messageJson
.
isNull
(
"groupable"
))
{
messageJson
.
put
(
"groupable"
,
true
);
if
(
messageJson
.
isNull
(
GROUPABLE
))
{
messageJson
.
put
(
GROUPABLE
,
true
);
}
return
messageJson
;
...
...
app/src/main/java/chat/rocket/android/model/ddp/MeteorLoginServiceConfiguration.java
View file @
6ccb8ad4
...
...
@@ -10,6 +10,13 @@ import io.realm.annotations.PrimaryKey;
"PMD.MethodNamingConventions"
,
"PMD.VariableNamingConventions"
})
public
class
MeteorLoginServiceConfiguration
extends
RealmObject
{
public
static
final
String
ID
=
"_id"
;
public
static
final
String
SERVICE
=
"service"
;
public
static
final
String
CONSUMER_KEY
=
"consumerKey"
;
public
static
final
String
APP_ID
=
"appId"
;
public
static
final
String
CLIENT_ID
=
"clientId"
;
@PrimaryKey
private
String
_id
;
private
String
service
;
private
String
consumerKey
;
//for Twitter
...
...
app/src/main/java/chat/rocket/android/model/ddp/PublicSetting.java
View file @
6ccb8ad4
...
...
@@ -6,6 +6,7 @@ import io.realm.annotations.PrimaryKey;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
chat.rocket.android.model.JsonConstants
;
import
chat.rocket.android.realm_helper.RealmHelper
;
/**
...
...
@@ -14,6 +15,14 @@ import chat.rocket.android.realm_helper.RealmHelper;
@SuppressWarnings
({
"PMD.ShortClassName"
,
"PMD.ShortVariable"
,
"PMD.MethodNamingConventions"
,
"PMD.VariableNamingConventions"
})
public
class
PublicSetting
extends
RealmObject
{
public
static
final
String
ID
=
"_id"
;
public
static
final
String
GROUP
=
"group"
;
public
static
final
String
TYPE
=
"type"
;
public
static
final
String
VALUE
=
"value"
;
public
static
final
String
UPDATED_AT
=
"_updatedAt"
;
public
static
final
String
META
=
"meta"
;
@PrimaryKey
private
String
_id
;
private
String
group
;
private
String
type
;
...
...
@@ -22,26 +31,25 @@ public class PublicSetting extends RealmObject {
private
String
meta
;
//JSON
public
static
JSONObject
customizeJson
(
JSONObject
settingJson
)
throws
JSONException
{
if
(!
settingJson
.
isNull
(
"_updatedAt"
))
{
long
updatedAt
=
settingJson
.
getJSONObject
(
"_updatedAt"
).
getLong
(
"$date"
);
settingJson
.
remove
(
"_updatedAt"
);
settingJson
.
put
(
"_updatedAt"
,
updatedAt
);
if
(!
settingJson
.
isNull
(
UPDATED_AT
))
{
long
updatedAt
=
settingJson
.
getJSONObject
(
UPDATED_AT
)
.
getLong
(
JsonConstants
.
DATE
);
settingJson
.
remove
(
UPDATED_AT
);
settingJson
.
put
(
UPDATED_AT
,
updatedAt
);
}
return
settingJson
;
}
private
static
@Nullable
PublicSetting
get
(
RealmHelper
realmHelper
,
String
_id
)
{
private
static
PublicSetting
get
(
RealmHelper
realmHelper
,
String
_id
)
{
return
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
PublicSetting
.
class
).
equalTo
(
"_id"
,
_id
).
findFirst
());
realm
.
where
(
PublicSetting
.
class
).
equalTo
(
ID
,
_id
).
findFirst
());
}
public
static
@Nullable
String
getString
(
RealmHelper
realmHelper
,
String
_id
,
String
defaultValue
)
{
public
static
String
getString
(
RealmHelper
realmHelper
,
String
_id
,
String
defaultValue
)
{
PublicSetting
setting
=
get
(
realmHelper
,
_id
);
if
(
setting
!=
null
)
{
return
setting
.
getValue
();
...
...
@@ -49,10 +57,8 @@ public class PublicSetting extends RealmObject {
return
defaultValue
;
}
public
static
@Nullable
boolean
getBoolean
(
RealmHelper
realmHelper
,
String
_id
,
boolean
defaultValue
)
{
public
static
boolean
getBoolean
(
RealmHelper
realmHelper
,
String
_id
,
boolean
defaultValue
)
{
PublicSetting
setting
=
get
(
realmHelper
,
_id
);
if
(
setting
!=
null
)
{
return
Boolean
.
parseBoolean
(
setting
.
getValue
());
...
...
app/src/main/java/chat/rocket/android/model/ddp/RoomSubscription.java
View file @
6ccb8ad4
...
...
@@ -5,12 +5,25 @@ import io.realm.annotations.PrimaryKey;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
chat.rocket.android.model.JsonConstants
;
/**
* Chat Room(Subscription).
*/
@SuppressWarnings
({
"PMD.ShortClassName"
,
"PMD.ShortVariable"
,
"PMD.MethodNamingConventions"
,
"PMD.VariableNamingConventions"
})
public
class
RoomSubscription
extends
RealmObject
{
public
static
final
String
ID
=
"_id"
;
public
static
final
String
ROOM_ID
=
"rid"
;
public
static
final
String
NAME
=
"name"
;
public
static
final
String
TYPE
=
"t"
;
public
static
final
String
OPEN
=
"open"
;
public
static
final
String
ALERT
=
"alert"
;
public
static
final
String
UNREAD
=
"unread"
;
public
static
final
String
UPDATED_AT
=
"_updatedAt"
;
public
static
final
String
LAST_SEEN
=
"ls"
;
public
static
final
String
TYPE_CHANNEL
=
"c"
;
public
static
final
String
TYPE_PRIVATE
=
"p"
;
public
static
final
String
TYPE_DIRECT_MESSAGE
=
"d"
;
...
...
@@ -27,16 +40,16 @@ public class RoomSubscription extends RealmObject {
private
long
ls
;
//last seen.
public
static
JSONObject
customizeJson
(
JSONObject
roomSubscriptionJson
)
throws
JSONException
{
if
(!
roomSubscriptionJson
.
isNull
(
"ls"
))
{
long
ls
=
roomSubscriptionJson
.
getJSONObject
(
"ls"
).
getLong
(
"$date"
);
roomSubscriptionJson
.
remove
(
"ls"
);
roomSubscriptionJson
.
put
(
"ls"
,
ls
);
if
(!
roomSubscriptionJson
.
isNull
(
LAST_SEEN
))
{
long
ls
=
roomSubscriptionJson
.
getJSONObject
(
LAST_SEEN
).
getLong
(
JsonConstants
.
DATE
);
roomSubscriptionJson
.
remove
(
LAST_SEEN
);
roomSubscriptionJson
.
put
(
LAST_SEEN
,
ls
);
}
if
(!
roomSubscriptionJson
.
isNull
(
"_updatedAt"
))
{
long
updatedAt
=
roomSubscriptionJson
.
getJSONObject
(
"_updatedAt"
).
getLong
(
"$date"
);
roomSubscriptionJson
.
remove
(
"_updatedAt"
);
roomSubscriptionJson
.
put
(
"_updatedAt"
,
updatedAt
);
if
(!
roomSubscriptionJson
.
isNull
(
UPDATED_AT
))
{
long
updatedAt
=
roomSubscriptionJson
.
getJSONObject
(
UPDATED_AT
).
getLong
(
JsonConstants
.
DATE
);
roomSubscriptionJson
.
remove
(
UPDATED_AT
);
roomSubscriptionJson
.
put
(
UPDATED_AT
,
updatedAt
);
}
return
roomSubscriptionJson
;
...
...
app/src/main/java/chat/rocket/android/model/ddp/User.java
View file @
6ccb8ad4
...
...
@@ -12,6 +12,14 @@ import io.realm.annotations.PrimaryKey;
@SuppressWarnings
({
"PMD.ShortClassName"
,
"PMD.ShortVariable"
,
"PMD.MethodNamingConventions"
,
"PMD.VariableNamingConventions"
})
public
class
User
extends
RealmObject
{
public
static
final
String
ID
=
"_id"
;
public
static
final
String
USERNAME
=
"username"
;
public
static
final
String
STATUS
=
"status"
;
public
static
final
String
UTC_OFFSET
=
"utcOffset"
;
public
static
final
String
EMAILS
=
"emails"
;
public
static
final
String
SETTINGS
=
"settings"
;
public
static
final
String
STATUS_ONLINE
=
"online"
;
public
static
final
String
STATUS_BUSY
=
"busy"
;
public
static
final
String
STATUS_AWAY
=
"away"
;
...
...
@@ -25,7 +33,7 @@ public class User extends RealmObject {
private
Settings
settings
;
public
static
RealmQuery
<
User
>
queryCurrentUser
(
Realm
realm
)
{
return
realm
.
where
(
User
.
class
).
isNotEmpty
(
"emails"
);
return
realm
.
where
(
User
.
class
).
isNotEmpty
(
EMAILS
);
}
public
String
getId
()
{
...
...
app/src/main/java/chat/rocket/android/model/internal/FileUploading.java
View file @
6ccb8ad4
...
...
@@ -7,6 +7,18 @@ import io.realm.annotations.PrimaryKey;
* holding statuses for uploading file.
*/
public
class
FileUploading
extends
RealmObject
{
public
static
final
String
ID
=
"uplId"
;
public
static
final
String
SYNC_STATE
=
"syncstate"
;
public
static
final
String
STORAGE_TYPE
=
"storageType"
;
public
static
final
String
URI
=
"uri"
;
public
static
final
String
FILENAME
=
"filename"
;
public
static
final
String
FILE_SIZE
=
"filesize"
;
public
static
final
String
MIME_TYPE
=
"mimeType"
;
public
static
final
String
ROOM_ID
=
"roomId"
;
public
static
final
String
UPLOADED_SIZE
=
"uploadedSize"
;
public
static
final
String
ERROR
=
"error"
;
public
static
final
String
STORAGE_TYPE_S3
=
"AmazonS3"
;
public
static
final
String
STORAGE_TYPE_GRID_FS
=
"GridFS"
;
public
static
final
String
STORAGE_TYPE_FILE_SYSTEM
=
"FileSystem"
;
...
...
app/src/main/java/chat/rocket/android/model/internal/GetUsersOfRoomsProcedure.java
View file @
6ccb8ad4
...
...
@@ -7,6 +7,13 @@ import io.realm.annotations.PrimaryKey;
* Get users in a Room.
*/
public
class
GetUsersOfRoomsProcedure
extends
RealmObject
{
public
static
final
String
ID
=
"roomId"
;
public
static
final
String
SYNC_STATE
=
"syncstate"
;
public
static
final
String
SHOW_ALL
=
"showAll"
;
public
static
final
String
TOTAL
=
"total"
;
public
static
final
String
RECORDS
=
"records"
;
@PrimaryKey
private
String
roomId
;
private
int
syncstate
;
private
boolean
showAll
;
...
...
app/src/main/java/chat/rocket/android/model/internal/LoadMessageProcedure.java
View file @
6ccb8ad4
...
...
@@ -7,9 +7,16 @@ import io.realm.annotations.PrimaryKey;
* Load messages in the room.
*/
public
class
LoadMessageProcedure
extends
RealmObject
{
public
static
final
String
ID
=
"roomId"
;
public
static
final
String
SYNC_STATE
=
"syncstate"
;
public
static
final
String
RESET
=
"reset"
;
public
static
final
String
TIMESTAMP
=
"timestamp"
;
public
static
final
String
COUNT
=
"count"
;
public
static
final
String
HAS_NEXT
=
"hasNext"
;
@PrimaryKey
private
String
roomId
;
private
int
syncstate
;
private
boolean
reset
;
private
long
timestamp
;
private
int
count
;
...
...
app/src/main/java/chat/rocket/android/model/internal/MethodCall.java
View file @
6ccb8ad4
...
...
@@ -20,6 +20,13 @@ import chat.rocket.android.service.RocketChatService;
public
class
MethodCall
extends
RealmObject
{
public
static
final
String
ID
=
"methodCallId"
;
public
static
final
String
SYNC_STATE
=
"syncstate"
;
public
static
final
String
NAME
=
"name"
;
public
static
final
String
PARAMS_JSON
=
"paramsJson"
;
public
static
final
String
RESULT_JSON
=
"resultJson"
;
public
static
final
String
TIMEOUT
=
"timeout"
;
private
static
final
HashMap
<
String
,
RealmObjectObserver
<
MethodCall
>>
REF_MAP
=
new
HashMap
<>();
@PrimaryKey
private
String
methodCallId
;
private
int
syncstate
;
...
...
@@ -38,10 +45,10 @@ public class MethodCall extends RealmObject {
TaskCompletionSource
<
String
>
task
=
new
TaskCompletionSource
<>();
realmHelper
.
executeTransaction
(
realm
->
{
MethodCall
call
=
realm
.
createObjectFromJson
(
MethodCall
.
class
,
new
JSONObject
()
.
put
(
"methodCallId"
,
newId
)
.
put
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
put
(
"timeout"
,
timeout
)
.
put
(
"name"
,
name
));
.
put
(
ID
,
newId
)
.
put
(
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
TIMEOUT
,
timeout
)
.
put
(
NAME
,
name
));
call
.
setParamsJson
(
paramsJson
);
return
null
;
}).
continueWith
(
_task
->
{
...
...
@@ -50,7 +57,7 @@ public class MethodCall extends RealmObject {
}
else
{
final
RealmObjectObserver
<
MethodCall
>
observer
=
realmHelper
.
createObjectObserver
(
realm
->
realm
.
where
(
MethodCall
.
class
).
equalTo
(
"methodCallId"
,
newId
));
realm
.
where
(
MethodCall
.
class
).
equalTo
(
ID
,
newId
));
observer
.
setOnUpdateListener
(
methodCall
->
{
if
(
methodCall
==
null
)
{
observer
.
unsub
();
...
...
@@ -95,7 +102,7 @@ public class MethodCall extends RealmObject {
public
static
final
Task
<
Void
>
remove
(
RealmHelper
realmHelper
,
String
methodCallId
)
{
return
realmHelper
.
executeTransaction
(
realm
->
realm
.
where
(
MethodCall
.
class
)
.
equalTo
(
"methodCallId"
,
methodCallId
)
.
equalTo
(
ID
,
methodCallId
)
.
findAll
()
.
deleteAllFromRealm
());
}
...
...
app/src/main/java/chat/rocket/android/model/internal/NotificationItem.java
View file @
6ccb8ad4
...
...
@@ -7,6 +7,15 @@ import io.realm.annotations.PrimaryKey;
* ViewData model for notification.
*/
public
class
NotificationItem
extends
RealmObject
{
public
static
final
String
ID
=
"roomId"
;
public
static
final
String
TITLE
=
"title"
;
public
static
final
String
DESCRIPTION
=
"description"
;
public
static
final
String
UNREAD_COUNT
=
"unreadCount"
;
public
static
final
String
SENDER_NAME
=
"senderName"
;
public
static
final
String
CONTENT_UPDATED_AT
=
"contentUpdatedAt"
;
public
static
final
String
LAST_SEEN_AT
=
"lastSeenAt"
;
@PrimaryKey
private
String
roomId
;
private
String
title
;
private
String
description
;
...
...
app/src/main/java/chat/rocket/android/model/internal/Session.java
View file @
6ccb8ad4
...
...
@@ -15,23 +15,31 @@ import hugo.weaving.DebugLog;
* Login session info.
*/
public
class
Session
extends
RealmObject
{
public
static
final
String
ID
=
"sessionId"
;
public
static
final
String
TOKEN
=
"token"
;
public
static
final
String
TOKEN_VERIFIED
=
"tokenVerified"
;
public
static
final
String
ERROR
=
"error"
;
public
static
final
int
DEFAULT_ID
=
0
;
public
static
final
String
AUTH_ERROR_CODE
=
"[403]"
;
@PrimaryKey
private
int
sessionId
;
//only 0 is used!
private
String
token
;
private
boolean
tokenVerified
;
private
String
error
;
public
static
RealmQuery
<
Session
>
queryDefaultSession
(
Realm
realm
)
{
return
realm
.
where
(
Session
.
class
).
equalTo
(
"sessionId"
,
Session
.
DEFAULT_ID
);
return
realm
.
where
(
Session
.
class
).
equalTo
(
ID
,
Session
.
DEFAULT_ID
);
}
/**
* Log the server connection is lost due to so
em
exception.
* Log the server connection is lost due to so
me
exception.
*/
@DebugLog
public
static
void
logError
(
RealmHelper
realmHelper
,
Exception
exception
)
{
String
errString
=
exception
.
getMessage
();
if
(!
TextUtils
.
isEmpty
(
errString
)
&&
errString
.
contains
(
"[403]"
))
{
if
(!
TextUtils
.
isEmpty
(
errString
)
&&
errString
.
contains
(
AUTH_ERROR_CODE
))
{
realmHelper
.
executeTransaction
(
realm
->
{
realm
.
delete
(
Session
.
class
);
return
null
;
...
...
@@ -39,9 +47,9 @@ public class Session extends RealmObject {
}
else
{
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Session
.
class
,
new
JSONObject
()
.
put
(
"sessionId"
,
Session
.
DEFAULT_ID
)
.
put
(
"tokenVerified"
,
false
)
.
put
(
"error"
,
errString
)))
.
put
(
ID
,
Session
.
DEFAULT_ID
)
.
put
(
TOKEN_VERIFIED
,
false
)
.
put
(
ERROR
,
errString
)))
.
continueWith
(
new
LogcatIfError
());
}
}
...
...
app/src/main/java/chat/rocket/android/service/RocketChatService.java
View file @
6ccb8ad4
...
...
@@ -39,8 +39,8 @@ public class RocketChatService extends Service {
realmHelper
=
RealmStore
.
getDefault
();
connectionRequiredServerConfigObserver
=
realmHelper
.
createListObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
isNotNull
(
"hostname"
)
.
equalTo
(
"state"
,
ServerConfig
.
STATE_READY
)
.
isNotNull
(
ServerConfig
.
HOSTNAME
)
.
equalTo
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_READY
)
.
findAll
())
.
setOnUpdateListener
(
this
::
connectToServerWithServerConfig
);
...
...
@@ -50,7 +50,7 @@ public class RocketChatService extends Service {
private
void
refreshServerConfigState
()
{
realmHelper
.
executeTransaction
(
realm
->
{
RealmResults
<
ServerConfig
>
configs
=
realm
.
where
(
ServerConfig
.
class
)
.
notEqualTo
(
"state"
,
ServerConfig
.
STATE_READY
)
.
notEqualTo
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_READY
)
.
findAll
();
for
(
ServerConfig
config
:
configs
)
{
config
.
setState
(
ServerConfig
.
STATE_READY
);
...
...
@@ -64,7 +64,7 @@ public class RocketChatService extends Service {
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
List
<
ServerConfig
>
configs
=
realmHelper
.
executeTransactionForReadResults
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"state"
,
ServerConfig
.
STATE_CONNECTED
)
.
equalTo
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_CONNECTED
)
.
findAll
());
for
(
ServerConfig
config
:
configs
)
{
String
serverConfigId
=
config
.
getServerConfigId
();
...
...
@@ -80,11 +80,11 @@ public class RocketChatService extends Service {
RealmResults
<
ServerConfig
>
targetConfigs
=
realm
.
where
(
ServerConfig
.
class
)
.
beginGroup
()
.
equalTo
(
"state"
,
ServerConfig
.
STATE_CONNECTION_ERROR
)
.
equalTo
(
ServerConfig
.
STATE
,
ServerConfig
.
STATE_CONNECTION_ERROR
)
.
or
()
.
isNotNull
(
"error"
)
.
isNotNull
(
ServerConfig
.
ERROR
)
.
endGroup
()
.
isNotNull
(
"session"
)
.
isNotNull
(
ServerConfig
.
SESSION
)
.
findAll
();
for
(
ServerConfig
config
:
targetConfigs
)
{
config
.
setState
(
ServerConfig
.
STATE_READY
);
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
6ccb8ad4
...
...
@@ -144,7 +144,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
if
(
ddpClient
==
null
||
!
ddpClient
.
isConnected
())
{
defaultRealm
.
executeTransaction
(
realm
->
{
ServerConfig
config
=
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"serverConfigId"
,
serverConfigId
)
.
equalTo
(
ServerConfig
.
ID
,
serverConfigId
)
.
findFirst
();
if
(
config
!=
null
&&
config
.
getState
()
==
ServerConfig
.
STATE_CONNECTED
)
{
config
.
setState
(
ServerConfig
.
STATE_READY
);
...
...
@@ -164,7 +164,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
@DebugLog
private
Task
<
Void
>
connect
()
{
final
ServerConfig
config
=
defaultRealm
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
());
prepareWebSocket
(
config
.
getHostname
());
return
ddpClient
.
connect
(
config
.
getSession
()).
onSuccessTask
(
task
->
{
...
...
@@ -232,7 +232,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
listenersRegistered
=
true
;
final
ServerConfig
config
=
defaultRealm
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
ID
,
serverConfigId
).
findFirst
());
final
String
hostname
=
config
.
getHostname
();
for
(
Class
clazz
:
REGISTERABLE_CLASSES
)
{
...
...
app/src/main/java/chat/rocket/android/service/notification/NotificationDismissalCallbackService.java
View file @
6ccb8ad4
...
...
@@ -31,7 +31,7 @@ public class NotificationDismissalCallbackService extends IntentService {
realmHelper
.
executeTransaction
(
realm
->
{
NotificationItem
item
=
realm
.
where
(
NotificationItem
.
class
).
equalTo
(
"roomId"
,
roomId
).
findFirst
();
realm
.
where
(
NotificationItem
.
class
).
equalTo
(
NotificationItem
.
ID
,
roomId
).
findFirst
();
if
(
item
!=
null
)
{
long
currentTime
=
System
.
currentTimeMillis
();
if
(
item
.
getLastSeenAt
()
<=
currentTime
)
{
...
...
app/src/main/java/chat/rocket/android/service/observer/FileUploadingToS3Observer.java
View file @
6ccb8ad4
...
...
@@ -42,8 +42,8 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
RealmResults
<
FileUploading
>
pendingUploadRequests
=
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
)
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_S3
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
findAll
();
for
(
FileUploading
req
:
pendingUploadRequests
)
{
req
.
setSyncState
(
SyncState
.
NOT_SYNCED
);
...
...
@@ -52,11 +52,11 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
// clean up records.
realm
.
where
(
FileUploading
.
class
)
.
beginGroup
()
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
or
()
.
equalTo
(
"syncstate"
,
SyncState
.
FAILED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
endGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_S3
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
findAll
().
deleteAllFromRealm
();
return
null
;
}).
continueWith
(
new
LogcatIfError
());
...
...
@@ -65,8 +65,8 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
@Override
public
RealmResults
<
FileUploading
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_S3
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_S3
)
.
findAll
();
}
...
...
@@ -77,7 +77,8 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
}
List
<
FileUploading
>
uploadingList
=
realmHelper
.
executeTransactionForReadResults
(
realm
->
realm
.
where
(
FileUploading
.
class
).
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
).
findAll
());
realm
.
where
(
FileUploading
.
class
).
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
findAll
());
if
(
uploadingList
.
size
()
>=
3
)
{
// do not upload more than 3 files simultaneously
return
;
...
...
@@ -93,8 +94,8 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
)
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
)
).
onSuccessTask
(
_task
->
methodCall
.
uploadRequest
(
filename
,
filesize
,
mimeType
,
roomId
)
).
onSuccessTask
(
task
->
{
...
...
@@ -134,8 +135,8 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
numBytes
+=
readBytes
;
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"uploadedSize"
,
numBytes
)))
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
UPLOADED_SIZE
,
numBytes
)))
.
continueWith
(
new
LogcatIfError
());
}
}
...
...
@@ -164,18 +165,18 @@ public class FileUploadingToS3Observer extends AbstractModelObserver<FileUploadi
);
}).
onSuccessTask
(
task
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
)
.
put
(
"error"
,
JSONObject
.
NULL
)
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
put
(
FileUploading
.
ERROR
,
JSONObject
.
NULL
)
)
)).
continueWithTask
(
task
->
{
if
(
task
.
isFaulted
())
{
RCLog
.
w
(
task
.
getError
());
return
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
FAILED
)
.
put
(
"error"
,
task
.
getError
().
getMessage
())
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
put
(
FileUploading
.
ERROR
,
task
.
getError
().
getMessage
())
));
}
else
{
return
Task
.
forResult
(
null
);
...
...
app/src/main/java/chat/rocket/android/service/observer/FileUploadingWithUfsObserver.java
View file @
6ccb8ad4
...
...
@@ -38,11 +38,11 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
RealmResults
<
FileUploading
>
pendingUploadRequests
=
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
beginGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
or
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
endGroup
()
.
findAll
();
for
(
FileUploading
req
:
pendingUploadRequests
)
{
...
...
@@ -52,14 +52,14 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
// clean up records.
realm
.
where
(
FileUploading
.
class
)
.
beginGroup
()
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
or
()
.
equalTo
(
"syncstate"
,
SyncState
.
FAILED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
endGroup
()
.
beginGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
or
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
endGroup
()
.
findAll
().
deleteAllFromRealm
();
return
null
;
...
...
@@ -69,11 +69,11 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
@Override
public
RealmResults
<
FileUploading
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
FileUploading
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
beginGroup
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_GRID_FS
)
.
or
()
.
equalTo
(
"storageType"
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
equalTo
(
FileUploading
.
STORAGE_TYPE
,
FileUploading
.
STORAGE_TYPE_FILE_SYSTEM
)
.
endGroup
()
.
findAll
();
}
...
...
@@ -85,7 +85,8 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
}
List
<
FileUploading
>
uploadingList
=
realmHelper
.
executeTransactionForReadResults
(
realm
->
realm
.
where
(
FileUploading
.
class
).
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
).
findAll
());
realm
.
where
(
FileUploading
.
class
).
equalTo
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
findAll
());
if
(
uploadingList
.
size
()
>=
1
)
{
// do not upload multiple files simultaneously
return
;
...
...
@@ -115,8 +116,8 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
)
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCING
)
)
).
onSuccessTask
(
_task
->
methodCall
.
ufsCreate
(
filename
,
filesize
,
mimeType
,
store
,
roomId
)
).
onSuccessTask
(
task
->
{
...
...
@@ -145,8 +146,8 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
Response
response
=
OkHttpHelper
.
getClientForUploadFile
().
newCall
(
request
).
execute
();
if
(
response
.
isSuccessful
())
{
final
JSONObject
obj
=
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"uploadedSize"
,
offset
);
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
UPLOADED_SIZE
,
offset
);
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
obj
));
}
else
{
...
...
@@ -159,18 +160,18 @@ public class FileUploadingWithUfsObserver extends AbstractModelObserver<FileUplo
}).
onSuccessTask
(
task
->
methodCall
.
sendFileMessage
(
roomId
,
null
,
task
.
getResult
())
).
onSuccessTask
(
task
->
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
)
.
put
(
"error"
,
JSONObject
.
NULL
)
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
put
(
FileUploading
.
ERROR
,
JSONObject
.
NULL
)
)
)).
continueWithTask
(
task
->
{
if
(
task
.
isFaulted
())
{
RCLog
.
w
(
task
.
getError
());
return
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
FileUploading
.
class
,
new
JSONObject
()
.
put
(
"uplId"
,
uplId
)
.
put
(
"syncstate"
,
SyncState
.
FAILED
)
.
put
(
"error"
,
task
.
getError
().
getMessage
())
.
put
(
FileUploading
.
ID
,
uplId
)
.
put
(
FileUploading
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
put
(
FileUploading
.
ERROR
,
task
.
getError
().
getMessage
())
));
}
else
{
return
Task
.
forResult
(
null
);
...
...
app/src/main/java/chat/rocket/android/service/observer/GetUsersOfRoomsProcedureObserver.java
View file @
6ccb8ad4
...
...
@@ -31,7 +31,7 @@ public class GetUsersOfRoomsProcedureObserver
@Override
public
RealmResults
<
GetUsersOfRoomsProcedure
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
GetUsersOfRoomsProcedure
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
equalTo
(
GetUsersOfRoomsProcedure
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
findAll
();
}
...
...
@@ -47,8 +47,8 @@ public class GetUsersOfRoomsProcedureObserver
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
GetUsersOfRoomsProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
))
.
put
(
GetUsersOfRoomsProcedure
.
ID
,
roomId
)
.
put
(
GetUsersOfRoomsProcedure
.
SYNC_STATE
,
SyncState
.
SYNCING
))
).
onSuccessTask
(
task
->
methodCall
.
getUsersOfRoom
(
roomId
,
showAll
)
.
onSuccessTask
(
_task
->
{
...
...
@@ -64,8 +64,8 @@ public class GetUsersOfRoomsProcedureObserver
RCLog
.
w
(
task
.
getError
());
return
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
GetUsersOfRoomsProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
FAILED
)));
.
put
(
GetUsersOfRoomsProcedure
.
ID
,
roomId
)
.
put
(
GetUsersOfRoomsProcedure
.
SYNC_STATE
,
SyncState
.
FAILED
)));
}
else
{
return
Task
.
forResult
(
null
);
}
...
...
app/src/main/java/chat/rocket/android/service/observer/LoadMessageProcedureObserver.java
View file @
6ccb8ad4
...
...
@@ -32,7 +32,7 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
@Override
public
RealmResults
<
LoadMessageProcedure
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
LoadMessageProcedure
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
equalTo
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
findAll
();
}
...
...
@@ -51,33 +51,33 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
LoadMessageProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
))
.
put
(
LoadMessageProcedure
.
ID
,
roomId
)
.
put
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
SYNCING
))
).
onSuccessTask
(
task
->
methodCall
.
loadHistory
(
roomId
,
isReset
?
0
:
timestamp
,
count
,
lastSeen
)
.
onSuccessTask
(
_task
->
{
Message
lastMessage
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
Message
.
class
)
.
equalTo
(
"rid"
,
roomId
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
findAllSorted
(
"ts"
,
Sort
.
ASCENDING
).
first
(
null
));
.
equalTo
(
Message
.
ROOM_ID
,
roomId
)
.
equalTo
(
Message
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
findAllSorted
(
Message
.
TIMESTAMP
,
Sort
.
ASCENDING
).
first
(
null
));
long
lastTs
=
lastMessage
!=
null
?
lastMessage
.
getTimestamp
()
:
0
;
int
messageCount
=
_task
.
getResult
().
length
();
return
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
LoadMessageProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
)
.
put
(
"timestamp"
,
lastTs
)
.
put
(
"reset"
,
false
)
.
put
(
"hasNext"
,
messageCount
==
count
)));
.
put
(
LoadMessageProcedure
.
ID
,
roomId
)
.
put
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
put
(
LoadMessageProcedure
.
TIMESTAMP
,
lastTs
)
.
put
(
LoadMessageProcedure
.
RESET
,
false
)
.
put
(
LoadMessageProcedure
.
HAS_NEXT
,
messageCount
==
count
)));
})
).
continueWithTask
(
task
->
{
if
(
task
.
isFaulted
())
{
RCLog
.
w
(
task
.
getError
());
return
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
LoadMessageProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
FAILED
)));
.
put
(
LoadMessageProcedure
.
ID
,
roomId
)
.
put
(
LoadMessageProcedure
.
SYNC_STATE
,
SyncState
.
FAILED
)));
}
else
{
return
Task
.
forResult
(
null
);
}
...
...
app/src/main/java/chat/rocket/android/service/observer/MethodCallObserver.java
View file @
6ccb8ad4
...
...
@@ -30,7 +30,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
RealmResults
<
MethodCall
>
pendingMethodCalls
=
realm
.
where
(
MethodCall
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
)
.
equalTo
(
MethodCall
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
findAll
();
for
(
MethodCall
call
:
pendingMethodCalls
)
{
call
.
setSyncState
(
SyncState
.
NOT_SYNCED
);
...
...
@@ -39,9 +39,9 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
// clean up records.
realm
.
where
(
MethodCall
.
class
)
.
beginGroup
()
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
equalTo
(
MethodCall
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
or
()
.
equalTo
(
"syncstate"
,
SyncState
.
FAILED
)
.
equalTo
(
MethodCall
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
endGroup
()
.
findAll
().
deleteAllFromRealm
();
return
null
;
...
...
@@ -51,8 +51,8 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
@Override
public
RealmResults
<
MethodCall
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
MethodCall
.
class
)
.
isNotNull
(
"name"
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
isNotNull
(
MethodCall
.
NAME
)
.
equalTo
(
MethodCall
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
findAll
();
}
...
...
@@ -94,16 +94,16 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
final
long
timeout
=
call
.
getTimeout
();
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
MethodCall
.
class
,
new
JSONObject
()
.
put
(
"methodCallId"
,
methodCallId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
))
.
put
(
MethodCall
.
ID
,
methodCallId
)
.
put
(
MethodCall
.
SYNC_STATE
,
SyncState
.
SYNCING
))
).
onSuccessTask
(
task
->
ddpClient
.
rpc
(
methodCallId
,
methodName
,
params
,
timeout
)
.
onSuccessTask
(
_task
->
realmHelper
.
executeTransaction
(
realm
->
{
String
json
=
_task
.
getResult
().
result
;
return
realm
.
createOrUpdateObjectFromJson
(
MethodCall
.
class
,
new
JSONObject
()
.
put
(
"methodCallId"
,
methodCallId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
)
.
put
(
"resultJson"
,
json
));
.
put
(
MethodCall
.
ID
,
methodCallId
)
.
put
(
MethodCall
.
SYNC_STATE
,
SyncState
.
SYNCED
)
.
put
(
MethodCall
.
RESULT_JSON
,
json
));
}))
).
continueWithTask
(
task
->
{
if
(
task
.
isFaulted
())
{
...
...
@@ -113,9 +113,9 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
?
((
DDPClientCallback
.
RPC
.
Error
)
exception
).
error
.
toString
()
:
exception
.
getMessage
();
realm
.
createOrUpdateObjectFromJson
(
MethodCall
.
class
,
new
JSONObject
()
.
put
(
"methodCallId"
,
methodCallId
)
.
put
(
"syncstate"
,
SyncState
.
FAILED
)
.
put
(
"resultJson"
,
errMessage
));
.
put
(
MethodCall
.
ID
,
methodCallId
)
.
put
(
MethodCall
.
SYNC_STATE
,
SyncState
.
FAILED
)
.
put
(
MethodCall
.
RESULT_JSON
,
errMessage
));
return
null
;
});
}
...
...
app/src/main/java/chat/rocket/android/service/observer/NewMessageObserver.java
View file @
6ccb8ad4
...
...
@@ -29,7 +29,7 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
RealmResults
<
Message
>
pendingMethodCalls
=
realm
.
where
(
Message
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCING
)
.
equalTo
(
Message
.
SYNC_STATE
,
SyncState
.
SYNCING
)
.
findAll
();
for
(
Message
message
:
pendingMethodCalls
)
{
message
.
setSyncState
(
SyncState
.
NOT_SYNCED
);
...
...
@@ -42,8 +42,8 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
@Override
public
RealmResults
<
Message
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
Message
.
class
)
.
equalTo
(
"syncstate"
,
SyncState
.
NOT_SYNCED
)
.
isNotNull
(
"rid"
)
.
equalTo
(
Message
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
isNotNull
(
Message
.
ROOM_ID
)
.
findAll
();
}
...
...
@@ -60,8 +60,8 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
"_id"
,
messageId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
)
.
put
(
Message
.
ID
,
messageId
)
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
SYNCING
)
)
).
onSuccessTask
(
task
->
methodCall
.
sendMessage
(
messageId
,
roomId
,
msg
).
onSuccessTask
(
_task
->
{
...
...
@@ -75,8 +75,8 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
RCLog
.
w
(
task
.
getError
());
realmHelper
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
Message
.
class
,
new
JSONObject
()
.
put
(
"_id"
,
messageId
)
.
put
(
"syncstate"
,
SyncState
.
FAILED
)));
.
put
(
Message
.
ID
,
messageId
)
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
FAILED
)));
}
return
null
;
});
...
...
app/src/main/java/chat/rocket/android/service/observer/NotificationItemObserver.java
View file @
6ccb8ad4
...
...
@@ -91,7 +91,7 @@ public class NotificationItemObserver extends AbstractModelObserver<Notification
Intent
intent
=
new
Intent
(
context
,
MainActivity
.
class
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
|
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
);
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"hostname"
,
hostname
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
HOSTNAME
,
hostname
).
findFirst
());
if
(
config
!=
null
)
{
intent
.
putExtra
(
"serverConfigId"
,
config
.
getServerConfigId
());
intent
.
putExtra
(
"roomId"
,
roomId
);
...
...
@@ -105,7 +105,7 @@ public class NotificationItemObserver extends AbstractModelObserver<Notification
private
PendingIntent
getDeleteIntent
(
String
roomId
)
{
Intent
intent
=
new
Intent
(
context
,
NotificationDismissalCallbackService
.
class
);
ServerConfig
config
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"hostname"
,
hostname
).
findFirst
());
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
HOSTNAME
,
hostname
).
findFirst
());
if
(
config
!=
null
)
{
intent
.
putExtra
(
"serverConfigId"
,
config
.
getServerConfigId
());
intent
.
putExtra
(
"roomId"
,
roomId
);
...
...
app/src/main/java/chat/rocket/android/service/observer/ReactiveNotificationManager.java
View file @
6ccb8ad4
...
...
@@ -27,7 +27,7 @@ public class ReactiveNotificationManager extends AbstractModelObserver<RoomSubsc
@Override
public
RealmResults
<
RoomSubscription
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
RoomSubscription
.
class
)
.
equalTo
(
"open"
,
true
)
.
equalTo
(
RoomSubscription
.
OPEN
,
true
)
.
findAll
();
}
...
...
@@ -37,9 +37,10 @@ public class ReactiveNotificationManager extends AbstractModelObserver<RoomSubsc
for
(
RoomSubscription
roomSubscription
:
roomSubscriptions
)
{
final
String
roomId
=
roomSubscription
.
getRoomId
();
NotificationItem
item
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
NotificationItem
.
class
).
equalTo
(
"roomId"
,
roomId
).
findFirst
());
realm
.
where
(
NotificationItem
.
class
).
equalTo
(
NotificationItem
.
ID
,
roomId
).
findFirst
());
long
lastSeenAt
=
Math
.
max
(
item
!=
null
?
item
.
getLastSeenAt
()
:
0
,
roomSubscription
.
getLastSeen
());
long
lastSeenAt
=
Math
.
max
(
item
!=
null
?
item
.
getLastSeenAt
()
:
0
,
roomSubscription
.
getLastSeen
());
try
{
JSONObject
notification
=
new
JSONObject
()
.
put
(
"roomId"
,
roomSubscription
.
getRoomId
())
...
...
app/src/main/java/chat/rocket/android/service/observer/SessionObserver.java
View file @
6ccb8ad4
...
...
@@ -38,9 +38,9 @@ public class SessionObserver extends AbstractModelObserver<Session> {
@Override
public
RealmResults
<
Session
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
Session
.
class
)
.
isNotNull
(
"token"
)
.
equalTo
(
"tokenVerified"
,
true
)
.
isNull
(
"error"
)
.
isNotNull
(
Session
.
TOKEN
)
.
equalTo
(
Session
.
TOKEN_VERIFIED
,
true
)
.
isNull
(
Session
.
ERROR
)
.
findAll
();
}
...
...
app/src/main/java/chat/rocket/android/service/observer/TokenLoginObserver.java
View file @
6ccb8ad4
...
...
@@ -24,9 +24,9 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
@Override
public
RealmResults
<
Session
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
Session
.
class
)
.
isNotNull
(
"token"
)
.
equalTo
(
"tokenVerified"
,
false
)
.
isNull
(
"error"
)
.
isNotNull
(
Session
.
TOKEN
)
.
equalTo
(
Session
.
TOKEN_VERIFIED
,
false
)
.
isNull
(
Session
.
ERROR
)
.
findAll
();
}
...
...
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