这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: show online status #574

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

Merged
merged 3 commits into from
Mar 16, 2025
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
1 change: 1 addition & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ showMenuButtonInTabBar: "Show menu button in tab bar"
showNoteCreatedAt: "Show creation date of notes"
showNoteFooter: "Show action buttons in notes"
showNoteReactionsViewer: "Show reactions viewers in notes"
showOnlineStatus: "Show online status"
showPopupOnNewNote: "Show popup on new note"
showQuoteButtonInNoteFooter: "Add \"Quote\" to note action menu"
showReactionsCountForEachTypes: "See the number of reactions for each reaction types"
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 31
/// Strings: 57343 (1849 per locale)
/// Strings: 57344 (1849 per locale)

// coverage:ignore-file
// ignore_for_file: type=lint, unused_import
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class TranslationsAriaEnUs {
String get showNoteCreatedAt => 'Show creation date of notes';
String get showNoteFooter => 'Show action buttons in notes';
String get showNoteReactionsViewer => 'Show reactions viewers in notes';
String get showOnlineStatus => 'Show online status';
String get showPopupOnNewNote => 'Show popup on new note';
String get showQuoteButtonInNoteFooter => 'Add "Quote" to note action menu';
String get showReactionsCountForEachTypes => 'See the number of reactions for each reaction types';
Expand Down
1 change: 1 addition & 0 deletions lib/model/general_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ abstract class GeneralSettings with _$GeneralSettings {
@Default(false) bool enableEmojiFadeIn,
@Default(false) bool forceShowAds,
@Default(false) bool useGroupedNotifications,
@Default(false) bool showOnlineStatus,
@Default(false) bool showTimelineTabBarAtBottom,
@Default(false) bool showMenuButtonInTabBar,
@Default(defaultTimelinesPageButtonTypes)
Expand Down
27 changes: 15 additions & 12 deletions lib/model/general_settings.freezed.dart

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/model/general_settings.g.dart

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

5 changes: 5 additions & 0 deletions lib/provider/general_settings_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ class GeneralSettingsNotifier extends _$GeneralSettingsNotifier {
await _save();
}

Future<void> setShowOnlineStatus(bool showOnlineStatus) async {
state = state.copyWith(showOnlineStatus: showOnlineStatus);
await _save();
}

Future<void> setShowTimelineTabBarAtBottom(
bool showTimelineTabBarAtBottom,
) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/general_settings_notifier_provider.g.dart

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

1 change: 1 addition & 0 deletions lib/view/page/clip_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class _ClipDescription extends ConsumerWidget {
account: account,
user: user,
size: 32.0,
showOnlineIndicator: true,
onTap: () => context.push('/$account/users/${user.id}'),
),
const SizedBox(width: 4.0),
Expand Down
14 changes: 14 additions & 0 deletions lib/view/page/settings/appearance_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ class AppearancePage extends HookConsumerWidget {
),
),
),
Center(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
width: maxContentWidth,
child: SwitchListTile(
title: Text(t.aria.showOnlineStatus),
value: settings.showOnlineStatus,
onChanged:
(value) => ref
.read(generalSettingsNotifierProvider.notifier)
.setShowOnlineStatus(value),
),
),
),
Center(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
Expand Down
1 change: 1 addition & 0 deletions lib/view/page/settings/blocked_users_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BlockedUsersPage extends ConsumerWidget {
account: account,
user: blocking.blockee,
size: 32.0,
showOnlineIndicator: true,
),
title: UsernameWidget(account: account, user: blocking.blockee),
subtitle: Column(
Expand Down
1 change: 1 addition & 0 deletions lib/view/page/settings/muted_users_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MutedUsersPage extends ConsumerWidget {
account: account,
user: muting.mutee,
size: 32.0,
showOnlineIndicator: true,
),
title: UsernameWidget(account: account, user: muting.mutee),
subtitle: Column(
Expand Down
4 changes: 1 addition & 3 deletions lib/view/page/settings/note_display_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,7 @@ class NoteDisplayPage extends HookConsumerWidget {
onTap: () async {
final result = await showRadioDialog(
context,
title: Text(
t.misskey.mediaListWithOneImageAppearance,
),
title: Text(t.aria.displayOfThumbnail),
values: [BoxFit.contain, BoxFit.cover],
initialValue: settings.thumbnailBoxFit,
itemBuilder:
Expand Down
1 change: 1 addition & 0 deletions lib/view/page/settings/renote_muted_users_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RenoteMutedUsersPage extends ConsumerWidget {
account: account,
user: renoteMuting.mutee,
size: 32.0,
showOnlineIndicator: true,
),
title: UsernameWidget(account: account, user: renoteMuting.mutee),
subtitle: Column(
Expand Down
20 changes: 7 additions & 13 deletions lib/view/page/user/user_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class _UserHome extends ConsumerWidget {
account: account,
user: user,
size: 100.0,
showOnlineIndicator: true,
onTap:
() => showImageDialog(
context,
Expand Down Expand Up @@ -484,19 +485,12 @@ class _UserHome extends ConsumerWidget {
(context) =>
UrlSheet(url: link.url),
),
child:
link.imgSrc != null
? ImageWidget(
url: link.imgSrc!,
width: 200.0,
height: 40.0,
semanticLabel:
link.description,
)
: const SizedBox(
width: 200.0,
height: 40.0,
),
child: ImageWidget(
url: link.imgSrc,
width: 200.0,
height: 40.0,
semanticLabel: link.description,
),
),
)
.toList(),
Expand Down
85 changes: 33 additions & 52 deletions lib/view/widget/cat_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:misskey_dart/misskey_dart.dart';

import '../../model/account.dart';
import '../../provider/average_color_provider.dart';
import '../../provider/data_saver_provider.dart';
import '../../provider/general_settings_notifier_provider.dart';
import '../../provider/static_image_url_provider.dart';
import 'avatar_decorations.dart';
import 'cat_ear.dart';
import 'image_widget.dart';
import 'online_indicator.dart';

final _catEarWiggleTween = TweenSequence([
TweenSequenceItem(
Expand All @@ -28,50 +24,36 @@ final _catEarWiggleTween = TweenSequence([
TweenSequenceItem(tween: Tween(begin: 0.0, end: 0.65624379), weight: 25),
]);

class CatAvatar extends HookConsumerWidget {
class CatAvatar extends HookWidget {
const CatAvatar({
super.key,
required this.account,
required this.user,
required this.url,
required this.blurHash,
required this.catEarColor,
required this.showAvatarDecorations,
required this.decorations,
required this.showOnlineStatus,
required this.onlineStatus,
required this.size,
this.decorations,
this.forceShowDecoration = false,
this.onTap,
required this.borderRadius,
required this.onTap,
});

final Account account;
final User user;
final Uri? url;
final String? blurHash;
final Color catEarColor;
final bool showAvatarDecorations;
final List<UserAvatarDecoration> decorations;
final bool showOnlineStatus;
final OnlineStatus? onlineStatus;
final double size;
final List<UserAvatarDecoration>? decorations;
final bool forceShowDecoration;
final BorderRadius borderRadius;
final void Function()? onTap;

@override
Widget build(BuildContext context, WidgetRef ref) {
final (
showAvatarDecorations,
squareAvatars,
disableShowingAnimatedImages,
) = ref.watch(
generalSettingsNotifierProvider.select(
(settings) => (
settings.showAvatarDecorations,
settings.squareAvatars,
settings.disableShowingAnimatedImages,
),
),
);
final useStaticImage =
disableShowingAnimatedImages ||
ref.watch(dataSaverProvider.select((dataSaver) => dataSaver.avatar));
final borderRadius = BorderRadius.circular(
squareAvatars ? size * 0.2 : size,
);
final blurHash = user.avatarBlurhash;
final catEarColor =
blurHash != null
? ref.watch(averageColorProvider(blurHash))
: Theme.of(context).colorScheme.primary;
Widget build(BuildContext context) {
final controller = useAnimationController(
duration: const Duration(seconds: 1),
);
Expand Down Expand Up @@ -138,29 +120,28 @@ class CatAvatar extends HookConsumerWidget {
ClipRRect(
borderRadius: borderRadius,
child: ImageWidget(
url:
useStaticImage
? ref
.watch(
staticImageUrlProvider(
account.host,
user.avatarUrl.toString(),
),
)
.toString()
: user.avatarUrl.toString(),
blurHash: user.avatarBlurhash,
url: url?.toString(),
blurHash: blurHash,
height: size,
width: size,
fit: BoxFit.cover,
),
),
if (forceShowDecoration || showAvatarDecorations)
if (showAvatarDecorations)
AvatarDecorations(
account: account,
decorations: decorations ?? user.avatarDecorations,
decorations: decorations,
size: size,
),
if (showOnlineStatus)
Positioned(
left: 0.0,
bottom: 0.0,
child: OnlineIndicator(
onlineStatus: onlineStatus,
size: size * 0.2,
),
),
],
),
),
Expand Down
5 changes: 3 additions & 2 deletions lib/view/widget/image_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ImageWidget extends ConsumerWidget {
this.enableFadeIn = true,
});

final String url;
final String? url;
final String? blurHash;
final double? width;
final double? height;
Expand All @@ -46,7 +46,8 @@ class ImageWidget extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
if (url.isEmpty) {
final url = this.url;
if (url == null || url.isEmpty) {
return _buildPlaceholder();
}
if (url.startsWith('data')) {
Expand Down
1 change: 1 addition & 0 deletions lib/view/widget/note_detailed_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class _NoteDetailedContent extends HookConsumerWidget {
account: account,
user: appearNote.user,
size: style.lineHeight * avatarScale,
showOnlineIndicator: true,
onTap: () => context.push('/$account/users/${appearNote.userId}'),
),
const SizedBox(width: 8.0),
Expand Down
44 changes: 44 additions & 0 deletions lib/view/widget/online_indicator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:misskey_dart/misskey_dart.dart';

import '../../i18n/strings.g.dart';

class OnlineIndicator extends StatelessWidget {
const OnlineIndicator({
super.key,
required this.onlineStatus,
required this.size,
});

final OnlineStatus? onlineStatus;
final double size;

@override
Widget build(BuildContext context) {
return Tooltip(
message: switch (onlineStatus) {
OnlineStatus.online => t.misskey.online,
OnlineStatus.active => t.misskey.active,
OnlineStatus.offline => t.misskey.offline,
OnlineStatus.unknown || null => t.misskey.unknown,
},
child: DecoratedBox(
decoration: BoxDecoration(
color: switch (onlineStatus) {
OnlineStatus.online => const Color(0xff58d4c9),
OnlineStatus.active => const Color(0xffe4bc48),
OnlineStatus.offline => const Color(0xffea5353),
OnlineStatus.unknown || null => const Color(0xff888888),
},
border: Border.all(
color: Theme.of(context).colorScheme.surface,
width: 3.0,
strokeAlign: BorderSide.strokeAlignOutside,
),
shape: BoxShape.circle,
),
child: SizedBox.square(dimension: size),
),
);
}
}
Loading
Loading