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

UserNotesでローカルのuserIdからuserInfoをとるように #284

Merged
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
135 changes: 75 additions & 60 deletions lib/view/user_page/user_notes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import 'package:misskey_dart/misskey_dart.dart';

class UserNotes extends ConsumerStatefulWidget {
final String userId;

final String? remoteUserId;
final Account? actualAccount;

const UserNotes(
{super.key, required this.userId, required this.actualAccount});
const UserNotes({
super.key,
required this.userId,
this.remoteUserId,
this.actualAccount,
}) : assert((remoteUserId == null) == (actualAccount == null));

@override
ConsumerState<ConsumerStatefulWidget> createState() => UserNotesState();
Expand Down Expand Up @@ -63,85 +67,96 @@ class UserNotesState extends ConsumerState<UserNotes> {
},
children: const [
Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("返信つき")),
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("返信つき"),
),
Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("ファイルつき")),
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("ファイルつき"),
),
Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("リノートも"))
padding: EdgeInsets.only(left: 5, right: 5),
child: Text("リノートも"),
),
],
),
),
),
IconButton(
onPressed: () async {
final firstDate = widget.actualAccount == null
? ref
.read(userInfoProvider(widget.userId))
?.response
?.createdAt
: ref
.read(userInfoProvider(widget.userId))
?.remoteResponse
?.createdAt;
onPressed: () async {
final userInfo = ref.read(userInfoProvider(widget.userId));
final firstDate = widget.actualAccount == null
? userInfo?.response?.createdAt
: userInfo?.remoteResponse?.createdAt;

final result = await showDatePicker(
context: context,
initialDate: untilDate ?? DateTime.now(),
helpText: "この日までを表示",
firstDate: firstDate ?? DateTime.now(),
lastDate: DateTime.now());
if (result != null) {
untilDate = DateTime(result.year, result.month,
result.day, 23, 59, 59, 999);
}
setState(() {});
},
icon: const Icon(Icons.date_range))
final result = await showDatePicker(
context: context,
initialDate: untilDate ?? DateTime.now(),
helpText: "この日までを表示",
firstDate: firstDate ?? DateTime.now(),
lastDate: DateTime.now(),
);
if (result != null) {
untilDate = DateTime(
result.year,
result.month,
result.day,
23,
59,
59,
999,
);
}
setState(() {});
},
icon: const Icon(Icons.date_range),
),
],
),
),
Expanded(
child: PushableListView<Note>(
listKey:
Object.hashAll([isFileOnly, withReply, renote, untilDate]),
initializeFuture: () async {
final notes = await misskey.users.notes(UsersNotesRequest(
userId: widget.userId,
listKey: Object.hashAll([isFileOnly, withReply, renote, untilDate]),
initializeFuture: () async {
final notes = await misskey.users.notes(
UsersNotesRequest(
userId: widget.remoteUserId ?? widget.userId,
withFiles: isFileOnly,
includeReplies: withReply,
includeMyRenotes: renote,
untilDate: untilDate?.millisecondsSinceEpoch,
));
if (!mounted) return [];
ref
.read(notesProvider(AccountScope.of(context)))
.registerAll(notes);
return notes.toList();
},
nextFuture: (lastElement, _) async {
final notes = await misskey.users.notes(UsersNotesRequest(
userId: widget.userId,
),
);
if (!mounted) return [];
ref
.read(notesProvider(AccountScope.of(context)))
.registerAll(notes);
return notes.toList();
},
nextFuture: (lastElement, _) async {
final notes = await misskey.users.notes(
UsersNotesRequest(
userId: widget.remoteUserId ?? widget.userId,
untilId: lastElement.id,
withFiles: isFileOnly,
includeReplies: withReply,
includeMyRenotes: renote,
untilDate: untilDate?.millisecondsSinceEpoch,
));
if (!mounted) return [];
ref
.read(notesProvider(AccountScope.of(context)))
.registerAll(notes);
return notes.toList();
},
itemBuilder: (context, element) {
return MisskeyNote(
note: element,
loginAs: widget.actualAccount,
);
}),
),
);
if (!mounted) return [];
ref
.read(notesProvider(AccountScope.of(context)))
.registerAll(notes);
return notes.toList();
},
itemBuilder: (context, element) {
return MisskeyNote(
note: element,
loginAs: widget.actualAccount,
);
},
),
),
],
);
Expand Down
62 changes: 35 additions & 27 deletions lib/view/user_page/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ class UserPageState extends ConsumerState<UserPage> {
bottom: TabBar(
tabs: [
Tab(
text:
"アカウント情報${userInfo?.remoteResponse != null ? "(ローカル)" : ""}"),
text:
"アカウント情報${userInfo?.remoteResponse != null ? "(ローカル)" : ""}",
),
if (isRemoteUser) const Tab(text: "アカウント情報(リモート)"),
Tab(
text:
"ノート${userInfo?.remoteResponse != null ? "(ローカル)" : ""}"),
text:
"ノート${userInfo?.remoteResponse != null ? "(ローカル)" : ""}",
),
if (isRemoteUser) const Tab(text: "ノート(リモート)"),
const Tab(text: "クリップ"),
if (isReactionAvailable) const Tab(text: "リアクション"),
Expand Down Expand Up @@ -99,7 +101,6 @@ class UserPageState extends ConsumerState<UserPage> {
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserNotes(
userId: widget.userId,
actualAccount: null,
),
),
if (isRemoteUser)
Expand All @@ -108,35 +109,39 @@ class UserPageState extends ConsumerState<UserPage> {
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserNotes(
userId: userInfo.remoteResponse!.id,
userId: widget.userId,
remoteUserId: userInfo.remoteResponse!.id,
actualAccount: widget.account,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserClips(
userId: widget.userId,
)),
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserClips(
userId: widget.userId,
),
),
if (isReactionAvailable)
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserReactions(userId: widget.userId)),
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserReactions(userId: widget.userId),
),
if (isRemoteUser)
AccountScope(
account: Account.demoAccount(userInfo!.response!.host!),
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child:
UserPlays(userId: userInfo.remoteResponse!.id)),
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserPlays(userId: userInfo.remoteResponse!.id),
),
)
else
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserPlays(userId: widget.userId)),
padding: const EdgeInsets.only(left: 10, right: 10),
child: UserPlays(userId: widget.userId),
),
],
),
)
),
],
),
),
Expand Down Expand Up @@ -178,18 +183,20 @@ class UserDetailTabState extends ConsumerState<UserDetailTab> {
.read(notesProvider(account))
.registerAll(response?.pinnedNotes ?? []);
ref.read(userInfoProvider(widget.userId).notifier).state = UserInfo(
userId: widget.userId,
response: response,
remoteUserId: null,
remoteResponse: null);
userId: widget.userId,
response: response,
remoteUserId: null,
remoteResponse: null,
);

final remoteHost = response?.host;
if (remoteHost != null) {
final remoteResponse = await ref
.read(misskeyProvider(Account.demoAccount(remoteHost)))
.users
.showByName(
UsersShowByUserNameRequest(userName: response!.username));
UsersShowByUserNameRequest(userName: response!.username),
);

await ref
.read(emojiRepositoryProvider(Account.demoAccount(remoteHost)))
Expand All @@ -199,10 +206,11 @@ class UserDetailTabState extends ConsumerState<UserDetailTab> {
.read(notesProvider(Account.demoAccount(remoteHost)))
.registerAll(remoteResponse.pinnedNotes ?? []);
ref.read(userInfoProvider(widget.userId).notifier).state = UserInfo(
userId: widget.userId,
response: response,
remoteUserId: remoteResponse.id,
remoteResponse: remoteResponse);
userId: widget.userId,
response: response,
remoteUserId: remoteResponse.id,
remoteResponse: remoteResponse,
);
}
} catch (e) {
setState(() {
Expand Down