@@ -175,7 +175,7 @@ class QiscusSDK {
175
175
Future .sync (() async {
176
176
await _authenticated;
177
177
await clearSubscription ();
178
- await __< Storage > ().clear ();
178
+ __< Storage > ().clear ();
179
179
await __< IRealtimeService > ().end ();
180
180
}).toCallback1 (callback);
181
181
}
@@ -691,30 +691,7 @@ class QiscusSDK {
691
691
..syncInterval = syncInterval.milliseconds
692
692
..syncIntervalWhenConnected = syncIntervalWhenConnected.milliseconds;
693
693
694
- await __< AppConfigUseCase > ()(noParams).toCallback1 (callback);
695
- }
696
-
697
- Future <void > __subscribes (String token) async {
698
- final params = TokenParams (token);
699
- final onMessageReceived = __< OnMessageReceived > ();
700
- final realtimeService = __< IRealtimeService > ();
701
- final onMessageUpdated = __< OnMessageUpdated > ();
702
-
703
- var stream = StreamGroup .merge <void >([
704
- onMessageReceived.subscribe (params).map ((_) => null ),
705
- onMessageUpdated.subscribe (params).map ((_) => null ),
706
- realtimeService.subscribe (TopicBuilder .notification (token)).asStream (),
707
- ]);
708
-
709
- return stream.first;
710
- }
711
-
712
- Future <Tuple2 <String , Account >> _subscribes (
713
- Tuple2 <String , Account > data,
714
- ) async {
715
- await __subscribes (data.first);
716
-
717
- return data;
694
+ __< AppConfigUseCase > ()(noParams).toCallback1 (callback);
718
695
}
719
696
720
697
void setUser ({
@@ -745,8 +722,7 @@ class QiscusSDK {
745
722
746
723
authenticate
747
724
.call (params)
748
- .then ((either) => _connectMqtt (either))
749
- .then (_subscribes)
725
+ .tap ((_) => _connectMqtt ())
750
726
.then ((it) => it.second.toModel ())
751
727
.toCallback2 (callback);
752
728
}
@@ -760,18 +736,27 @@ class QiscusSDK {
760
736
761
737
authenticate (params)
762
738
.then ((account) => Tuple2 (token, account))
763
- .then ((either) => _connectMqtt (either))
764
- .then (_subscribes)
739
+ .tap ((_) => _connectMqtt ())
765
740
.then ((it) => it.second.toModel ())
766
741
.toCallback2 (callback);
767
742
}
768
743
769
- Future < T > _connectMqtt <T >(T it ) async {
744
+ void _connectMqtt <T >() async {
770
745
if (__< Storage > ().isRealtimeEnabled) {
771
746
await __< IRealtimeService > ().connect ();
772
- return it;
773
747
}
774
- return it;
748
+ final params = TokenParams (token);
749
+ final onMessageReceived = __< OnMessageReceived > ();
750
+ final realtimeService = __< IRealtimeService > ();
751
+ final onMessageUpdated = __< OnMessageUpdated > ();
752
+
753
+ var stream = StreamGroup .merge <void >([
754
+ onMessageReceived.subscribe (params).map ((_) => null ),
755
+ onMessageUpdated.subscribe (params).map ((_) => null ),
756
+ realtimeService.subscribe (TopicBuilder .notification (token)).asStream (),
757
+ ]);
758
+
759
+ await stream.first;
775
760
}
776
761
777
762
void unsubscribeChatRoom (QChatRoom room) {
0 commit comments