Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap Work page and Work tab #541

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/icons/copy_thick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/partner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/share_thick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/l10n/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ btn_mute_chat = Mute chat
btn_mute_chats = Mute chats
btn_next = Next
btn_ok = Ok
btn_one_time_account = One-time account
btn_participants = Participants
btn_participants_desc =
Call
Expand All @@ -216,6 +217,7 @@ btn_select_and_delete = Select and delete
btn_set_password = Set password
btn_settings = Settings
btn_share = Share
btn_sign_in = Sign in
btn_start = Start
btn_submit = Submit
btn_unblock = Unblock
Expand All @@ -225,6 +227,7 @@ btn_unmute_chat = Unmute chat
btn_unmute_chats = Unmute chats
btn_upload = Upload
btn_video_call = Video call
btn_work_with_us = Work with us
btn_write_message = Write a message
btn_your_profile = Your profile
colon_space = :{" "}
Expand Down Expand Up @@ -730,6 +733,7 @@ label_was_added2 = {" "}joined via direct link
label_was_removed = {$author} left the group
label_was_removed1 = {$author}
label_was_removed2 = {" "}left the group
label_work_with_us = Work with us
label_you = You
label_you_were_added_to_group = You were added to the group
label_your_blacklist = Your blacklist
Expand Down
4 changes: 4 additions & 0 deletions assets/l10n/ru-RU.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ btn_mute_chat = Отключить звук
btn_mute_chats = Отключить звук
btn_next = Далее
btn_ok = Ок
btn_one_time_account = Одноразовый аккаунт
btn_participants = Участники
btn_participants_desc =
Список
Expand All @@ -216,6 +217,7 @@ btn_select_and_delete = Выбрать и удалить
btn_set_password = Задать пароль
btn_settings = Настройки
btn_share = Поделиться
btn_sign_in = Войти
btn_start = Начать
btn_submit = Применить
btn_unblock = Разблокировать
Expand All @@ -225,6 +227,7 @@ btn_unmute_chat = Включить звук
btn_unmute_chats = Включить звук
btn_upload = Загрузить
btn_video_call = Видеозвонок
btn_work_with_us = Работайте с нами
btn_write_message = Написать сообщение
btn_your_profile = Ваш профиль
colon_space = :{" "}
Expand Down Expand Up @@ -751,6 +754,7 @@ label_was_added2 = {" "}вступил(а) по прямой ссылке
label_was_removed = {$author} покинул(а) группу
label_was_removed1 = {$author}
label_was_removed2 = {" "}покинул(а) группу
label_work_with_us = Работайте с нами
label_you = Вы
label_you_were_added_to_group = Вас добавили в группу
label_your_blacklist = Ваш чёрный список
Expand Down
4 changes: 4 additions & 0 deletions lib/domain/repository/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,8 @@ abstract class RxChat implements Comparable<RxChat> {
List<Attachment> attachments = const [],
List<ChatItem> repliesTo = const [],
});

// TODO: Remove when backend supports welcome messages.
/// Posts a new [ChatMessage] with the provided [text] by the recipient.
Future<void> addMessage(ChatMessageText text);
}
47 changes: 22 additions & 25 deletions lib/domain/service/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ class AuthService extends GetxService {
/// Currently authorized session's [Credentials].
final Rx<Credentials?> credentials = Rx(null);

/// Authorization status.
///
/// Can be:
/// - `status.isEmpty` meaning that `MyUser` is unauthorized;
/// - `status.isLoading` meaning that authorization data is being fetched
/// from storage;
/// - `status.isLoadingMore` meaning that `MyUser` is authorized according to
/// the storage, but network request to the server is still in-flight;
/// - `status.isSuccess` meaning successful authorization.
final Rx<RxStatus> status = Rx<RxStatus>(RxStatus.loading());

/// [SessionDataHiveProvider] used to store user [Session].
final SessionDataHiveProvider _sessionProvider;

/// Authorization repository containing required authentication methods.
final AbstractAuthRepository _authRepository;

/// Authorization status.
final Rx<RxStatus> _status = Rx<RxStatus>(RxStatus.loading());

/// [Timer] used to periodically check the [Session.expireAt] and refresh it
/// if necessary.
Timer? _refreshTimer;
Expand All @@ -72,17 +80,6 @@ class AuthService extends GetxService {
/// [Credentials].
StreamSubscription? _storageSubscription;

/// Authorization status.
///
/// Can be:
/// - `status.isEmpty` meaning that `MyUser` is unauthorized;
/// - `status.isLoading` meaning that authorization data is being fetched
/// from storage;
/// - `status.isLoadingMore` meaning that `MyUser` is authorized according to
/// the storage, but network request to the server is still in-flight;
/// - `status.isSuccess` meaning successful authorization.
Rx<RxStatus> get status => _status;

/// Returns the currently authorized [Credentials.userId].
UserId? get userId => credentials.value?.userId;

Expand Down Expand Up @@ -134,7 +131,7 @@ class AuthService extends GetxService {
_authRepository.token = creds.session.token;
_authRepository.applyToken();
credentials.value = creds;
_status.value = RxStatus.success();
status.value = RxStatus.success();
}
} else {
if (!WebUtils.isPopup) {
Expand All @@ -154,7 +151,7 @@ class AuthService extends GetxService {
if (remembered == null) {
if (session.expireAt.isAfter(PreciseDateTime.now().toUtc())) {
_authorized(creds!);
_status.value = RxStatus.success();
status.value = RxStatus.success();
return null;
}
} else if (remembered.expireAt.isAfter(PreciseDateTime.now().toUtc())) {
Expand All @@ -164,7 +161,7 @@ class AuthService extends GetxService {
.isBefore(PreciseDateTime.now().toUtc())) {
renewSession();
}
_status.value = RxStatus.success();
status.value = RxStatus.success();
return null;
}

Expand Down Expand Up @@ -242,13 +239,13 @@ class AuthService extends GetxService {
/// Once the created [Session] expires, the created [MyUser] looses access, if
/// he doesn't re-sign in within that period of time.
Future<void> register() async {
_status.value = RxStatus.loading();
status.value = RxStatus.loading();
return _tokenGuard.protect(() async {
try {
var data = await _authRepository.signUp();
_authorized(data);
_sessionProvider.setCredentials(data);
_status.value = RxStatus.success();
status.value = RxStatus.success();
} catch (e) {
_unauthorized();
rethrow;
Expand All @@ -267,7 +264,7 @@ class AuthService extends GetxService {
UserNum? num,
UserEmail? email,
UserPhone? phone}) async {
_status.value = RxStatus.loadingMore();
status.value = RxStatus.loadingMore();
return _tokenGuard.protect(() async {
try {
Credentials data = await _authRepository.signIn(
Expand All @@ -279,7 +276,7 @@ class AuthService extends GetxService {
);
_authorized(data);
_sessionProvider.setCredentials(data);
_status.value = RxStatus.success();
status.value = RxStatus.success();
} catch (e) {
_unauthorized();
rethrow;
Expand All @@ -290,7 +287,7 @@ class AuthService extends GetxService {
// TODO: Clean Hive storage on logout.
/// Deletes [Session] of the currently authenticated [MyUser].
Future<String> logout() async {
_status.value = RxStatus.loading();
status.value = RxStatus.loading();

try {
await _authRepository.logout();
Expand Down Expand Up @@ -336,7 +333,7 @@ class AuthService extends GetxService {
_authorized(data);

_sessionProvider.setCredentials(data);
_status.value = RxStatus.success();
status.value = RxStatus.success();
} on RenewSessionException catch (_) {
router.go(_unauthorized());
rethrow;
Expand All @@ -363,15 +360,15 @@ class AuthService extends GetxService {
renewSession();
}
});
_status.value = RxStatus.loadingMore();
status.value = RxStatus.loadingMore();
}

/// Sets authorized [status] to `isEmpty` (aka "unauthorized").
String _unauthorized() {
_sessionProvider.clear();
_authRepository.token = null;
credentials.value = null;
_status.value = RxStatus.empty();
status.value = RxStatus.empty();
_refreshTimer?.cancel();
return Routes.auth;
}
Expand Down
Loading
Loading