Skip to content

Commit

Permalink
Merge pull request Privoce#16 from Privoce/feature-invitation_link
Browse files Browse the repository at this point in the history
Feature invitation link
  • Loading branch information
shuotwang committed Oct 26, 2022
2 parents 55d8d8c + 067d055 commit d8790fa
Show file tree
Hide file tree
Showing 12 changed files with 788 additions and 224 deletions.
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 355Y8J4TGX;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.43;
MARKETING_VERSION = 0.2.44;
PRODUCT_BUNDLE_IDENTIFIER = com.privoce.vocechatclient;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -499,15 +499,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 355Y8J4TGX;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.43;
MARKETING_VERSION = 0.2.44;
PRODUCT_BUNDLE_IDENTIFIER = com.privoce.vocechatclient;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -525,15 +525,15 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 355Y8J4TGX;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2.43;
MARKETING_VERSION = 0.2.44;
PRODUCT_BUNDLE_IDENTIFIER = com.privoce.vocechatclient;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
8 changes: 8 additions & 0 deletions lib/api/lib/user_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ class UserApi {
return dio.get("/check_email?email=$email");
}

Future<Response<bool>> checkMagicToken(String magicToken) async {
final dio = DioUtil(baseUrl: _baseUrl);
dio.options.headers["content-type"] = "application/json";

return dio.post("/check_magic_token",
data: json.encode({"magic_token": magicToken}));
}

Future<Response<LoginResponse>> register(RegisterRequest req) async {
final dio = DioUtil(baseUrl: _baseUrl);
dio.options.validateStatus = (status) {
Expand Down
2 changes: 2 additions & 0 deletions lib/services/sse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class Sse {
try {
eventSource.onMessage.listen((event) {
App.app.statusService.fireSseLoading(LoadingStatus.success);
App.app.statusService.fireTokenLoading(TokenStatus.success);
App.logger.info(event.data);
fireSseEvent(event.data);
isConnecting = false;
});

eventSource.onOpen.listen((event) {
App.app.statusService.fireSseLoading(LoadingStatus.success);
App.app.statusService.fireTokenLoading(TokenStatus.success);
reconnectSec = 1;
cancelDelay();
isConnecting = false;
Expand Down
156 changes: 156 additions & 0 deletions lib/ui/auth/chat_server_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:vocechat_client/api/lib/admin_login_api.dart';
import 'package:vocechat_client/api/lib/admin_system_api.dart';
import 'package:vocechat_client/api/lib/resource_api.dart';
import 'package:vocechat_client/app.dart';
import 'package:vocechat_client/app_alert_dialog.dart';
import 'package:vocechat_client/dao/org_dao/chat_server.dart';
import 'package:vocechat_client/dao/org_dao/properties_models/chat_server_properties.dart';
import 'package:vocechat_client/ui/auth/server_page.dart';

class ChatServerHelper {
BuildContext context;

ChatServerHelper({required this.context});

Future<ChatServerM?> prepareChatServerM(String url) async {
ChatServerM chatServerM = ChatServerM();
ServerStatusWithChatServerM s;

if (!url.startsWith("https://") && !url.startsWith("http://")) {
final httpsUrl = "https://" + url;

s = await _checkServerAvailability(httpsUrl);
if (s.status == ServerStatus.uninitialized) {
await _showServerUninitializedError(s.chatServerM);
return null;
} else if (s.status == ServerStatus.available) {
chatServerM = s.chatServerM;
} else if (s.status == ServerStatus.error) {
// test http
final httpUrl = "http://" + url;
s = await _checkServerAvailability(httpUrl);
if (s.status == ServerStatus.uninitialized) {
await _showServerUninitializedError(s.chatServerM);
return null;
} else if (s.status == ServerStatus.available) {
chatServerM = s.chatServerM;
} else if (s.status == ServerStatus.error) {
await _showConnectionError();
return null;
}
}
} else {
s = await _checkServerAvailability(url);
if (s.status == ServerStatus.uninitialized) {
await _showServerUninitializedError(s.chatServerM);
return null;
} else if (s.status == ServerStatus.available) {
chatServerM = s.chatServerM;
} else if (s.status == ServerStatus.error) {
await _showConnectionError();
return null;
}
}

try {
final adminSystemApi = AdminSystemApi(chatServerM.fullUrl);

final orgInfoRes = await adminSystemApi.getOrgInfo();
if (orgInfoRes.statusCode == 200 && orgInfoRes.data != null) {
App.logger.info(orgInfoRes.data!.toJson().toString());
final orgInfo = orgInfoRes.data!;
chatServerM.properties = ChatServerProperties(
serverName: orgInfo.name, description: orgInfo.description ?? "");

final resourceApi = ResourceApi(chatServerM.fullUrl);
final logoRes = await resourceApi.getOrgLogo();
if (logoRes.statusCode == 200 && logoRes.data != null) {
chatServerM.logo = logoRes.data!;
}

final AdminLoginApi adminLoginApi = AdminLoginApi(chatServerM.fullUrl);
final adminLoginRes = await adminLoginApi.getConfig();
if (adminLoginRes.statusCode == 200 && adminLoginRes.data != null) {
chatServerM.properties = ChatServerProperties(
serverName: orgInfo.name,
description: orgInfo.description ?? "",
config: adminLoginRes.data);
}

chatServerM.updatedAt = DateTime.now().millisecondsSinceEpoch;
await ChatServerDao.dao.addOrUpdate(chatServerM);
} else {
await _showConnectionError();
return null;
}
} catch (e) {
App.logger.severe(e);
await _showConnectionError();
return null;
}

App.app.chatServerM = chatServerM;
return chatServerM;
}

Future<ServerStatusWithChatServerM> _checkServerAvailability(
String url) async {
ChatServerM chatServerM = ChatServerM();
if (!chatServerM.setByUrl(url)) {
return ServerStatusWithChatServerM(
status: ServerStatus.error, chatServerM: chatServerM);
}

final adminSystemApi = AdminSystemApi(chatServerM.fullUrl);

// Check if server has been initialized
final initializedRes = await adminSystemApi.getInitialized();
if (initializedRes.statusCode == 200 && initializedRes.data != true) {
return ServerStatusWithChatServerM(
status: ServerStatus.uninitialized, chatServerM: chatServerM);
} else if (initializedRes.statusCode != 200) {
return ServerStatusWithChatServerM(
status: ServerStatus.error, chatServerM: chatServerM);
}

return ServerStatusWithChatServerM(
status: ServerStatus.available, chatServerM: chatServerM);
}

Future<void> _showServerUninitializedError(ChatServerM chatServerM) async {
return showAppAlert(
context: context,
title: "Server Not Initialized",
content: "Please use web client for initialization.",
actions: [
AppAlertDialogAction(
text: "Cancel", action: () => Navigator.of(context).pop()),
AppAlertDialogAction(
text: "Copy Url",
action: () {
Navigator.of(context).pop();

final url = "${chatServerM.fullUrl}/#/onboarding";
Clipboard.setData(ClipboardData(text: url));
})
]);
}

Future<void> _showConnectionError() async {
return showAppAlert(
context: context,
title: "Server Connection Error",
content:
"VoceChat can't retrieve server info. You may check url format, such as 'https' and 'http', or port number, or contact server owner for help.",
actions: [
AppAlertDialogAction(
text: "OK",
action: () {
Navigator.of(context).pop();
},
)
]);
}
}
Loading

0 comments on commit d8790fa

Please sign in to comment.