Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon committed Nov 24, 2023
1 parent 4b49524 commit fff597b
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 304 deletions.
7 changes: 0 additions & 7 deletions lib/extensions/users_show_response_extension.dart

This file was deleted.

6 changes: 3 additions & 3 deletions lib/model/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Account with _$Account {
required String host,
required String userId,
String? token,
required IResponse i,
required MeDetailed i,
}) = _Account;

factory Account.fromJson(Map<String, Object?> json) =>
Expand Down Expand Up @@ -41,7 +41,7 @@ class Account with _$Account {
host: host,
userId: "",
token: null,
i: IResponse(
i: MeDetailed(
id: "",
username: "",
createdAt: DateTime.now(),
Expand All @@ -56,7 +56,7 @@ class Account with _$Account {
followersCount: 0,
notesCount: 0,
publicReactions: false,
ffVisibility: "",
ffVisibility: FFVisibility.public,
twoFactorEnabled: false,
usePasswordLessLogin: false,
securityKeys: false,
Expand Down
24 changes: 12 additions & 12 deletions lib/model/account.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mixin _$Account {
String get host => throw _privateConstructorUsedError;
String get userId => throw _privateConstructorUsedError;
String? get token => throw _privateConstructorUsedError;
IResponse get i => throw _privateConstructorUsedError;
MeDetailed get i => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -35,9 +35,9 @@ abstract class $AccountCopyWith<$Res> {
factory $AccountCopyWith(Account value, $Res Function(Account) then) =
_$AccountCopyWithImpl<$Res, Account>;
@useResult
$Res call({String host, String userId, String? token, IResponse i});
$Res call({String host, String userId, String? token, MeDetailed i});

$IResponseCopyWith<$Res> get i;
$MeDetailedCopyWith<$Res> get i;
}

/// @nodoc
Expand Down Expand Up @@ -74,14 +74,14 @@ class _$AccountCopyWithImpl<$Res, $Val extends Account>
i: null == i
? _value.i
: i // ignore: cast_nullable_to_non_nullable
as IResponse,
as MeDetailed,
) as $Val);
}

@override
@pragma('vm:prefer-inline')
$IResponseCopyWith<$Res> get i {
return $IResponseCopyWith<$Res>(_value.i, (value) {
$MeDetailedCopyWith<$Res> get i {
return $MeDetailedCopyWith<$Res>(_value.i, (value) {
return _then(_value.copyWith(i: value) as $Val);
});
}
Expand All @@ -94,10 +94,10 @@ abstract class _$$AccountImplCopyWith<$Res> implements $AccountCopyWith<$Res> {
__$$AccountImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String host, String userId, String? token, IResponse i});
$Res call({String host, String userId, String? token, MeDetailed i});

@override
$IResponseCopyWith<$Res> get i;
$MeDetailedCopyWith<$Res> get i;
}

/// @nodoc
Expand Down Expand Up @@ -132,7 +132,7 @@ class __$$AccountImplCopyWithImpl<$Res>
i: null == i
? _value.i
: i // ignore: cast_nullable_to_non_nullable
as IResponse,
as MeDetailed,
));
}
}
Expand All @@ -154,7 +154,7 @@ class _$AccountImpl extends _Account {
@override
final String? token;
@override
final IResponse i;
final MeDetailed i;

@override
String toString() {
Expand All @@ -180,7 +180,7 @@ abstract class _Account extends Account {
{required final String host,
required final String userId,
final String? token,
required final IResponse i}) = _$AccountImpl;
required final MeDetailed i}) = _$AccountImpl;
const _Account._() : super._();

factory _Account.fromJson(Map<String, dynamic> json) = _$AccountImpl.fromJson;
Expand All @@ -192,7 +192,7 @@ abstract class _Account extends Account {
@override
String? get token;
@override
IResponse get i;
MeDetailed get i;
@override
@JsonKey(ignore: true)
_$$AccountImplCopyWith<_$AccountImpl> get copyWith =>
Expand Down
2 changes: 1 addition & 1 deletion lib/model/account.g.dart

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

Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
}
final deletedNoteChannel = note.channel;

final replyTo = <User>[];
if (note.mentions.isNotEmpty) {
replyTo.addAll(
await misskey.users
.showByIds(UsersShowByIdsRequest(userIds: note.mentions)),
);
}

resultState = resultState.copyWith(
noteVisibility: note.visibility,
localOnly: note.localOnly,
Expand All @@ -193,11 +201,7 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
isCw: note.cw?.isNotEmpty == true,
text: note.text ?? "",
reactionAcceptance: note.reactionAcceptance,
replyTo: [
for (final userId in note.mentions)
(await misskey.users.show(UsersShowRequest(userId: userId)))
.toUser()
],
replyTo: replyTo.toList(),
isVote: note.poll != null,
isVoteMultiple: note.poll?.multiple ?? false,
voteExpireType: note.poll?.expiresAt == null
Expand All @@ -223,6 +227,14 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
}

if (reply != null) {
final replyTo = <User>[];
if (reply.mentions.isNotEmpty) {
replyTo.addAll(
await misskey.users
.showByIds(UsersShowByIdsRequest(userIds: reply.mentions)),
);
}

resultState = resultState.copyWith(
reply: reply,
noteVisibility:
Expand All @@ -231,9 +243,7 @@ class NoteCreateNotifier extends StateNotifier<NoteCreate> {
isCw: reply.cw?.isNotEmpty == true,
replyTo: [
reply.user,
for (final userId in reply.mentions)
(await misskey.users.show(UsersShowRequest(userId: userId)))
.toUser()
...replyTo,
]..removeWhere((element) => element.id == state.account.i.id),
);
}
Expand Down
33 changes: 0 additions & 33 deletions lib/view/common/avatar_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,6 @@ class AvatarIcon extends StatefulWidget {
this.onTap,
});

factory AvatarIcon.fromIResponse(IResponse response, {double height = 48}) {
return AvatarIcon(
user: User(
id: response.id,
username: response.username,
avatarUrl: response.avatarUrl,
avatarBlurhash: response.avatarBlurhash,
avatarDecorations: response.avatarDecorations,
isCat: response.isCat,
isBot: response.isBot,
),
height: height,
);
}

factory AvatarIcon.fromUserResponse(
UsersShowResponse response, {
double height = 48,
}) {
return AvatarIcon(
user: User(
id: response.id,
username: response.username,
avatarUrl: response.avatarUrl,
avatarBlurhash: response.avatarBlurhash,
avatarDecorations: response.avatarDecorations,
isCat: response.isCat,
isBot: response.isBot,
),
height: height,
);
}

@override
State<StatefulWidget> createState() => AvatarIconState();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/view/common/common_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CommonDrawer extends ConsumerWidget {
AccountScope(
account: account,
child: ExpansionTile(
leading: AvatarIcon.fromIResponse(account.i),
leading: AvatarIcon(user: account.i),
initiallyExpanded: account.acct == initialOpenAcct,
title: SimpleMfmText(
account.i.name ?? account.i.username,
Expand Down
2 changes: 1 addition & 1 deletion lib/view/common/misskey_notes/open_another_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AccountSelectDialog extends ConsumerWidget {
AccountScope(
account: account,
child: ListTile(
leading: AvatarIcon.fromIResponse(account.i),
leading: AvatarIcon(user: account.i),
title: SimpleMfmText(account.i.name ?? account.i.username,
style: Theme.of(context).textTheme.titleMedium),
subtitle: Text(
Expand Down
4 changes: 2 additions & 2 deletions lib/view/note_create_page/note_create_setting_top.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class NoteCreateSettingTop extends ConsumerWidget {
return Row(
children: [
const Padding(padding: EdgeInsets.only(left: 5)),
AvatarIcon.fromIResponse(
AccountScope.of(context).i,
AvatarIcon(
user: AccountScope.of(context).i,
height:
Theme.of(context).iconButtonTheme.style?.iconSize?.resolve({}) ??
32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AccountListItem extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return ListTile(
leading: AvatarIcon.fromIResponse(account.i),
leading: AvatarIcon(user: account.i),
title: Text(
account.i.name ?? account.i.username,
style: Theme.of(context).textTheme.titleMedium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class HardMutePageState extends ConsumerState<HardMutePage> {
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10),
child: CommonFuture<IResponse>(
child: CommonFuture<MeDetailed>(
future: ref.read(misskeyProvider(widget.account)).i.i(),
futureFinished: (data) {
controller.text = muteValueString(data.mutedWords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class InstanceMutePageState extends ConsumerState<InstanceMutePage> {
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(10),
child: CommonFuture<IResponse>(
child: CommonFuture<MeDetailed>(
future: ref.read(misskeyProvider(widget.account)).i.i(),
futureFinished: (data) {
controller.text = data.mutedInstances.join("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SharingAccountSelectPage extends ConsumerWidget {
initialMediaFiles: filePath,
));
},
leading: AvatarIcon.fromIResponse(account.i),
leading: AvatarIcon(user: account.i),
title: Text(account.i.name ?? account.i.username,
style: Theme.of(context).textTheme.titleMedium),
subtitle: Text(
Expand Down
23 changes: 11 additions & 12 deletions lib/view/user_page/user_control_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:miria/extensions/users_show_response_extension.dart';
import 'package:miria/extensions/user_extension.dart';
import 'package:miria/model/account.dart';
import 'package:miria/providers.dart';
import 'package:miria/view/common/error_dialog_handler.dart';
Expand All @@ -21,14 +21,12 @@ enum UserControl {

class UserControlDialog extends ConsumerStatefulWidget {
final Account account;
final UsersShowResponse response;
final bool isMe;
final UserDetailed response;

const UserControlDialog({
super.key,
required this.account,
required this.response,
required this.isMe,
});

@override
Expand Down Expand Up @@ -138,6 +136,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {

@override
Widget build(BuildContext context) {
final user = widget.response;
return ListView(children: [
ListTile(
onTap: () {
Expand All @@ -146,7 +145,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
text: Uri(
scheme: "https",
host: widget.account.host,
path: widget.response.acct,
path: user.acct,
).toString(),
),
);
Expand All @@ -161,7 +160,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
onTap: () {
Clipboard.setData(
ClipboardData(
text: widget.response.name ?? widget.response.username,
text: user.name ?? user.username,
),
);
ScaffoldMessenger.of(context).showSnackBar(
Expand All @@ -173,7 +172,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
),
ListTile(
onTap: () {
Clipboard.setData(ClipboardData(text: widget.response.acct));
Clipboard.setData(ClipboardData(text: user.acct));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("コピーしました")),
);
Expand All @@ -188,7 +187,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
Uri(
scheme: "https",
host: widget.account.host,
path: widget.response.acct,
path: user.acct,
),
);
Navigator.of(context).pop();
Expand All @@ -202,8 +201,8 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
onTap: addToAntenna,
title: const Text("アンテナに追加"),
),
if (!widget.isMe) ...[
if (widget.response.isRenoteMuted ?? false)
if (user is UserDetailedNotMeWithRelations) ...[
if (user.isRenoteMuted)
ListTile(
onTap: renoteMuteDelete.expectFailure(context),
title: const Text("Renoteのミュート解除する"),
Expand All @@ -213,7 +212,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
onTap: renoteMuteCreate.expectFailure(context),
title: const Text("Renoteをミュートする"),
),
if (widget.response.isMuted ?? false)
if (user.isMuted)
ListTile(
onTap: muteDelete.expectFailure(context),
title: const Text("ミュート解除する"),
Expand All @@ -223,7 +222,7 @@ class UserControlDialogState extends ConsumerState<UserControlDialog> {
onTap: muteCreate.expectFailure(context),
title: const Text("ミュートする"),
),
if (widget.response.isBlocking ?? false)
if (user.isBlocking)
ListTile(
onTap: blockingDelete.expectFailure(context),
title: const Text("ブロックを解除する"),
Expand Down
Loading

0 comments on commit fff597b

Please sign in to comment.