Skip to content

Commit

Permalink
add login expired dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenDoXiu committed Feb 3, 2025
1 parent 9025008 commit 0e8080b
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 100 deletions.
29 changes: 21 additions & 8 deletions lib/apis/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import 'package:dio/dio.dart';
import 'package:dio_smart_retry/dio_smart_retry.dart';

class MisskeyApisHttpClient {
MisskeyApisHttpClient({required this.host, required this.accessToken}) {
MisskeyApisHttpClient({
required this.host,
required this.accessToken,
required this.onUnauthorized,
}) {
client = Dio(BaseOptions(
baseUrl: "$host/api",
));
Expand All @@ -16,6 +20,7 @@ class MisskeyApisHttpClient {

String host;
String accessToken;
Function? onUnauthorized;
late Dio client;

Future<T> post<T>(
Expand All @@ -24,13 +29,21 @@ class MisskeyApisHttpClient {
auth = true,
Options? options,
}) async {
return (await client.post(path,
data: {
if (auth) "i": accessToken,
...?data,
},
options: options))
.data;
try {
return (await client.post(path,
data: {
if (auth) "i": accessToken,
...?data,
},
options: options))
.data;
} on DioException catch (e) {
// 401
if (e.response?.statusCode == 401) {
onUnauthorized?.call();
}
rethrow;
}
}

Future<Map<String, dynamic>?> get(
Expand Down
8 changes: 7 additions & 1 deletion lib/apis/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class MisskeyApis {
MisskeyApis({
required this.instance,
required this.accessToken,
required this.onUnauthorized,
}) {
client = MisskeyApisHttpClient(host: instance, accessToken: accessToken);
client = MisskeyApisHttpClient(
host: instance,
accessToken: accessToken,
onUnauthorized: onUnauthorized,
);
account = AccountService(client: client);
app = AppService(client: client);
auth = AuthService(client: client);
Expand All @@ -30,6 +35,7 @@ class MisskeyApis {

String instance;
String accessToken;
Function? onUnauthorized;
late MisskeyApisHttpClient client;
late AccountService account;
late AppService app;
Expand Down
122 changes: 122 additions & 0 deletions lib/apis/models/me_detailed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:moekey/apis/models/note.dart';
import 'package:moekey/apis/models/user_full.dart';
import 'package:moekey/apis/models/user_lite.dart';
import 'package:flutter/foundation.dart';

part 'me_detailed.freezed.dart';

part 'me_detailed.g.dart';

@freezed
class MeDetailed with _$MeDetailed {
const factory MeDetailed({
required String? avatarBlurhash,
required List<AvatarDecoration> avatarDecorations,
required String? avatarUrl,
List<BadgeRole>? badgeRoles,
required Map<String, String> emojis,
required String? host,
required String id,
Instance? instance,
bool? isBot,
bool? isCat,
double? makeNotesFollowersOnlyBefore,
double? makeNotesHiddenBefore,
required String? name,
required OnlineStatus onlineStatus,
bool? requireSigninToViewContents,
required String username,
required List<String>? alsoKnownAs,
required String? bannerBlurhash,
required String? bannerUrl,
required String? birthday,
required DateTime createdAt,
required String? description,
@Default([]) List<dynamic> fields,
required String? followedMessage,
required double followersCount,
required FollowVisibility followersVisibility,
required double followingCount,
required FollowVisibility followingVisibility,
bool? hasPendingFollowRequestFromYou,
bool? hasPendingFollowRequestToYou,
bool? isBlocked,
bool? isBlocking,
bool? isFollowed,
bool? isFollowing,
required bool isLocked,
bool? isMuted,
bool? isRenoteMuted,
required bool isSilenced,
required bool isSuspended,
required String? lang,
required DateTime? lastFetchedAt,
required String? location,
required String? memo,
String? moderationNote,
required String? movedTo,
required double notesCount,
Notify? notify,
required List<String> pinnedNoteIds,
required List<NoteModel> pinnedNotes,
// required Page pinnedPage,
required String? pinnedPageId,
required bool publicReactions,
// required List<RoleLite> roles,
required bool securityKeys,
required bool twoFactorEnabled,
required DateTime? updatedAt,
required String? uri,
required String? url,
required bool usePasswordLessLogin,
required List<String> verifiedLinks,
bool? withReplies,
// required List<Achievement> achievements,
required bool alwaysMarkNsfw,
required bool autoAcceptFollowed,
required bool autoSensitive,
required String? avatarId,
required String? bannerId,
required bool carefulBot,
String? email,
required List<String> emailNotificationTypes,
bool? emailVerified,
required List<List<String>> hardMutedWords,
required bool hasPendingReceivedFollowRequest,
required bool hasUnreadAnnouncement,
required bool hasUnreadAntenna,
required bool hasUnreadChannel,
required bool hasUnreadMentions,
required bool hasUnreadNotification,
required bool hasUnreadSpecifiedNotes,
required bool hideOnlineStatus,
required bool injectFeaturedNote,
required bool? isAdmin,
required bool isDeleted,
required bool isExplorable,
required bool? isModerator,
required double loggedInDays,
required List<String>? mutedInstances,
required List<List<String>> mutedWords,
required bool noCrawle,
// required NotificationRecieveConfig notificationRecieveConfig,
// required RolePolicies policies,
required bool preventAiLearning,
required bool receiveAnnouncementEmail,
// List<SecurityKeysList>? securityKeysList,
// required TwoFactorBackupCodesStock twoFactorBackupCodesStock,
// required List<Announcement> unreadAnnouncements,
required double unreadNotificationsCount,
}) = _MeDetailed;

factory MeDetailed.fromJson(Map<String, dynamic> json) =>
_$MeDetailedFromJson(json);
}

enum Notify {
@JsonValue("none")
NONE,
@JsonValue("normal")
NORMAL
}
13 changes: 11 additions & 2 deletions lib/apis/models/user_full.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class UserFullModel with _$UserFullModel {
@Default([]) List<dynamic> fields,
List<AvatarDecoration>? avatarDecorations,
String? ffVisibility,
String? followersVisibility,
String? followingVisibility,
FollowVisibility? followersVisibility,
FollowVisibility? followingVisibility,
@Default([]) List<NoteModel> pinnedNotes,
@Default([]) List<String> pinnedNotesIds,
String? uri,
Expand All @@ -48,3 +48,12 @@ class UserFullModel with _$UserFullModel {
factory UserFullModel.fromJson(Map<String, dynamic> json) =>
_$UserFullModelFromJson(json);
}

enum FollowVisibility {
@JsonValue("followers")
FOLLOWERS,
@JsonValue("private")
PRIVATE,
@JsonValue("public")
PUBLIC
}
2 changes: 2 additions & 0 deletions lib/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class MessageLookup extends MessageLookupByLibrary {
"clipRemove": MessageLookupByLibrary.simpleMessage("移除便签"),
"clipUpdate": MessageLookupByLibrary.simpleMessage("更新便签"),
"clips": MessageLookupByLibrary.simpleMessage("便签"),
"close": MessageLookupByLibrary.simpleMessage("关闭"),
"confirmSelection": m0,
"copyContent": MessageLookupByLibrary.simpleMessage("复制内容"),
"copyLink": MessageLookupByLibrary.simpleMessage("复制链接"),
Expand Down Expand Up @@ -160,6 +161,7 @@ class MessageLookup extends MessageLookupByLibrary {
"local": MessageLookupByLibrary.simpleMessage("本地"),
"localUpload": MessageLookupByLibrary.simpleMessage("本地上传"),
"login": MessageLookupByLibrary.simpleMessage("登录"),
"loginExpired": MessageLookupByLibrary.simpleMessage("登录信息已经过期,请重新登录"),
"loginFailed": MessageLookupByLibrary.simpleMessage("登录失败"),
"loginFailedWithAppCreate":
MessageLookupByLibrary.simpleMessage("登录失败: 应用创建失败"),
Expand Down
20 changes: 20 additions & 0 deletions lib/generated/l10n.dart

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

4 changes: 3 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
"copyUserHomeLink": "复制用户主页地址",
"pendingFollowRequest": "关注请求批准中",
"processing": "处理中",
"overviews": "概览"
"overviews": "概览",
"close": "关闭",
"loginExpired": "登录信息已经过期,请重新登录"
}

2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MyApp extends HookConsumerWidget {
mediaQueryData = mediaQueryData.copyWith(textScaler: TextScaler.linear(1));
// 获取 MediaQuery 的 platformBrightness
var platformBrightness = MediaQuery.platformBrightnessOf(context);
var systemBrightness = ref.watch(systemBrightnessProvider);
ref.watch(systemBrightnessProvider);
// 更新 Provider 的值
Future.delayed(Duration.zero, () {
ref
Expand Down
Loading

0 comments on commit 0e8080b

Please sign in to comment.