3333import android .content .IntentFilter ;
3434import android .content .res .Configuration ;
3535import android .os .Bundle ;
36- import android .os .Parcelable ;
3736import android .support .annotation .NonNull ;
3837import android .support .annotation .Nullable ;
3938import android .support .v7 .app .AppCompatActivity ;
5655import com .nextcloud .talk .api .helpers .api .ApiHelper ;
5756import com .nextcloud .talk .api .models .json .call .CallOverall ;
5857import com .nextcloud .talk .api .models .json .generic .GenericOverall ;
58+ import com .nextcloud .talk .api .models .json .rooms .Room ;
59+ import com .nextcloud .talk .api .models .json .rooms .RoomsOverall ;
5960import com .nextcloud .talk .api .models .json .signaling .DataChannelMessage ;
6061import com .nextcloud .talk .api .models .json .signaling .NCIceCandidate ;
6162import com .nextcloud .talk .api .models .json .signaling .NCMessagePayload ;
@@ -221,14 +222,14 @@ protected void onCreate(Bundle savedInstanceState) {
221222 ButterKnife .bind (this );
222223
223224 roomToken = getIntent ().getExtras ().getString ("roomToken" , "" );
224- userEntity = Parcels .unwrap (( Parcelable ) getIntent ().getExtras ().get ("userEntity" ));
225+ userEntity = Parcels .unwrap (getIntent ().getExtras ().getParcelable ("userEntity" ));
225226 callSession = "0" ;
226227 credentials = ApiHelper .getCredentials (userEntity .getUsername (), userEntity .getToken ());
227228
228229 callControls .setZ (100.0f );
229230 basicInitialization ();
230231
231- if (userUtils . getCurrentUser () != null && userUtils . getCurrentUser () != userEntity ) {
232+ if (! userEntity . getCurrent () ) {
232233 userUtils .createOrUpdateUser (userEntity .getUsername (),
233234 userEntity .getToken (), userEntity .getBaseUrl (), null ,
234235 null , true )
@@ -242,8 +243,12 @@ public void onSubscribe(Disposable d) {
242243 public void onNext (UserEntity userEntity ) {
243244 cookieManager .getCookieStore ().removeAll ();
244245 userUtils .disableAllUsersWithoutId (userEntity .getId ());
245- initViews ();
246- checkPermissions ();
246+ if (getIntent ().getExtras ().containsKey ("fromNotification" )) {
247+ handleFromNotification ();
248+ } else {
249+ initViews ();
250+ checkPermissions ();
251+ }
247252 }
248253
249254 @ Override
@@ -257,13 +262,50 @@ public void onComplete() {
257262 }
258263 });
259264
265+ } else if (getIntent ().getExtras ().containsKey ("fromNotification" )) {
266+ handleFromNotification ();
260267 } else {
261268 initViews ();
262269 checkPermissions ();
263270 }
271+ }
272+
273+ private void handleFromNotification () {
274+ ncApi .getRooms (credentials , ApiHelper .getUrlForGetRooms (userEntity .getBaseUrl ()))
275+ .subscribeOn (Schedulers .newThread ())
276+ .observeOn (AndroidSchedulers .mainThread ())
277+ .subscribe (new Observer <RoomsOverall >() {
278+ @ Override
279+ public void onSubscribe (Disposable d ) {
280+
281+ }
282+
283+ @ Override
284+ public void onNext (RoomsOverall roomsOverall ) {
285+ for (Room room : roomsOverall .getOcs ().getData ()) {
286+ if (roomToken .equals (room .getRoomId ())) {
287+ roomToken = room .getToken ();
288+ break ;
289+ }
290+ }
264291
292+ initViews ();
293+ checkPermissions ();
294+ }
295+
296+ @ Override
297+ public void onError (Throwable e ) {
298+
299+ }
300+
301+ @ Override
302+ public void onComplete () {
303+
304+ }
305+ });
265306 }
266307
308+
267309 private void toggleMedia (boolean enable , boolean video ) {
268310 String message ;
269311 if (video ) {
@@ -731,6 +773,7 @@ public void onNext(SignalingOverall signalingOverall) {
731773
732774 @ Override
733775 public void onError (Throwable e ) {
776+ Log .d ("MARIO_DEBUG" , e .getLocalizedMessage ());
734777 dispose (signalingDisposable );
735778 }
736779
@@ -745,7 +788,7 @@ public void onComplete() {
745788
746789 @ Override
747790 public void onError (Throwable e ) {
748-
791+ Log . d ( "MARIO_DEBUG" , e . getLocalizedMessage ());
749792 }
750793
751794 @ Override
0 commit comments