Skip to content

Commit

Permalink
Merge pull request #328 from tacko-o/role_timeline
Browse files Browse the repository at this point in the history
ロールタイムラインタブを追加できるように #327
  • Loading branch information
shiosyakeyakini-info authored Oct 1, 2023
2 parents e0f7d58 + df5c0a7 commit 203bf97
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ app.*.map.json

# builder
**/node_modules/
**/build/

# Release
/private_keys/
3 changes: 3 additions & 0 deletions lib/model/tab_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class TabSetting with _$TabSetting {
/// タブ種別
required TabType tabType,

/// ロールタイムラインのノートの場合、ロールID
String? roleId,

/// チャンネルのノートの場合、チャンネルID
String? channelId,

Expand Down
29 changes: 28 additions & 1 deletion lib/model/tab_setting.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ mixin _$TabSetting {
/// タブ種別
TabType get tabType => throw _privateConstructorUsedError;

/// ロールタイムラインのノートの場合、ロールID
String? get roleId => throw _privateConstructorUsedError;

/// チャンネルのノートの場合、チャンネルID
String? get channelId => throw _privateConstructorUsedError;

Expand Down Expand Up @@ -60,6 +63,7 @@ abstract class $TabSettingCopyWith<$Res> {
$Res call(
{@IconDataConverter() TabIcon icon,
TabType tabType,
String? roleId,
String? channelId,
String? listId,
String? antennaId,
Expand Down Expand Up @@ -87,6 +91,7 @@ class _$TabSettingCopyWithImpl<$Res, $Val extends TabSetting>
$Res call({
Object? icon = null,
Object? tabType = null,
Object? roleId = freezed,
Object? channelId = freezed,
Object? listId = freezed,
Object? antennaId = freezed,
Expand All @@ -104,6 +109,10 @@ class _$TabSettingCopyWithImpl<$Res, $Val extends TabSetting>
? _value.tabType
: tabType // ignore: cast_nullable_to_non_nullable
as TabType,
roleId: freezed == roleId
? _value.roleId
: roleId // ignore: cast_nullable_to_non_nullable
as String?,
channelId: freezed == channelId
? _value.channelId
: channelId // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -163,6 +172,7 @@ abstract class _$$_TabSettingCopyWith<$Res>
$Res call(
{@IconDataConverter() TabIcon icon,
TabType tabType,
String? roleId,
String? channelId,
String? listId,
String? antennaId,
Expand Down Expand Up @@ -190,6 +200,7 @@ class __$$_TabSettingCopyWithImpl<$Res>
$Res call({
Object? icon = null,
Object? tabType = null,
Object? roleId = freezed,
Object? channelId = freezed,
Object? listId = freezed,
Object? antennaId = freezed,
Expand All @@ -207,6 +218,10 @@ class __$$_TabSettingCopyWithImpl<$Res>
? _value.tabType
: tabType // ignore: cast_nullable_to_non_nullable
as TabType,
roleId: freezed == roleId
? _value.roleId
: roleId // ignore: cast_nullable_to_non_nullable
as String?,
channelId: freezed == channelId
? _value.channelId
: channelId // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -242,6 +257,7 @@ class _$_TabSetting extends _TabSetting {
const _$_TabSetting(
{@IconDataConverter() required this.icon,
required this.tabType,
this.roleId,
this.channelId,
this.listId,
this.antennaId,
Expand All @@ -262,6 +278,10 @@ class _$_TabSetting extends _TabSetting {
@override
final TabType tabType;

/// ロールタイムラインのノートの場合、ロールID
@override
final String? roleId;

/// チャンネルのノートの場合、チャンネルID
@override
final String? channelId;
Expand Down Expand Up @@ -292,7 +312,7 @@ class _$_TabSetting extends _TabSetting {

@override
String toString() {
return 'TabSetting(icon: $icon, tabType: $tabType, channelId: $channelId, listId: $listId, antennaId: $antennaId, isSubscribe: $isSubscribe, name: $name, account: $account, renoteDisplay: $renoteDisplay)';
return 'TabSetting(icon: $icon, tabType: $tabType, roleId: $roleId, channelId: $channelId, listId: $listId, antennaId: $antennaId, isSubscribe: $isSubscribe, name: $name, account: $account, renoteDisplay: $renoteDisplay)';
}

@override
Expand All @@ -302,6 +322,7 @@ class _$_TabSetting extends _TabSetting {
other is _$_TabSetting &&
(identical(other.icon, icon) || other.icon == icon) &&
(identical(other.tabType, tabType) || other.tabType == tabType) &&
(identical(other.roleId, roleId) || other.roleId == roleId) &&
(identical(other.channelId, channelId) ||
other.channelId == channelId) &&
(identical(other.listId, listId) || other.listId == listId) &&
Expand All @@ -321,6 +342,7 @@ class _$_TabSetting extends _TabSetting {
runtimeType,
icon,
tabType,
roleId,
channelId,
listId,
antennaId,
Expand All @@ -347,6 +369,7 @@ abstract class _TabSetting extends TabSetting {
const factory _TabSetting(
{@IconDataConverter() required final TabIcon icon,
required final TabType tabType,
final String? roleId,
final String? channelId,
final String? listId,
final String? antennaId,
Expand All @@ -368,6 +391,10 @@ abstract class _TabSetting extends TabSetting {
TabType get tabType;
@override

/// ロールタイムラインのノートの場合、ロールID
String? get roleId;
@override

/// チャンネルのノートの場合、チャンネルID
String? get channelId;
@override
Expand Down
3 changes: 3 additions & 0 deletions lib/model/tab_setting.g.dart

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

3 changes: 3 additions & 0 deletions lib/model/tab_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum TabType {
homeTimeline("ホームタイムライン"),
globalTimeline("グローバルタイムライン"),
hybridTimeline("ソーシャルタイムライン"),
roleTimeline("ロールタイムライン"),
channel("チャンネル"),
userList("リスト"),
antenna("アンテナ"),
Expand All @@ -27,6 +28,8 @@ enum TabType {
return globalTimeLineProvider(setting);
case TabType.hybridTimeline:
return hybridTimeLineProvider(setting); //FIXME
case TabType.roleTimeline:
return roleTimelineProvider(setting);
case TabType.channel:
return channelTimelineProvider(setting);
case TabType.userList:
Expand Down
14 changes: 14 additions & 0 deletions lib/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:miria/repository/main_stream_repository.dart';
import 'package:miria/repository/global_time_line_repository.dart';
import 'package:miria/repository/home_time_line_repository.dart';
import 'package:miria/repository/local_time_line_repository.dart';
import 'package:miria/repository/role_timeline_repository.dart';
import 'package:miria/repository/note_repository.dart';
import 'package:miria/repository/tab_settings_repository.dart';
import 'package:miria/repository/time_line_repository.dart';
Expand Down Expand Up @@ -85,6 +86,19 @@ final hybridTimeLineProvider =
ref.read(emojiRepositoryProvider(tabSetting.account)),
));

final roleTimelineProvider =
ChangeNotifierProvider.family<RoleTimelineRepository, TabSetting>(
(ref, tabSetting) => RoleTimelineRepository(
ref.read(misskeyProvider(tabSetting.account)),
ref.read(notesProvider(tabSetting.account)),
ref.read(mainStreamRepositoryProvider(tabSetting.account)),
ref.read(generalSettingsRepositoryProvider),
tabSetting,
ref.read(mainStreamRepositoryProvider(tabSetting.account)),
ref.read(accountRepository),
ref.read(emojiRepositoryProvider(tabSetting.account)),
));

final channelTimelineProvider =
ChangeNotifierProvider.family<ChannelTimelineRepository, TabSetting>(
(ref, tabSetting) => ChannelTimelineRepository(
Expand Down
1 change: 1 addition & 0 deletions lib/repository/account_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class AccountRepository extends ChangeNotifier {
notifyListeners();
}

//一つ目のアカウントが追加されたときに自動で追加されるタブ
Future<void> _addIfTabSettingNothing() async {
if (_account.length == 1) {
final account = _account.first;
Expand Down
41 changes: 41 additions & 0 deletions lib/repository/role_timeline_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'dart:async';

import 'package:miria/repository/socket_timeline_repository.dart';
import 'package:misskey_dart/misskey_dart.dart';

class RoleTimelineRepository extends SocketTimelineRepository {
RoleTimelineRepository(
super.misskey,
super.noteRepository,
super.globalNotificationRepository,
super.generalSettingsRepository,
super.tabSetting,
super.mainStreamRepository,
super.accountRepository,
super.emojiRepository,
);

@override
SocketController createSocketController({
required void Function(Note note) onReceived,
required FutureOr<void> Function(String id, TimelineReacted reaction)
onReacted,
required FutureOr<void> Function(String id, TimelineVoted vote) onVoted,
}) {
return misskey.roleTimelineStream(
roleId: tabSetting.roleId!,
onNoteReceived: onReceived,
onReacted: onReacted,
onVoted: onVoted,
);
}

@override
Future<Iterable<Note>> requestNotes({String? untilId}) async {
return await misskey.roles.notes(RolesNotesRequest(
roleId: tabSetting.roleId!,
limit: 30,
untilId: untilId,
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class IconSelectDialog extends StatelessWidget {
Icons.rocket_outlined,
Icons.rocket_launch,
Icons.rocket_launch_outlined,
Icons.bookmark,
Icons.bookmark_outline,
Icons.hub,
Icons.hub_outlined,
Icons.settings_input_antenna,
Expand Down
71 changes: 71 additions & 0 deletions lib/view/settings_page/tab_settings_page/role_select_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:miria/model/account.dart';
import 'package:miria/providers.dart';
import 'package:miria/view/common/account_scope.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:misskey_dart/misskey_dart.dart';

class RoleSelectDialog extends ConsumerStatefulWidget {
final Account account;

const RoleSelectDialog({super.key, required this.account});

@override
ConsumerState<ConsumerStatefulWidget> createState() =>
RoleSelectDialogState();
}

class RoleSelectDialogState extends ConsumerState<RoleSelectDialog> {
final roles = <RolesListResponse>[];

@override
void didChangeDependencies() {
super.didChangeDependencies();
Future(() async {
final rolesList = await ref
.read(misskeyProvider(widget.account))
.roles
.list();
roles
..clear()
..addAll(rolesList);
setState(() {});
});
}

@override
Widget build(BuildContext context) {
return AccountScope(
account: widget.account,
child: AlertDialog(
title: const Text("ロール選択"),
content: SizedBox(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.8,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"ロール",
style: Theme.of(context).textTheme.titleMedium,
),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: roles.length,
itemBuilder: (context, index) {
return ListTile(
onTap: () {
Navigator.of(context).pop(roles[index]);
},
title: Text(roles[index].name));
}),
],
),
),
),
),
);
}
}
Loading

0 comments on commit 203bf97

Please sign in to comment.