Skip to content

Commit

Permalink
Merge pull request #227 from bobs4462/dev
Browse files Browse the repository at this point in the history
build 2.2.1
  • Loading branch information
bmuddha authored Jan 26, 2021
2 parents 8edc361 + 457f469 commit c3affbf
Show file tree
Hide file tree
Showing 36 changed files with 1,100 additions and 720 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.twake.twake"
minSdkVersion 16
minSdkVersion 17
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
6 changes: 0 additions & 6 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>Making pictures and videos to posting directly to the chat</string>
<key>NSMicrophoneUsageDescription</key>
<string>Video recording requires microphone</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Uploading pictures to the chat</string>
<key>UIBackgroundModes</key>
<array/>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/add_channel_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AddChannelBloc extends Bloc<AddChannelEvent, AddChannelState> {
repository.channelGroup = event.groupName ?? repository.channelGroup;
repository.type = event.type ?? repository.type ?? ChannelType.public;
repository.members = event.participants ?? repository.members ?? [];
repository.def = event.automaticallyAddNew ?? repository.def ?? false;
repository.def = event.automaticallyAddNew ?? repository.def ?? true;

// print('Updated data: ${repository.toJson()}');
var newRepo = AddChannelRepository(
Expand Down
75 changes: 63 additions & 12 deletions lib/blocs/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,49 @@ import 'package:twake/repositories/auth_repository.dart';
import 'package:twake/services/api.dart';
import 'package:twake/services/init.dart';
import 'package:twake/states/auth_state.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

export 'package:twake/events/auth_event.dart';
export 'package:twake/states/auth_state.dart';

class AuthBloc extends Bloc<AuthEvent, AuthState> {
final AuthRepository repository;
HeadlessInAppWebView webView;
final twakeConsole =
'https://beta.twake.app/ajax/users/console/openid?mobile=1';
AuthBloc(this.repository) : super(AuthInitializing()) {
Api().resetAuthentication = resetAuthentication;
webView = HeadlessInAppWebView(
initialUrl: twakeConsole,
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
cacheEnabled: false,
javaScriptCanOpenWindowsAutomatically: true,
),
),
onConsoleMessage: (ctrl, msg) => print('CONSOLEJS: $msg'),
onLoadStop: (ctrl, url) async {
print('URL: $url');
if (url.contains('redirect_to_app')) {
final qp = Uri.parse(url).queryParameters;
// Logger().d('PARAMS: $qp');
if (qp['token'] == null || qp['username'] == null) {
print('NO TOKEN AND USERNAME');
ctrl.loadUrl(url: twakeConsole);
return;
}
this.add(
SetAuthData(qp),
);
ctrl.clearCache();
await CookieManager().deleteAllCookies();
}
},
onWebViewCreated: (ctrl) {
print('CREATED WEBVIEW');
},
);
CookieManager.instance().deleteAllCookies();
}

@override
Expand Down Expand Up @@ -41,41 +76,57 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
break;
case AuthResult.WrongCredentials:
yield Unauthenticated();
webView.run();
}
break;
case TokenStatus.BothExpired:
yield Unauthenticated(message: 'Session expired');
webView.run();
}
} else if (event is Authenticate) {
yield Authenticating();
final result = await repository.authenticate(
username: event.username,
password: event.password,
);
if (result == AuthResult.WrongCredentials) {
yield Unauthenticated(message: 'Wrong credentials');
} else if (result == AuthResult.NetworkError) {
yield AuthenticationError();
} else {
final InitData initData = await initMain();
yield Authenticated(initData);
}
print('CURRENT PAGE ${await webView.webViewController.getUrl()}');
print(await webView.webViewController.evaluateJavascript(
source:
'''!function(l,p){function f(){document.getElementById("userfield").value=l,document.getElementById("passwordfield").value=p,document.getElementById("lform").submit()}"complete"===document.readyState||"interactive"===document.readyState?setTimeout(f,1):document.addEventListener("DOMContentLoaded",f)}("${event.username}","${event.password}");'''));
// final result = await repository.authenticate(
// username: event.username,
// password: event.password,
// );
// if (result == AuthResult.WrongCredentials) {
// yield Unauthenticated(message: 'Wrong credentials');
// } else if (result == AuthResult.NetworkError) {
// yield AuthenticationError();
// } else {
// final InitData initData = await initMain();
// yield Authenticated(initData);
// }
} else if (event is SetAuthData) {
yield Authenticating();
await repository.setAuthData(event.authData);
final InitData initData = await initMain();
yield Authenticated(initData);
webView.dispose();
} else if (event is ResetAuthentication) {
if (event.message == null) {
repository.fullClean();
} else {
repository.clean();
}
yield Unauthenticated(message: event.message);
await CookieManager.instance().deleteAllCookies();
await webView.dispose();
webView.run();
}
}

void resetAuthentication() {
this.add(ResetAuthentication(message: 'Session has expired'));
}

@override
Future<void> close() {
webView.dispose();
return super.close();
}
}
40 changes: 22 additions & 18 deletions lib/blocs/threads_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,31 @@ class ThreadsBloc<T extends BaseChannelBloc>
@override
Stream<MessagesState> mapEventToState(MessagesEvent event) async* {
if (event is LoadMessages) {
yield MessagesLoading(
threadMessage: threadMessage,
parentChannel: parentChannel,
);
List<List> filters = [
['thread_id', '=', event.threadId],
];
bool success = await repository.reload(
queryParams: _makeQueryParams(event),
filters: filters,
sortFields: {'creation_date': true},
limit: _THREAD_MESSAGES_LIMIT,
);
if (!success) {
repository.clean();
yield ErrorLoadingMessages(
if (threadMessage.responsesCount > 0) {
yield MessagesLoading(
threadMessage: threadMessage,
parentChannel: parentChannel,
force: DateTime.now().toString(),
);
return;
List<List> filters = [
['thread_id', '=', event.threadId],
];
bool success = await repository.reload(
queryParams: _makeQueryParams(event),
filters: filters,
sortFields: {'creation_date': true},
limit: _THREAD_MESSAGES_LIMIT,
);
if (!success) {
repository.clean();
yield ErrorLoadingMessages(
threadMessage: threadMessage,
parentChannel: parentChannel,
force: DateTime.now().toString(),
);
return;
}
} else {
repository.clean();
}
if (repository.items.isEmpty)
yield MessagesEmpty(
Expand Down
3 changes: 3 additions & 0 deletions lib/config/styles_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class StylesConfig {
elevation: 0.0,
brightness: Brightness.light,
),
cardTheme: CardTheme(
color: Colors.transparent,
),
// fontFamily: 'PT',
);

Expand Down
2 changes: 1 addition & 1 deletion lib/models/base_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class BaseChannel extends CollectionItem {
@JsonKey(required: true)
String name;

@JsonKey(defaultValue: ':+1:')
@JsonKey(defaultValue: '👽')
String icon;

String description;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/channel.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/models/direct.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions lib/pages/initial_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import 'package:twake/blocs/threads_bloc.dart';
import 'package:twake/blocs/workspaces_bloc.dart';
import 'package:twake/blocs/add_channel_bloc.dart';
import 'package:twake/config/dimensions_config.dart';
// import 'package:twake/pages/auth_page.dart';
import 'package:twake/pages/auth_page.dart';
import 'package:twake/pages/routes.dart';
import 'package:twake/pages/web_auth_page.dart';
// import 'package:twake/pages/web_auth_page.dart';

class InitialPage extends StatefulWidget {
@override
_InitialPageState createState() => _InitialPageState();
}

class _InitialPageState extends State<InitialPage> {
final _navigatorKey = GlobalKey<NavigatorState>();
@override
void initState() {
super.initState();
Expand Down Expand Up @@ -54,7 +55,7 @@ class _InitialPageState extends State<InitialPage> {
return buildSplashScreen();
}
if (state is Unauthenticated) {
return WebAuthPage();
return AuthPage();
}
if (state is Authenticated) {
return MultiBlocProvider(
Expand Down Expand Up @@ -142,10 +143,15 @@ class _InitialPageState extends State<InitialPage> {
lazy: false,
),
],
child: Navigator(
initialRoute: Routes.main,
onGenerateRoute: (settings) =>
Routes.onGenerateRoute(settings.name),
child: WillPopScope(
onWillPop: () async =>
!await _navigatorKey.currentState.maybePop(),
child: Navigator(
key: _navigatorKey,
initialRoute: Routes.main,
onGenerateRoute: (settings) =>
Routes.onGenerateRoute(settings.name),
),
),
);
} else // is Authenticating
Expand Down
Loading

0 comments on commit c3affbf

Please sign in to comment.