Skip to content

Commit

Permalink
## 0.3.13
Browse files Browse the repository at this point in the history
### fix:

- Error when switching users
- User follow list can't load
- Fix duplicate loading of timeline
- Fix image save failed

### refactor

move logger.dart file update loading state in list riverpod
  • Loading branch information
ChenDoxiu committed Jul 12, 2024
1 parent 4a35c18 commit 445a92c
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 88 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.3.13

### fix:

- Error when switching users
- User follow list can't load
- Fix duplicate loading of timeline
- Fix image save failed

### refactor

move logger.dart file update loading state in list riverpod

## 0.3.12

### Feature
Expand Down
3 changes: 2 additions & 1 deletion lib/apis/models/drive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class DriveFileModel extends DriveModel {
size: map['size'],
name: map['name'],
id: map['id'],
properties: Properties.fromMap(map['properties']),
properties:
Properties.fromMap(Map<String, dynamic>.from(map['properties'])),
isSensitive: map['isSensitive'] ?? false,
thumbnailUrl: map['thumbnailUrl'],
comment: map['comment'],
Expand Down
26 changes: 22 additions & 4 deletions lib/apis/models/login_user.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:moekey/apis/models/user_full.dart';

class LoginUser {
final String serverUrl;
final String token;
final Map userInfo;
final UserFullModel userInfo;
final String name;
final String id;

Expand All @@ -22,16 +24,32 @@ class LoginUser {
return {
"serverUrl": serverUrl,
"token": token,
"userInfo": userInfo,
"userInfo": userInfo.toMap(),
"name": name,
"id": id,
};
}

factory LoginUser.fromMap(Map<dynamic, dynamic> json) => LoginUser(
LoginUser copyWith({
String? serverUrl,
String? token,
UserFullModel? userInfo,
String? name,
String? id,
}) {
return LoginUser(
name: name ?? this.name,
serverUrl: serverUrl ?? this.serverUrl,
token: token ?? this.token,
userInfo: userInfo ?? this.userInfo,
id: id ?? this.id,
);
}

factory LoginUser.fromMap(Map json) => LoginUser(
serverUrl: json["serverUrl"],
token: json["token"],
userInfo: json["userInfo"],
userInfo: UserFullModel.fromMap(json["userInfo"]),
name: json["name"],
id: json["id"]);
}
2 changes: 1 addition & 1 deletion lib/apis/models/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class NoteModel {
reply: map['reply'] != null ? NoteModel.fromMap(map['reply']) : null,
text: map['text'],
uri: map['uri'],
user: UserLiteModel.fromMap(map['user']),
user: UserLiteModel.fromMap(Map<String, dynamic>.from(map['user'])),
userId: map['userId'],
visibility: NoteVisibility.fromString(
map['visibility'],
Expand Down
42 changes: 40 additions & 2 deletions lib/apis/models/user_full.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class UserFullModel {
createdAt: DateTime.parse(map['createdAt']),
description: map['description'],
email: map['email'],
emojis: map['emojis'],
emojis: Map<String, dynamic>.from(map['emojis']),
followersCount: map['followersCount'],
followingCount: map['followingCount'],
host: map['host'],
Expand Down Expand Up @@ -209,5 +209,43 @@ class UserFullModel {
);
}

toMap() {}
Map<String, dynamic> toMap() {
return {
'avatarBlurhash': avatarBlurhash,
'avatarUrl': avatarUrl,
'bannerBlurhash': bannerBlurhash,
'bannerUrl': bannerUrl,
'birthday': birthday,
'createdAt': createdAt.toIso8601String(),
'description': description,
'email': email,
'emojis': emojis,
'followersCount': followersCount,
'followingCount': followingCount,
'host': host,
'id': id,
'isAdmin': isAdmin,
'publicReactions': publicReactions,
'onlineStatus': onlineStatusValues.reverse[onlineStatus],
'updatedAt': updatedAt?.toIso8601String(),
'username': username,
'name': name,
'fields': fields,
'avatarDecorations':
avatarDecorations?.map((decoration) => decoration.toMap()).toList(),
'ffVisibility': ffVisibility,
'followersVisibility': followersVisibility,
'followingVisibility': followingVisibility,
'pinnedNotes': pinnedNotes.map((note) => note.toMap()).toList(),
'pinnedNotesIds': pinnedNotesIds,
'uri': uri,
'url': url,
'notesCount': notesCount,
'isFollowed': isFollowed,
'isFollowing': isFollowing,
'hasPendingFollowRequestFromYou': hasPendingFollowRequestFromYou,
'hasPendingFollowRequestToYou': hasPendingFollowRequestToYou,
'isLocked': isLocked,
};
}
}
15 changes: 13 additions & 2 deletions lib/apis/models/user_lite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class UserLiteModel {
final OnlineStatus onlineStatus;
final String username;

@override
String toString() {
return 'UserLiteModel{avatarBlurhash: $avatarBlurhash, avatarDecorations: $avatarDecorations, avatarUrl: $avatarUrl, badgeRoles: $badgeRoles, emojis: $emojis, host: $host, id: $id, instance: $instance, isBot: $isBot, isCat: $isCat, name: $name, onlineStatus: $onlineStatus, username: $username}';
}

UserLiteModel({
required this.avatarBlurhash,
required this.avatarDecorations,
Expand Down Expand Up @@ -76,8 +81,9 @@ class UserLiteModel {

factory UserLiteModel.fromMap(Map<String, dynamic> json) => UserLiteModel(
avatarBlurhash: json["avatarBlurhash"],
avatarDecorations: List<AvatarDecoration>.from(
json["avatarDecorations"].map((x) => AvatarDecoration.fromMap(x))),
avatarDecorations: List<AvatarDecoration>.from(json["avatarDecorations"]
.map(
(x) => AvatarDecoration.fromMap(Map<String, dynamic>.from(x)))),
avatarUrl: json["avatarUrl"],
badgeRoles: json["badgeRoles"] == null
? []
Expand Down Expand Up @@ -183,6 +189,11 @@ class BadgeRoleModel {
final String? iconUrl;
final String name;

@override
String toString() {
return 'BadgeRoleModel{behavior: $behavior, displayOrder: $displayOrder, iconUrl: $iconUrl, name: $name}';
}

BadgeRoleModel({
this.behavior,
required this.displayOrder,
Expand Down
2 changes: 1 addition & 1 deletion lib/apis/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AuthService extends MisskeyApiServices {
/// {"appSecret": appSecret, "token": token}
Future<Map<String, dynamic>?> sessionUserKey(
{required String appSecret, required String token}) async {
return await client.post(
return await client.post<Map<String, dynamic>>(
"/auth/session/userkey",
data: {"appSecret": appSecret, "token": token},
auth: false,
Expand Down
8 changes: 3 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Future<void> main() async {
}

final globalNav = GlobalKey<NavigatorState>();
final globalMaterialAppKey = GlobalKey();

class MyApp extends HookConsumerWidget {
const MyApp({super.key});
Expand All @@ -62,7 +61,6 @@ class MyApp extends HookConsumerWidget {
return MaterialApp(
debugShowCheckedModeBanner: false,
navigatorKey: globalNav,
key: globalMaterialAppKey,
theme: theme,
home: const SplashPage(),
// builder: (context, child) {
Expand Down Expand Up @@ -94,10 +92,10 @@ class SplashPage extends HookConsumerWidget {
builder: (context) {
return Consumer(
builder: (context, ref, child) {
var user = ref.watch(currentLoginUserProvider);
var user = ref.read(currentLoginUserProvider);
// 启动webSocket
ref.watch(moekeyGlobalEventProvider);
ref.watch(moekeyMainChannelProvider);
ref.read(moekeyGlobalEventProvider);
ref.read(moekeyMainChannelProvider);
if (user != null) {
return HomePage();
}
Expand Down
3 changes: 0 additions & 3 deletions lib/pages/clips/clips_notes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_tabler_icons/flutter_tabler_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand All @@ -20,7 +18,6 @@ import '../../apis/models/clips.dart';
import '../../apis/models/note.dart';
import '../../status/themes.dart';
import '../../utils/get_padding_note.dart';
import '../../widgets/loading_weight.dart';
import '../../widgets/mk_info_dialog.dart';
import '../../widgets/notes/note_card.dart';
import '../notes/note_page.dart';
Expand Down
80 changes: 59 additions & 21 deletions lib/pages/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ import 'package:moekey/status/themes.dart';
import 'package:moekey/widgets/context_menu.dart';
import 'package:moekey/widgets/login/servers_select.dart';

import '../../status/misskey_api.dart';
import '../../widgets/blur_widget.dart';
import '../../widgets/hover_builder.dart';
import '../../widgets/mk_image.dart';
import '../../widgets/note_create_dialog/note_create_dialog.dart';
import '../user_widgets/widgets_list/view.dart';

void updateUserInfo(WidgetRef ref) {
Future.delayed(
Duration.zero,
() async {
var api = ref.read(misskeyApisProvider);
var user = ref.read(currentLoginUserProvider);
var data = await api.user.show(userId: user?.id);

user = user?.copyWith(name: data?.name ?? data?.username, userInfo: data);
ref.read(loginUserListProvider.notifier).addUser(user!);
},
);
}

class HomePage extends HookConsumerWidget {
HomePage({super.key});

Expand All @@ -45,6 +60,7 @@ class HomePage extends HookConsumerWidget {
var themes = ref.watch(themeColorsProvider);
var router = ref.watch(routerDelegateProvider);
var currentId = useState(router.currentConfiguration?.path);
var user = ref.read(currentLoginUserProvider);
func() {
currentId.value = router.currentConfiguration?.path;
}
Expand All @@ -58,7 +74,10 @@ class HomePage extends HookConsumerWidget {
"announcements",
"search"
].contains(currentId.value);

useEffect(() {
updateUserInfo(ref);
return null;
}, [user?.id]);
useEffect(() {
func();
router.addListener(func);
Expand Down Expand Up @@ -365,7 +384,7 @@ class UserAvatarButton extends ConsumerWidget {
SizedBox(
width: 28,
height: 28,
child: MkImage(user?.userInfo["avatarUrl"],
child: MkImage(user?.userInfo.avatarUrl ?? "",
shape: BoxShape.circle),
),
SizedBox(width: large ? 8 : 4),
Expand All @@ -374,10 +393,19 @@ class UserAvatarButton extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (user?.userInfo["name"] != null)
Text(user?.userInfo["name"] ?? "")
else
Text("@${user?.userInfo["username"] ?? ""}"),
if (user?.userInfo.name != null) ...[
Text(user?.userInfo.name ?? ""),
Text(
"@${user?.userInfo.username ?? ""}@${Uri.parse(user?.serverUrl ?? "").host}",
style: const TextStyle(fontSize: 12),
)
] else ...[
Text("@${user?.userInfo.username ?? ""}"),
Text(
Uri.parse(user?.serverUrl ?? "").host,
style: const TextStyle(fontSize: 12),
)
]
],
))
],
Expand Down Expand Up @@ -417,7 +445,7 @@ class UserAvatarButton extends ConsumerWidget {
SizedBox(
width: 28,
height: 28,
child: MkImage(item.userInfo["avatarUrl"],
child: MkImage(item.userInfo.avatarUrl ?? "",
shape: BoxShape.circle),
),
const SizedBox(width: 4),
Expand All @@ -426,20 +454,31 @@ class UserAvatarButton extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (item.userInfo["name"] != null)
Text(item.userInfo["name"] ?? "")
else
Text("@${item.userInfo["username"] ?? ""}"),
if (item.userInfo.name != null) ...[
Text(item.userInfo.name ?? ""),
Text(
"@${item.userInfo.username}@${Uri.parse(item.serverUrl).host}",
style: const TextStyle(fontSize: 12),
)
] else ...[
Text("@${item.userInfo.username}"),
Text(
Uri.parse(item.serverUrl).host,
style: const TextStyle(fontSize: 12),
)
]
],
))
],
),
);
},
onTap: () {
ref
.read(currentLoginUserProvider.notifier)
.setLoginUser(item.id);
Future.delayed(const Duration(milliseconds: 200), () {
ref
.read(currentLoginUserProvider.notifier)
.setLoginUser(item.id);
});
return false;
},
),
Expand Down Expand Up @@ -488,18 +527,18 @@ class UserAvatarButton extends ConsumerWidget {
child: Padding(
padding: const EdgeInsets.fromLTRB(18, 0, 18, 0),
child: Tooltip(
message: extend ? "" : "账户:@${userData?["username"] ?? ""}",
message: extend ? "" : "账户:@${userData?.username ?? ""}",
child: Row(
mainAxisAlignment:
extend ? MainAxisAlignment.start : MainAxisAlignment.center,
children: [
userData?["avatarUrl"] != null
userData?.avatarUrl != null
? SizedBox(
width: extend ? 32 : 38,
height: extend ? 32 : 38,
child: MkImage(
userData?["avatarUrl"],
blurHash: userData?["avatarBlurhash"],
userData?.avatarUrl ?? "",
blurHash: userData?.avatarBlurhash,
width: extend ? 32 : 38,
height: extend ? 32 : 38,
fit: BoxFit.cover,
Expand All @@ -516,9 +555,8 @@ class UserAvatarButton extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (userData?["name"] != null)
Text(userData?["name"] ?? ""),
Text("@${userData?["username"] ?? ""}"),
if (userData?.name != null) Text(userData?.name ?? ""),
Text("@${userData?.username ?? ""}"),
],
)
],
Expand Down
1 change: 1 addition & 0 deletions lib/pages/notes/note_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class UserInfo extends HookConsumerWidget {
GestureDetector(
child: MkImage(
data.avatarUrl ?? "",
blurHash: data.avatarBlurhash,
width: 56,
height: 56,
shape: BoxShape.circle,
Expand Down
Loading

0 comments on commit 445a92c

Please sign in to comment.