2929
3030public class StorageClient {
3131 private static LCLogger LOGGER = LogUtil .getLogger (StorageClient .class );
32+ private static final String CUSTOM_ENDPOINT_PREFIX = "CUSTOM_ENDPOINT_" ;
3233
3334 private APIService apiService = null ;
3435 private boolean asynchronized = false ;
@@ -127,9 +128,15 @@ private Observable<LCQueryResult> queryRemoteServer(final LCUser authenticatedUs
127128 String authenticatedSession = getSessionToken (authenticatedUser );
128129 if (LCUser .CLASS_NAME .equalsIgnoreCase (className )) {
129130 return wrapObservable (apiService .queryUsers (authenticatedSession , query ));
130- } else {
131+ }else if (LCBlockRelation .CLASS_NAME .equalsIgnoreCase (className )){
132+ return wrapObservable (apiService .getBlockListOfFriend (authenticatedSession , query ));
133+ } else if (className .startsWith (CUSTOM_ENDPOINT_PREFIX )){
134+ String endPoint = className .substring (CUSTOM_ENDPOINT_PREFIX .length ());
135+ return wrapObservable (apiService .queryObjectsByCustomEndPoint (authenticatedSession , endPoint , query ));
136+ } else {
131137 return wrapObservable (apiService .queryObjects (authenticatedSession , className , query ));
132138 }
139+
133140 }
134141
135142 public Observable <List <LCUser >> strictlyQueryUsers (final LCUser authenticatedUser ,
@@ -161,11 +168,14 @@ public List<LCUser> apply(List<LCObject> var1) throws Exception {
161168
162169
163170 public Observable <List <LCObject >> queryObjects (final LCUser authenticatedUser ,
164- final String className , final Map <String , String > query ,
171+ final String className , final String endPoint , final Map <String , String > query ,
165172 LCQuery .CachePolicy cachePolicy , final long maxAgeInMilliseconds ) {
166173 final String cacheKey = QueryResultCache .generateKeyForQueryCondition (className , query );
167174 Observable <List <LCObject >> result = null ;
168175 Observable <LCQueryResult > queryResult = null ;
176+ //check whether use endPoint
177+ final String validPath = (endPoint == null || endPoint .length () == 0 ) ? className : (CUSTOM_ENDPOINT_PREFIX +endPoint );
178+
169179 switch (cachePolicy ) {
170180 case CACHE_ONLY :
171181 result = wrapObservable (
@@ -178,8 +188,7 @@ public Observable<List<LCObject>> queryObjects(final LCUser authenticatedUser,
178188 @ Override
179189 public ObservableSource <? extends List <LCObject >> apply (Throwable throwable ) throws Exception {
180190 LOGGER .d ("failed to query local cache, cause: " + throwable .getMessage () + ", try to query networking" );
181-
182- return queryRemoteServer (authenticatedUser , className , query )
191+ return queryRemoteServer (authenticatedUser , validPath , query )
183192 .map (new Function <LCQueryResult , List <LCObject >>() {
184193 public List <LCObject > apply (LCQueryResult o ) throws Exception {
185194 o .setClassName (className );
@@ -196,7 +205,7 @@ public List<LCObject> apply(LCQueryResult o) throws Exception {
196205 });
197206 break ;
198207 case NETWORK_ELSE_CACHE :
199- queryResult = queryRemoteServer (authenticatedUser , className , query );
208+ queryResult = queryRemoteServer (authenticatedUser , validPath , query );
200209 if (null != queryResult ) {
201210 result = queryResult .map (new Function <LCQueryResult , List <LCObject >>() {
202211 public List <LCObject > apply (LCQueryResult o ) throws Exception {
@@ -221,7 +230,7 @@ public ObservableSource<? extends List<LCObject>> apply(Throwable throwable) thr
221230 break ;
222231 case IGNORE_CACHE :
223232 default :
224- queryResult = queryRemoteServer (authenticatedUser , className , query );
233+ queryResult = queryRemoteServer (authenticatedUser , validPath , query );
225234 if (null != queryResult ) {
226235 result = queryResult .map (new Function <LCQueryResult , List <LCObject >>() {
227236 public List <LCObject > apply (LCQueryResult o ) throws Exception {
@@ -616,7 +625,7 @@ public Observable<JSONObject> getFollowersAndFollowees(final LCUser authenticate
616625 public Observable <List <LCFriendship >> queryFriendship (final LCUser authenticatedUser , Map <String , String > conditions ) {
617626 String authenticatedSession = getSessionToken (authenticatedUser );
618627 return wrapObservable (
619- apiService .getFollowees (authenticatedSession , authenticatedUser . getObjectId () , conditions )
628+ apiService .getFriends (authenticatedSession , conditions )
620629 .map (new Function <LCQueryResult , List <LCFriendship >>() {
621630 @ Override
622631 public List <LCFriendship > apply (LCQueryResult result ) throws Exception {
@@ -633,6 +642,16 @@ public List<LCFriendship> apply(LCQueryResult result) throws Exception {
633642 }));
634643 }
635644
645+ public Observable <JSONObject > blockFriend (final LCUser authenticatedUser , String objectId ) {
646+ String authenticatedSession = getSessionToken (authenticatedUser );
647+ return wrapObservable (apiService .blockFriendByObjectId (authenticatedSession , objectId ));
648+ }
649+
650+ public Observable <JSONObject > unblockFriend (final LCUser authenticatedUser , String objectId ) {
651+ String authenticatedSession = getSessionToken (authenticatedUser );
652+ return wrapObservable (apiService .unblockFriendByObjectId (authenticatedSession , objectId ));
653+ }
654+
636655 public Observable <LCStatus > postStatus (final LCUser authenticatedUser , Map <String , Object > param ) {
637656 String authenticatedSession = getSessionToken (authenticatedUser );
638657 return wrapObservable (apiService .postStatus (authenticatedSession , param ));
0 commit comments