Skip to content

Commit

Permalink
Merge pull request #5 from ChenDoXiu/feat-mfm
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
ChenDoXiu authored Feb 4, 2024
2 parents b58e887 + 0591640 commit b571d93
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 183 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog

# 0.1.1
## 0.2.0

# 0.1.0
### Feature

- The preview of the original note is now displayed in the note create dialog
- The username mention is now automatically added to the reply dialog

### Fixed

- Some mention avatars on the notes page don't display in some cases
- The link for MFM is not opening

### Other

- Upgrade flutter dependencies
14 changes: 14 additions & 0 deletions lib/models/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ class NoteModel {
return 'NoteModel{id: $id, clippedCount: $clippedCount, createdAt: $createdAt, cw: $cw, emojis: $emojis, files: $files, localOnly: $localOnly, reactionAcceptance: $reactionAcceptance, reactionEmojis: $reactionEmojis, reactions: $reactions, myReaction: $myReaction, renote: $renote, renoteCount: $renoteCount, renoteId: $renoteId, repliesCount: $repliesCount, reply: $reply, replyId: $replyId, text: $text, uri: $uri, user: $user, userId: $userId, visibility: $visibility, poll: $poll}';
}

String createReplyAtText(String? currentUserId) {
var initText = "";
if (user.id != currentUserId) {
initText += user.getAtUserName();
}
if (reply?.user != null &&
reply!.user.id != user.id &&
reply!.user.id != currentUserId) {
initText += " ";
initText += reply!.user.getAtUserName();
}
return initText;
}

factory NoteModel.fromMap(dynamic map) {
List<DriveFileModel> files = [];
for (var item in map['files']) {
Expand Down
4 changes: 4 additions & 0 deletions lib/models/user_simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class UserSimpleModel {
required this.username,
required this.badgeRoles});

String getAtUserName() {
return "@$username${host != null ? "@$host" : ""}";
}

UserSimpleModel copyWith(
{bool? isCat,
Map? emojis,
Expand Down
2 changes: 0 additions & 2 deletions lib/networks/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
import 'package:moekey/networks/dio.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../main.dart';
import '../state/themes.dart';

part 'apis.g.dart';
Expand All @@ -25,7 +24,6 @@ class ServerInfoState extends _$ServerInfoState {
FutureOr<Map> build() async {
var colors = ref.read(themeColorsProvider.notifier);
var meta = await ref.watch(apiMetaProvider.future);
logger.d("123");
colors.updateThemes(meta);
return meta;
}
Expand Down
10 changes: 7 additions & 3 deletions lib/networks/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ class UserFollowing extends _$UserFollowing {

@riverpod
Future<UserFullModel> userInfo(UserInfoRef ref,
{required String userId}) async {
{String? username, String? host, String? userId}) async {
var http = await ref.read(httpProvider.future);
var user = await ref.read(currentLoginUserProvider.future);

var res = await http
.post("/users/show", data: {"userId": userId, "i": user?.token});
var res = await http.post("/users/show", data: {
if (username != null) "username": username,
if (host != null) "host": host,
"i": user?.token,
if (userId != null) "userId": userId,
});
return UserFullModel.fromMap(res.data);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/pages/notes/note_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class NotesPageNoteCard extends HookConsumerWidget {
MFMText(
text: data.text ?? "",
emojis: data.emojis,
currentServerHost: data.user.host ?? "",
currentServerHost: data.user.host,
isSelection: true,
),
const SizedBox(height: 4),
Expand All @@ -379,7 +379,7 @@ class NotesPageNoteCard extends HookConsumerWidget {
borderRadius: const BorderRadius.all(Radius.circular(8))),
padding: const EdgeInsets.all(12),
child: TimeLineNoteCardComponent(
data: data.renote,
data: data.renote!,
isShowAction: false,
disableReactions: true),
),
Expand Down
81 changes: 35 additions & 46 deletions lib/pages/users/user_overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ class UserOverview extends HookConsumerWidget {
} else {
padding = 0;
}
var dataProvider = userNotesListProvider(
userId: userId,
withRenotes: true,
withChannelNotes: false,
withFiles: false,
withReplies: false);
var dataProvider = userNotesListProvider(userId: userId);
var data = ref.watch(dataProvider);
print(data.error);
var themes = ref.watch(themeColorsProvider);
var user = ref.watch(userInfoProvider(userId: userId));
return RefreshIndicator.adaptive(
Expand Down Expand Up @@ -96,17 +90,11 @@ class UserOverview extends HookConsumerWidget {
pined: true,
);
}
print(index);
return NoteCard(
key: ValueKey(
data.valueOrNull!.list[index - pinCount].id),
borderRadius: borderRadius,
data: data.valueOrNull!.list[index - pinCount]);
// return KeepAliveWrapper(
// child: TimelineCardComponent(
// data: data.valueOrNull![index],
// borderRadius: borderRadius,
// ));
},
separatorBuilder: (BuildContext context, int index) {
return SizedBox(
Expand Down Expand Up @@ -235,7 +223,7 @@ class UserHomeCard extends HookConsumerWidget {
? Alignment.bottomCenter
: const Alignment(-1, 1),
child: Transform.translate(
offset: Offset(isSmall ? 0 : 32, isSmall ? 50 : 60),
offset: Offset(isSmall ? 0 : 16, isSmall ? 50 : 60),
child: Container(
decoration: BoxDecoration(
border: Border.all(
Expand All @@ -244,14 +232,14 @@ class UserHomeCard extends HookConsumerWidget {
Radius.circular(200),
),
color: themes.panelColor,
// boxShadow: [
// if (!isSmall)
// BoxShadow(
// color: Colors.black.withOpacity(0.1),
// offset: const Offset(0, 1),
// blurRadius: 2,
// ),
// ],
boxShadow: [
if (!isSmall)
BoxShadow(
color: Colors.black.withOpacity(0.1),
offset: const Offset(0, 1),
blurRadius: 2,
),
],
),
height: isSmall ? 120 : 160,
width: isSmall ? 120 : 160,
Expand Down Expand Up @@ -280,7 +268,7 @@ class UserHomeCard extends HookConsumerWidget {
bottom: 0,
left: 180,
child: Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 0, 16),
padding: const EdgeInsets.all(12),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -384,10 +372,10 @@ class UserHomeCard extends HookConsumerWidget {
)
],
),
),
if (!isSmall)
)
else if (userData.description != null)
Padding(
padding: const EdgeInsets.fromLTRB(212, 10, 24, 10),
padding: const EdgeInsets.fromLTRB(190, 10, 24, 10),
child: LayoutBuilder(
builder: (context, constraints) {
return ConstrainedBox(
Expand All @@ -400,7 +388,7 @@ class UserHomeCard extends HookConsumerWidget {
.style
.copyWith(fontSize: 13),
child: MFMText(
text: userData.description ?? "这个用户什么都没有写",
text: userData.description!,
bigEmojiCode: false,
emojis: userData.emojis,
currentServerHost: userData.host,
Expand All @@ -417,28 +405,29 @@ class UserHomeCard extends HookConsumerWidget {
color: themes.dividerColor,
),
if (isSmall) ...[
Padding(
padding: const EdgeInsets.all(12),
child: Column(
children: [
Align(
alignment: Alignment.center,
child: DefaultTextStyle(
style: DefaultTextStyle.of(context)
.style
.copyWith(fontSize: 13),
child: MFMText(
text: userData.description ?? "这个用户什么都没有写",
bigEmojiCode: false,
emojis: userData.emojis,
textAlign: TextAlign.center,
currentServerHost: userData.host,
if (userData.description != null)
Padding(
padding: const EdgeInsets.all(12),
child: Column(
children: [
Align(
alignment: Alignment.center,
child: DefaultTextStyle(
style: DefaultTextStyle.of(context)
.style
.copyWith(fontSize: 13),
child: MFMText(
text: userData.description!,
bigEmojiCode: false,
emojis: userData.emojis,
textAlign: TextAlign.center,
currentServerHost: userData.host,
),
),
),
),
],
],
),
),
),
Container(
height: 1,
color: themes.dividerColor,
Expand Down
30 changes: 17 additions & 13 deletions lib/pages/users/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ import '../../state/themes.dart';
class UserPage extends HookConsumerWidget {
const UserPage({
super.key,
required this.userId,
this.username,
this.host,
this.userId,
});
final String userId;
final String? username;
final String? host;
final String? userId;
@override
Widget build(BuildContext context, WidgetRef ref) {
var padding = MediaQuery.paddingOf(context);
var themes = ref.watch(themeColorsProvider);
var userProvider = userInfoProvider(userId: userId);
var userProvider =
userInfoProvider(username: username, host: host, userId: this.userId);
var user = ref.watch(userProvider);
if (user.isLoading) {
return MkScaffold(
Expand Down Expand Up @@ -59,7 +63,7 @@ class UserPage extends HookConsumerWidget {
));
}
var userData = user.valueOrNull;

var userId = userData!.id;
logger.d(user);
var tabs = [
const Tab(
Expand All @@ -84,7 +88,7 @@ class UserPage extends HookConsumerWidget {
],
),
),
if (userData?.publicReactions ?? false)
if (userData.publicReactions)
const Tab(
child: Row(
children: [
Expand Down Expand Up @@ -112,7 +116,7 @@ class UserPage extends HookConsumerWidget {
children: [
KeepAliveWrapper(child: UserOverview(userId: userId)),
KeepAliveWrapper(child: UserNotesPage(userId: userId)),
if (userData?.publicReactions ?? false)
if (userData.publicReactions)
KeepAliveWrapper(child: UserReactionsPage(userId: userId)),
// Text("data"),
],
Expand All @@ -129,7 +133,7 @@ class UserPage extends HookConsumerWidget {
width: 32,
height: 32,
child: MkImage(
userData?.avatarUrl ?? "",
userData.avatarUrl ?? "",
width: 32,
height: 32,
shape: BoxShape.circle,
Expand All @@ -149,8 +153,8 @@ class UserPage extends HookConsumerWidget {
.style
.copyWith(fontWeight: FontWeight.bold),
child: MFMText(
text: userData?.name ?? userData?.username ?? "",
emojis: userData?.emojis,
text: userData.name ?? userData.username,
emojis: userData.emojis,
maxLines: 1,
overflow: TextOverflow.ellipsis,
bigEmojiCode: false,
Expand All @@ -167,12 +171,12 @@ class UserPage extends HookConsumerWidget {
TextSpan(
children: [
TextSpan(
text: "@${userData?.username ?? ""}",
text: "@${userData.username}",
style:
textStyle.copyWith(fontSize: 12)),
TextSpan(
text: userData?.host != null
? "@${userData?.host}"
text: userData.host != null
? "@${userData.host}"
: "",
style: textStyle.copyWith(
color:
Expand Down
Loading

0 comments on commit b571d93

Please sign in to comment.