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
00f44484
Commit
00f44484
authored
Nov 19, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename RocketChatWebSocketAPI to DDPClientWrapper
parent
ab6c9b04
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
55 additions
and
55 deletions
+55
-55
DDPClientWraper.java
...rc/main/java/chat/rocket/android/api/DDPClientWraper.java
+5
-5
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+6
-6
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+11
-11
AbstractDDPDocEventSubscriber.java
...et/android/service/ddp/AbstractDDPDocEventSubscriber.java
+7
-7
ActiveUsersSubscriber.java
...hat/rocket/android/service/ddp/ActiveUsersSubscriber.java
+3
-3
LoginServiceConfigurationSubscriber.java
...roid/service/ddp/LoginServiceConfigurationSubscriber.java
+3
-3
AbstractModelObserver.java
...ocket/android/service/observer/AbstractModelObserver.java
+4
-4
LoadMessageProcedureObserver.java
...ndroid/service/observer/LoadMessageProcedureObserver.java
+4
-4
MethodCallObserver.java
...t/rocket/android/service/observer/MethodCallObserver.java
+4
-4
SessionObserver.java
...chat/rocket/android/service/observer/SessionObserver.java
+4
-4
TokenLoginObserver.java
...t/rocket/android/service/observer/TokenLoginObserver.java
+4
-4
No files found.
app/src/main/java/chat/rocket/android/api/
RocketChatWebSocketAPI
.java
→
app/src/main/java/chat/rocket/android/api/
DDPClientWraper
.java
View file @
00f44484
...
...
@@ -13,13 +13,13 @@ import org.json.JSONException;
import
rx.Observable
;
/**
*
API for several POST actions
.
*
DDP client wrapper
.
*/
public
class
RocketChatWebSocketAPI
{
public
class
DDPClientWraper
{
private
final
DDPClient
ddpClient
;
private
final
String
hostname
;
private
RocketChatWebSocketAPI
(
String
hostname
)
{
private
DDPClientWraper
(
String
hostname
)
{
ddpClient
=
new
DDPClient
(
OkHttpHelper
.
getClientForWebSocket
());
this
.
hostname
=
hostname
;
}
...
...
@@ -27,8 +27,8 @@ public class RocketChatWebSocketAPI {
/**
* create new API client instance.
*/
public
static
RocketChatWebSocketAPI
create
(
String
hostname
)
{
return
new
RocketChatWebSocketAPI
(
hostname
);
public
static
DDPClientWraper
create
(
String
hostname
)
{
return
new
DDPClientWraper
(
hostname
);
}
/**
...
...
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
00f44484
...
...
@@ -24,23 +24,23 @@ import org.json.JSONObject;
public
class
MethodCallHelper
{
private
final
RealmHelper
realmHelper
;
private
final
RocketChatWebSocketAPI
api
;
private
final
DDPClientWraper
ddpClient
;
private
static
final
long
TIMEOUT_MS
=
4000
;
public
MethodCallHelper
(
String
serverConfigId
)
{
this
.
realmHelper
=
RealmStore
.
get
(
serverConfigId
);
api
=
null
;
ddpClient
=
null
;
}
public
MethodCallHelper
(
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
public
MethodCallHelper
(
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
realmHelper
=
realmHelper
;
this
.
api
=
api
;
this
.
ddpClient
=
ddpClient
;
}
@DebugLog
private
Task
<
String
>
executeMethodCall
(
String
methodName
,
String
param
,
long
timeout
)
{
if
(
api
!=
null
)
{
return
api
.
rpc
(
UUID
.
randomUUID
().
toString
(),
methodName
,
param
,
timeout
)
if
(
ddpClient
!=
null
)
{
return
ddpClient
.
rpc
(
UUID
.
randomUUID
().
toString
(),
methodName
,
param
,
timeout
)
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
result
));
}
else
{
return
MethodCall
.
execute
(
realmHelper
,
methodName
,
param
,
timeout
);
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
00f44484
...
...
@@ -18,7 +18,7 @@ import chat.rocket.android.service.observer.LoadMessageProcedureObserver;
import
chat.rocket.android.service.observer.MethodCallObserver
;
import
chat.rocket.android.service.observer.SessionObserver
;
import
chat.rocket.android.service.observer.TokenLoginObserver
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
chat.rocket.android_ddp.DDPClientCallback
;
import
hugo.weaving.DebugLog
;
import
java.lang.reflect.Constructor
;
...
...
@@ -44,7 +44,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
final
RealmHelper
defaultRealm
;
private
final
RealmHelper
serverConfigRealm
;
private
final
ArrayList
<
Registerable
>
listeners
=
new
ArrayList
<>();
private
RocketChatWebSocketAPI
webSocketAPI
;
private
DDPClientWraper
ddpClient
;
private
boolean
socketExists
;
private
boolean
listenersRegistered
;
...
...
@@ -117,7 +117,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
private
Task
<
Void
>
ensureConnection
()
{
if
(
webSocketAPI
==
null
||
!
webSocketAPI
.
isConnected
())
{
if
(
ddpClient
==
null
||
!
ddpClient
.
isConnected
())
{
return
connect
();
}
else
{
return
Task
.
forResult
(
null
);
...
...
@@ -135,8 +135,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
private
void
prepareWebSocket
(
String
hostname
)
{
if
(
webSocketAPI
==
null
||
!
webSocketAPI
.
isConnected
())
{
webSocketAPI
=
RocketChatWebSocketAPI
.
create
(
hostname
);
if
(
ddpClient
==
null
||
!
ddpClient
.
isConnected
())
{
ddpClient
=
DDPClientWraper
.
create
(
hostname
);
}
}
...
...
@@ -150,7 +150,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
prepareWebSocket
(
config
.
getHostname
());
return
webSocketAPI
.
connect
(
config
.
getSession
()).
onSuccessTask
(
task
->
{
return
ddpClient
.
connect
(
config
.
getSession
()).
onSuccessTask
(
task
->
{
final
String
session
=
task
.
getResult
().
session
;
defaultRealm
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
()
...
...
@@ -213,8 +213,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
for
(
Class
clazz
:
REGISTERABLE_CLASSES
)
{
try
{
Constructor
ctor
=
clazz
.
getConstructor
(
Context
.
class
,
RealmHelper
.
class
,
RocketChatWebSocketAPI
.
class
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
serverConfigRealm
,
webSocketAPI
);
DDPClientWraper
.
class
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
serverConfigRealm
,
ddpClient
);
if
(
obj
instanceof
Registerable
)
{
Registerable
registerable
=
(
Registerable
)
obj
;
...
...
@@ -250,9 +250,9 @@ public class RocketChatWebSocketThread extends HandlerThread {
registerable
.
unregister
();
iterator
.
remove
();
}
if
(
webSocketAPI
!=
null
)
{
webSocketAPI
.
close
();
webSocketAPI
=
null
;
if
(
ddpClient
!=
null
)
{
ddpClient
.
close
();
ddpClient
=
null
;
}
listenersRegistered
=
false
;
socketExists
=
false
;
...
...
app/src/main/java/chat/rocket/android/service/ddp/AbstractDDPDocEventSubscriber.java
View file @
00f44484
...
...
@@ -5,7 +5,7 @@ import android.text.TextUtils;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.service.Registerable
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
chat.rocket.android_ddp.DDPSubscription
;
import
io.realm.Realm
;
import
io.realm.RealmObject
;
...
...
@@ -18,15 +18,15 @@ import timber.log.Timber;
abstract
class
AbstractDDPDocEventSubscriber
implements
Registerable
{
protected
final
Context
context
;
protected
final
RealmHelper
realmHelper
;
protected
final
RocketChatWebSocketAPI
webSocketAPI
;
protected
final
DDPClientWraper
ddpClient
;
private
String
subscriptionId
;
private
Subscription
rxSubscription
;
protected
AbstractDDPDocEventSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
realmHelper
=
realmHelper
;
this
.
webSocketAPI
=
api
;
this
.
ddpClient
=
ddpClient
;
}
protected
abstract
String
getSubscriptionName
();
...
...
@@ -40,7 +40,7 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
@Override
public
void
register
()
{
webSocketAPI
.
subscribe
(
getSubscriptionName
(),
null
).
onSuccess
(
task
->
{
ddpClient
.
subscribe
(
getSubscriptionName
(),
null
).
onSuccess
(
task
->
{
subscriptionId
=
task
.
getResult
().
id
;
return
null
;
}).
continueWith
(
task
->
{
...
...
@@ -60,7 +60,7 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
private
void
registerSubscriptionCallback
()
{
rxSubscription
=
webSocketAPI
.
getSubscriptionCallback
()
rxSubscription
=
ddpClient
.
getSubscriptionCallback
()
.
filter
(
event
->
event
instanceof
DDPSubscription
.
DocEvent
)
.
cast
(
DDPSubscription
.
DocEvent
.
class
)
.
filter
(
event
->
getSubscriptionCallbackName
().
equals
(
event
.
collection
))
...
...
@@ -146,7 +146,7 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
rxSubscription
.
unsubscribe
();
}
if
(!
TextUtils
.
isEmpty
(
subscriptionId
))
{
webSocketAPI
.
unsubscribe
(
subscriptionId
).
continueWith
(
new
LogcatIfError
());
ddpClient
.
unsubscribe
(
subscriptionId
).
continueWith
(
new
LogcatIfError
());
}
}
}
app/src/main/java/chat/rocket/android/service/ddp/ActiveUsersSubscriber.java
View file @
00f44484
...
...
@@ -3,7 +3,7 @@ package chat.rocket.android.service.ddp;
import
android.content.Context
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
io.realm.RealmObject
;
/**
...
...
@@ -11,8 +11,8 @@ import io.realm.RealmObject;
*/
public
class
ActiveUsersSubscriber
extends
AbstractDDPDocEventSubscriber
{
public
ActiveUsersSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
super
(
context
,
realmHelper
,
api
);
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
}
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/LoginServiceConfigurationSubscriber.java
View file @
00f44484
...
...
@@ -3,7 +3,7 @@ package chat.rocket.android.service.ddp;
import
android.content.Context
;
import
chat.rocket.android.model.ddp.MeteorLoginServiceConfiguration
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
io.realm.RealmObject
;
/**
...
...
@@ -11,8 +11,8 @@ import io.realm.RealmObject;
*/
public
class
LoginServiceConfigurationSubscriber
extends
AbstractDDPDocEventSubscriber
{
public
LoginServiceConfigurationSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
super
(
context
,
realmHelper
,
api
);
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
}
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/observer/AbstractModelObserver.java
View file @
00f44484
...
...
@@ -4,7 +4,7 @@ import android.content.Context;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmListObserver
;
import
chat.rocket.android.service.Registerable
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
io.realm.RealmObject
;
abstract
class
AbstractModelObserver
<
T
extends
RealmObject
>
...
...
@@ -12,14 +12,14 @@ abstract class AbstractModelObserver<T extends RealmObject>
protected
final
Context
context
;
protected
final
RealmHelper
realmHelper
;
protected
final
RocketChatWebSocketAPI
webSocketAPI
;
protected
final
DDPClientWraper
ddpClient
;
private
final
RealmListObserver
observer
;
protected
AbstractModelObserver
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
realmHelper
=
realmHelper
;
webSocketAPI
=
api
;
this
.
ddpClient
=
ddpClient
;
observer
=
realmHelper
.
createListObserver
(
this
).
setOnUpdateListener
(
this
);
}
...
...
app/src/main/java/chat/rocket/android/service/observer/LoadMessageProcedureObserver.java
View file @
00f44484
...
...
@@ -7,7 +7,7 @@ import chat.rocket.android.model.internal.LoadMessageProcedure;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
io.realm.Sort
;
...
...
@@ -23,9 +23,9 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
private
final
MethodCallHelper
methodCall
;
public
LoadMessageProcedureObserver
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
super
(
context
,
realmHelper
,
api
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
api
);
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
@Override
public
RealmResults
<
LoadMessageProcedure
>
queryItems
(
Realm
realm
)
{
...
...
app/src/main/java/chat/rocket/android/service/observer/MethodCallObserver.java
View file @
00f44484
...
...
@@ -6,7 +6,7 @@ import chat.rocket.android.helper.LogcatIfError;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.internal.MethodCall
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
chat.rocket.android_ddp.DDPClientCallback
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
...
...
@@ -23,8 +23,8 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
/**
* constructor.
*/
public
MethodCallObserver
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
super
(
context
,
realmHelper
,
api
);
public
MethodCallObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
RealmResults
<
MethodCall
>
pendingMethodCalls
=
realm
.
where
(
MethodCall
.
class
)
...
...
@@ -93,7 +93,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
.
put
(
"methodCallId"
,
methodCallId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCING
))
).
onSuccessTask
(
task
->
webSocketAPI
.
rpc
(
methodCallId
,
methodName
,
params
,
timeout
)
ddpClient
.
rpc
(
methodCallId
,
methodName
,
params
,
timeout
)
.
onSuccessTask
(
_task
->
realmHelper
.
executeTransaction
(
realm
->
{
String
json
=
_task
.
getResult
().
result
;
return
realm
.
createOrUpdateObjectFromJson
(
MethodCall
.
class
,
new
JSONObject
()
...
...
app/src/main/java/chat/rocket/android/service/observer/SessionObserver.java
View file @
00f44484
...
...
@@ -6,7 +6,7 @@ import chat.rocket.android.api.MethodCallHelper;
import
chat.rocket.android.model.ddp.RoomSubscription
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
...
...
@@ -22,9 +22,9 @@ public class SessionObserver extends AbstractModelObserver<Session> {
/**
* constructor.
*/
public
SessionObserver
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
super
(
context
,
realmHelper
,
api
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
api
);
public
SessionObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
count
=
0
;
}
...
...
app/src/main/java/chat/rocket/android/service/observer/TokenLoginObserver.java
View file @
00f44484
...
...
@@ -4,7 +4,7 @@ import android.content.Context;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.api.
RocketChatWebSocketAPI
;
import
chat.rocket.android.api.
DDPClientWraper
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
java.util.List
;
...
...
@@ -13,9 +13,9 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
private
final
MethodCallHelper
methodCall
;
public
TokenLoginObserver
(
Context
context
,
RealmHelper
realmHelper
,
RocketChatWebSocketAPI
api
)
{
super
(
context
,
realmHelper
,
api
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
api
);
public
TokenLoginObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
@Override
public
RealmResults
<
Session
>
queryItems
(
Realm
realm
)
{
...
...
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