Compare commits
7 Commits
25550ba197
...
2.4.2+78
Author | SHA1 | Date | |
---|---|---|---|
88396647f3 | |||
335318ae3f | |||
da25fb9c29 | |||
c1aef89b84 | |||
0241c5f804 | |||
f6939d7c23 | |||
d654c162e3 |
@ -771,5 +771,25 @@
|
||||
"messageUnablePreviewEncrypted": "Unable preview encrypted message",
|
||||
"postViewInGlobalDescription": "Do not view the post in the specific realm.",
|
||||
"postDraftSaved": "The draft has been saved.",
|
||||
"postDraftBox": "Draft Box"
|
||||
"postDraftBox": "Draft Box",
|
||||
"postShuffle": "Read Randomly",
|
||||
"checkInStreak": {
|
||||
"zero": "No streak",
|
||||
"one": "{} day streak",
|
||||
"other": "{} days streak"
|
||||
},
|
||||
"accountChangeStatus": "Change Status",
|
||||
"accountStatusSilent": "Do not Disturb",
|
||||
"accountStatusSilentDesc": "The notification will stop popping up",
|
||||
"accountStatusInvisible": "Invisible",
|
||||
"accountStatusInvisibleDesc": "Will show as offline, but all features still remain normal",
|
||||
"accountCustomStatus": "Custom Status",
|
||||
"accountCustomStatusDescription": "Customize your status.",
|
||||
"accountClearStatus": "Clear Status",
|
||||
"accountClearStatusDescription": "Clear your status, and let server decide which status you are for you.",
|
||||
"fieldAccountStatusLabel": "Status Text",
|
||||
"fieldAccountStatusClearAt": "Clear At",
|
||||
"accountStatusNegative": "Negative",
|
||||
"accountStatusNeutral": "Neutral",
|
||||
"accountStatusPositive": "Positive"
|
||||
}
|
||||
|
@ -769,5 +769,25 @@
|
||||
"messageUnablePreviewEncrypted": "无法预览加密消息",
|
||||
"postViewInGlobalDescription": "不查看特定领域的帖子。",
|
||||
"postDraftSaved": "已保存为草稿。",
|
||||
"postDraftBox": "草稿箱"
|
||||
"postDraftBox": "草稿箱",
|
||||
"postShuffle": "随便看看",
|
||||
"checkInStreak": {
|
||||
"zero": "无连击",
|
||||
"one": "连续签到 {} 天",
|
||||
"other": "连续签到 {} 天"
|
||||
},
|
||||
"accountChangeStatus": "修改状态",
|
||||
"accountStatusSilent": "请勿打扰",
|
||||
"accountStatusSilentDesc": "将会暂停所有通知推送",
|
||||
"accountStatusInvisible": "隐身",
|
||||
"accountStatusInvisibleDesc": "将会在他人界面显示离线,但不影响功能使用",
|
||||
"accountCustomStatus": "自定义状态",
|
||||
"accountCustomStatusDescription": "客制化你的状态。",
|
||||
"accountClearStatus": "清除状态",
|
||||
"accountClearStatusDescription": "清除你的状态,并让服务器决定你的状态。",
|
||||
"fieldAccountStatusLabel": "状态文字",
|
||||
"fieldAccountStatusClearAt": "清除时间",
|
||||
"accountStatusNegative": "负面",
|
||||
"accountStatusNeutral": "中性",
|
||||
"accountStatusPositive": "正面"
|
||||
}
|
||||
|
@ -769,5 +769,25 @@
|
||||
"messageUnablePreviewEncrypted": "無法預覽加密消息",
|
||||
"postViewInGlobalDescription": "不查看特定領域的帖子。",
|
||||
"postDraftSaved": "已保存為草稿。",
|
||||
"postDraftBox": "草稿箱"
|
||||
"postDraftBox": "草稿箱",
|
||||
"postShuffle": "隨便看看",
|
||||
"checkInStreak": {
|
||||
"zero": "無連擊",
|
||||
"one": "連續簽到 {} 天",
|
||||
"other": "連續簽到 {} 天"
|
||||
},
|
||||
"accountChangeStatus": "修改狀態",
|
||||
"accountStatusSilent": "請勿打擾",
|
||||
"accountStatusSilentDesc": "將會暫停所有通知推送",
|
||||
"accountStatusInvisible": "隱身",
|
||||
"accountStatusInvisibleDesc": "將會在他人界面顯示離線,但不影響功能使用",
|
||||
"accountCustomStatus": "自定義狀態",
|
||||
"accountCustomStatusDescription": "客製化你的狀態。",
|
||||
"accountClearStatus": "清除狀態",
|
||||
"accountClearStatusDescription": "清除你的狀態,並讓服務器決定你的狀態。",
|
||||
"fieldAccountStatusLabel": "狀態文字",
|
||||
"fieldAccountStatusClearAt": "清除時間",
|
||||
"accountStatusNegative": "負面",
|
||||
"accountStatusNeutral": "中性",
|
||||
"accountStatusPositive": "正面"
|
||||
}
|
||||
|
@ -769,5 +769,25 @@
|
||||
"messageUnablePreviewEncrypted": "無法預覽加密消息",
|
||||
"postViewInGlobalDescription": "不查看特定領域的帖子。",
|
||||
"postDraftSaved": "已保存為草稿。",
|
||||
"postDraftBox": "草稿箱"
|
||||
"postDraftBox": "草稿箱",
|
||||
"postShuffle": "隨便看看",
|
||||
"checkInStreak": {
|
||||
"zero": "無連擊",
|
||||
"one": "連續簽到 {} 天",
|
||||
"other": "連續簽到 {} 天"
|
||||
},
|
||||
"accountChangeStatus": "修改狀態",
|
||||
"accountStatusSilent": "請勿打擾",
|
||||
"accountStatusSilentDesc": "將會暫停所有通知推送",
|
||||
"accountStatusInvisible": "隱身",
|
||||
"accountStatusInvisibleDesc": "將會在他人界面顯示離線,但不影響功能使用",
|
||||
"accountCustomStatus": "自定義狀態",
|
||||
"accountCustomStatusDescription": "客製化你的狀態。",
|
||||
"accountClearStatus": "清除狀態",
|
||||
"accountClearStatusDescription": "清除你的狀態,並讓服務器決定你的狀態。",
|
||||
"fieldAccountStatusLabel": "狀態文字",
|
||||
"fieldAccountStatusClearAt": "清除時間",
|
||||
"accountStatusNegative": "負面",
|
||||
"accountStatusNeutral": "中性",
|
||||
"accountStatusPositive": "正面"
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ class $SnLocalChatChannelTable extends SnLocalChatChannel
|
||||
late final GeneratedColumn<String> alias = GeneratedColumn<String>(
|
||||
'alias', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnChannel, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -60,7 +58,6 @@ class $SnLocalChatChannelTable extends SnLocalChatChannel
|
||||
} else if (isInserting) {
|
||||
context.missing(_aliasMeta);
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
|
||||
@ -295,8 +292,6 @@ class $SnLocalChatMessageTable extends SnLocalChatMessage
|
||||
late final GeneratedColumn<int> senderId = GeneratedColumn<int>(
|
||||
'sender_id', aliasedName, true,
|
||||
type: DriftSqlType.int, requiredDuringInsert: false);
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnChatMessage, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -338,7 +333,6 @@ class $SnLocalChatMessageTable extends SnLocalChatMessage
|
||||
context.handle(_senderIdMeta,
|
||||
senderId.isAcceptableOrUnknown(data['sender_id']!, _senderIdMeta));
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
|
||||
@ -604,8 +598,6 @@ class $SnLocalChannelMemberTable extends SnLocalChannelMember
|
||||
late final GeneratedColumn<int> accountId = GeneratedColumn<int>(
|
||||
'account_id', aliasedName, false,
|
||||
type: DriftSqlType.int, requiredDuringInsert: true);
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnChannelMember, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -655,7 +647,6 @@ class $SnLocalChannelMemberTable extends SnLocalChannelMember
|
||||
} else if (isInserting) {
|
||||
context.missing(_accountIdMeta);
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
|
||||
@ -1265,8 +1256,6 @@ class $SnLocalAccountTable extends SnLocalAccount
|
||||
late final GeneratedColumn<String> name = GeneratedColumn<String>(
|
||||
'name', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnAccount, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -1308,7 +1297,6 @@ class $SnLocalAccountTable extends SnLocalAccount
|
||||
} else if (isInserting) {
|
||||
context.missing(_nameMeta);
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
|
||||
@ -1582,8 +1570,6 @@ class $SnLocalAttachmentTable extends SnLocalAttachment
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
defaultConstraints: GeneratedColumn.constraintIsAlways('UNIQUE'));
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnAttachment, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -1639,7 +1625,6 @@ class $SnLocalAttachmentTable extends SnLocalAttachment
|
||||
} else if (isInserting) {
|
||||
context.missing(_uuidMeta);
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('account_id')) {
|
||||
context.handle(_accountIdMeta,
|
||||
accountId.isAcceptableOrUnknown(data['account_id']!, _accountIdMeta));
|
||||
@ -1968,8 +1953,6 @@ class $SnLocalStickerTable extends SnLocalSticker
|
||||
late final GeneratedColumn<String> fullAlias = GeneratedColumn<String>(
|
||||
'full_alias', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnSticker, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -2011,7 +1994,6 @@ class $SnLocalStickerTable extends SnLocalSticker
|
||||
} else if (isInserting) {
|
||||
context.missing(_fullAliasMeta);
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
|
||||
@ -2261,8 +2243,6 @@ class $SnLocalStickerPackTable extends SnLocalStickerPack
|
||||
requiredDuringInsert: false,
|
||||
defaultConstraints:
|
||||
GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT'));
|
||||
static const VerificationMeta _contentMeta =
|
||||
const VerificationMeta('content');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<SnStickerPack, String> content =
|
||||
GeneratedColumn<String>('content', aliasedName, false,
|
||||
@ -2293,7 +2273,6 @@ class $SnLocalStickerPackTable extends SnLocalStickerPack
|
||||
if (data.containsKey('id')) {
|
||||
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
||||
}
|
||||
context.handle(_contentMeta, const VerificationResult.success());
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(_createdAtMeta,
|
||||
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta));
|
||||
|
@ -155,9 +155,12 @@ class SnPostContentProvider {
|
||||
String? realm,
|
||||
String? channel,
|
||||
bool isDraft = false,
|
||||
bool isShuffle = false,
|
||||
}) async {
|
||||
final resp = await _sn.client.get(
|
||||
'/cgi/co/posts${isDraft ? '/drafts' : ''}',
|
||||
isShuffle
|
||||
? '/cgi/co/recommendations/shuffle'
|
||||
: '/cgi/co/posts${isDraft ? '/drafts' : ''}',
|
||||
queryParameters: {
|
||||
'take': take,
|
||||
'offset': offset,
|
||||
|
@ -19,6 +19,7 @@ class UserDirectoryProvider {
|
||||
|
||||
final Map<String, int> _idCache = {};
|
||||
final Map<int, SnAccount> _cache = {};
|
||||
DateTime? _cacheExpiredAt;
|
||||
|
||||
Future<int> loadAccountCache({int max = 100}) async {
|
||||
final out = await (_dt.db.snLocalAccount.select()..limit(max)).get();
|
||||
@ -26,11 +27,18 @@ class UserDirectoryProvider {
|
||||
_cache[ele.id] = ele.content;
|
||||
_idCache[ele.name] = ele.id;
|
||||
}
|
||||
_cacheExpiredAt = DateTime.now().add(const Duration(hours: 1));
|
||||
return out.length;
|
||||
}
|
||||
|
||||
Future<List<SnAccount?>> listAccount(Iterable<dynamic> id) async {
|
||||
// In-memory cache
|
||||
if (_cacheExpiredAt != null && _cacheExpiredAt!.isAfter(DateTime.now())) {
|
||||
_cache.clear();
|
||||
_cacheExpiredAt = DateTime.now().add(const Duration(hours: 1));
|
||||
} else {
|
||||
_cacheExpiredAt ??= DateTime.now().add(const Duration(hours: 1));
|
||||
}
|
||||
final out = List<SnAccount?>.generate(id.length, (e) => null);
|
||||
final plannedQuery = <int>{};
|
||||
for (var idx = 0; idx < out.length; idx++) {
|
||||
@ -62,6 +70,7 @@ class UserDirectoryProvider {
|
||||
plannedQuery.remove(dbResp[idx].id);
|
||||
}
|
||||
// Remote server
|
||||
_saveToLocal(out.where((ele) => ele != null).cast());
|
||||
if (plannedQuery.isEmpty) return out;
|
||||
final resp = await _sn.client
|
||||
.get('/cgi/id/users', queryParameters: {'id': plannedQuery.join(',')});
|
||||
|
@ -30,6 +30,7 @@ import 'package:surface/screens/notification.dart';
|
||||
import 'package:surface/screens/post/post_detail.dart';
|
||||
import 'package:surface/screens/post/post_draft.dart';
|
||||
import 'package:surface/screens/post/post_editor.dart';
|
||||
import 'package:surface/screens/post/post_shuffle.dart';
|
||||
import 'package:surface/screens/post/publisher_page.dart';
|
||||
import 'package:surface/screens/post/post_search.dart';
|
||||
import 'package:surface/screens/realm.dart';
|
||||
@ -88,6 +89,11 @@ final _appRoutes = [
|
||||
extraProps: state.extra as PostEditorExtra?,
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/shuffle',
|
||||
name: 'postShuffle',
|
||||
builder: (context, state) => const PostShuffleScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/search',
|
||||
name: 'postSearch',
|
||||
|
@ -11,7 +11,9 @@ import 'package:surface/providers/database.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/providers/userinfo.dart';
|
||||
import 'package:surface/providers/websocket.dart';
|
||||
import 'package:surface/types/account.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/account/account_status.dart';
|
||||
import 'package:surface/widgets/app_bar_leading.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||
@ -112,7 +114,14 @@ class _AuthorizedAccountScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AccountImage(content: ua.user!.avatar, radius: 28),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AccountImage(content: ua.user!.avatar, radius: 28),
|
||||
_AccountStatusWidget(account: ua.user!),
|
||||
],
|
||||
),
|
||||
const Gap(8),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
@ -290,3 +299,81 @@ class _UnauthorizedAccountScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AccountStatusWidget extends StatefulWidget {
|
||||
final SnAccount account;
|
||||
const _AccountStatusWidget({required this.account});
|
||||
|
||||
@override
|
||||
State<_AccountStatusWidget> createState() => _AccountStatusWidgetState();
|
||||
}
|
||||
|
||||
class _AccountStatusWidgetState extends State<_AccountStatusWidget> {
|
||||
SnAccountStatusInfo? _status;
|
||||
|
||||
Future<void> _fetchStatus() async {
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
final resp =
|
||||
await sn.client.get('/cgi/id/users/${widget.account.name}/status');
|
||||
setState(() {
|
||||
_status = SnAccountStatusInfo.fromJson(resp.data);
|
||||
});
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchStatus();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
_status != null
|
||||
? (_status!.status?.label.isNotEmpty ?? false)
|
||||
? _status!.status!.label
|
||||
: _status!.isOnline
|
||||
? 'accountStatusOnline'.tr()
|
||||
: 'accountStatusOffline'.tr()
|
||||
: 'loading'.tr(),
|
||||
),
|
||||
const Gap(4),
|
||||
Icon(
|
||||
(_status?.isDisturbable ?? true)
|
||||
? Symbols.circle
|
||||
: Symbols.do_not_disturb_on,
|
||||
fill: (_status?.isOnline ?? false) ? 1 : 0,
|
||||
size: 16,
|
||||
color: (_status?.isOnline ?? false)
|
||||
? (_status?.isDisturbable ?? true)
|
||||
? Colors.green
|
||||
: Colors.red
|
||||
: Colors.grey,
|
||||
).padding(all: 4),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => AccountStatusActionPopup(
|
||||
currentStatus: _status,
|
||||
),
|
||||
).then((value) {
|
||||
if (value == true && mounted) {
|
||||
_fetchStatus();
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import 'package:surface/types/account.dart';
|
||||
import 'package:surface/types/check_in.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/account/badge.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/universal_image.dart';
|
||||
import 'package:surface/theme.dart';
|
||||
@ -450,19 +451,25 @@ class _UserScreenState extends State<UserScreen>
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Symbols.circle,
|
||||
fill: 1,
|
||||
(_status?.isDisturbable ?? true)
|
||||
? Symbols.circle
|
||||
: Symbols.do_not_disturb_on,
|
||||
fill: (_status?.isOnline ?? false) ? 1 : 0,
|
||||
size: 16,
|
||||
color: (_status?.isOnline ?? false)
|
||||
? Colors.green
|
||||
? (_status?.isDisturbable ?? true)
|
||||
? Colors.green
|
||||
: Colors.red
|
||||
: Colors.grey,
|
||||
).padding(all: 4),
|
||||
const Gap(8),
|
||||
Text(
|
||||
_status != null
|
||||
? _status!.isOnline
|
||||
? 'accountStatusOnline'.tr()
|
||||
: 'accountStatusOffline'.tr()
|
||||
? (_status!.status?.label.isNotEmpty ?? false)
|
||||
? _status!.status!.label
|
||||
: _status!.isOnline
|
||||
? 'accountStatusOnline'.tr()
|
||||
: 'accountStatusOffline'.tr()
|
||||
: 'loading'.tr(),
|
||||
),
|
||||
if (_status != null &&
|
||||
@ -484,34 +491,7 @@ class _UserScreenState extends State<UserScreen>
|
||||
Wrap(
|
||||
children: _account!.badges
|
||||
.map(
|
||||
(ele) => Tooltip(
|
||||
richMessage: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: kBadgesMeta[ele.type]?.$1.tr() ??
|
||||
'unknown'.tr(),
|
||||
),
|
||||
if (ele.metadata['title'] != null)
|
||||
TextSpan(
|
||||
text: '\n${ele.metadata['title']}',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(text: '\n'),
|
||||
TextSpan(
|
||||
text: DateFormat.yMEd().format(ele.createdAt),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Icon(
|
||||
kBadgesMeta[ele.type]?.$2 ??
|
||||
Symbols.question_mark,
|
||||
color: ele.metadata['color'] != null
|
||||
? HexColor.fromHex(ele.metadata['color']!)
|
||||
: kBadgesMeta[ele.type]?.$3,
|
||||
fill: 1,
|
||||
),
|
||||
),
|
||||
(ele) => AccountBadge(badge: ele),
|
||||
)
|
||||
.toList(),
|
||||
).padding(horizontal: 8),
|
||||
|
@ -225,7 +225,9 @@ class _ExploreScreenState extends State<ExploreScreen>
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Symbols.shuffle),
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
GoRouter.of(context).pushNamed('postShuffle');
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
@ -236,12 +238,12 @@ class _ExploreScreenState extends State<ExploreScreen>
|
||||
icon: _listKey.currentState?.realm != null
|
||||
? AccountImage(
|
||||
content: _listKey.currentState!.realm!.avatar,
|
||||
radius: 18,
|
||||
radius: 14,
|
||||
)
|
||||
: Image.asset(
|
||||
'assets/icon/icon-dark.png',
|
||||
width: 36,
|
||||
height: 36,
|
||||
width: 32,
|
||||
height: 32,
|
||||
color: Theme.of(context)
|
||||
.appBarTheme
|
||||
.foregroundColor,
|
||||
|
@ -546,11 +546,26 @@ class _HomeDashCheckInWidgetState extends State<_HomeDashCheckInWidget> {
|
||||
'+${_todayRecord!.resultExperience} EXP',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
if (_todayRecord!.resultCoin >= 0)
|
||||
if (_todayRecord!.resultCoin > 0)
|
||||
Text(
|
||||
'+${_todayRecord!.resultCoin} ${'walletCurrencyShort'.tr()}',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
)
|
||||
),
|
||||
if (_todayRecord!.currentStreak > 0)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Symbols.local_fire_department,
|
||||
size: 14,
|
||||
).padding(bottom: 2),
|
||||
const Gap(4),
|
||||
Text(
|
||||
'checkInStreak'
|
||||
.plural(_todayRecord!.currentStreak),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
).padding(top: 4),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
132
lib/screens/post/post_shuffle.dart
Normal file
132
lib/screens/post/post_shuffle.dart
Normal file
@ -0,0 +1,132 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/post.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||
import 'package:surface/widgets/post/post_item.dart';
|
||||
|
||||
class PostShuffleScreen extends StatefulWidget {
|
||||
const PostShuffleScreen({super.key});
|
||||
|
||||
@override
|
||||
State<PostShuffleScreen> createState() => _PostShuffleScreenState();
|
||||
}
|
||||
|
||||
class _PostShuffleScreenState extends State<PostShuffleScreen> {
|
||||
late final CardSwiperController _cardController = CardSwiperController();
|
||||
|
||||
bool _isBusy = false;
|
||||
final List<SnPost> _posts = List.empty(growable: true);
|
||||
|
||||
Future<void> _fetchPosts() async {
|
||||
_posts.clear();
|
||||
setState(() => _isBusy = true);
|
||||
try {
|
||||
final pt = context.read<SnPostContentProvider>();
|
||||
final result = await pt.listPosts(
|
||||
take: 10,
|
||||
offset: _posts.length,
|
||||
isShuffle: true,
|
||||
);
|
||||
_posts.addAll(result.$1);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchPosts();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_cardController.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppScaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('postShuffle').tr(),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
if (_isBusy || _posts.isEmpty)
|
||||
const Expanded(
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: CardSwiper(
|
||||
controller: _cardController,
|
||||
isLoop: false,
|
||||
padding: EdgeInsets.zero,
|
||||
cardsCount: _posts.length,
|
||||
cardBuilder: (context, idx, _, __) {
|
||||
final ele = _posts[idx];
|
||||
return SingleChildScrollView(
|
||||
child: Center(
|
||||
child: OpenablePostItem(
|
||||
key: ValueKey(ele),
|
||||
data: ele,
|
||||
maxWidth: 640,
|
||||
onChanged: (ele) {
|
||||
_posts[idx] = ele;
|
||||
setState(() {});
|
||||
},
|
||||
onDeleted: () {
|
||||
_fetchPosts();
|
||||
},
|
||||
).padding(
|
||||
all: 24,
|
||||
bottom:
|
||||
MediaQuery.of(context).padding.bottom + 16 + 50,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
onEnd: () {
|
||||
_fetchPosts();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!_isBusy && _posts.isNotEmpty)
|
||||
Positioned(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton.filled(
|
||||
icon: const Icon(Symbols.next_plan),
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
onPressed: () {
|
||||
_cardController.swipe(CardSwiperDirection.right);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -119,13 +119,33 @@ abstract class SnAccountStatusInfo with _$SnAccountStatusInfo {
|
||||
required bool isDisturbable,
|
||||
required bool isOnline,
|
||||
required DateTime? lastSeenAt,
|
||||
required dynamic status,
|
||||
required SnAccountStatus? status,
|
||||
}) = _SnAccountStatusInfo;
|
||||
|
||||
factory SnAccountStatusInfo.fromJson(Map<String, Object?> json) =>
|
||||
_$SnAccountStatusInfoFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class SnAccountStatus with _$SnAccountStatus {
|
||||
const factory SnAccountStatus({
|
||||
required int id,
|
||||
required DateTime createdAt,
|
||||
required DateTime updatedAt,
|
||||
required DateTime? deletedAt,
|
||||
required String type,
|
||||
required String label,
|
||||
required int attitude,
|
||||
required bool isNoDisturb,
|
||||
required bool isInvisible,
|
||||
required DateTime? clearAt,
|
||||
required int accountId,
|
||||
}) = _SnAccountStatus;
|
||||
|
||||
factory SnAccountStatus.fromJson(Map<String, Object?> json) =>
|
||||
_$SnAccountStatusFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class SnAbuseReport with _$SnAbuseReport {
|
||||
const factory SnAbuseReport({
|
||||
|
@ -2139,7 +2139,7 @@ mixin _$SnAccountStatusInfo {
|
||||
bool get isDisturbable;
|
||||
bool get isOnline;
|
||||
DateTime? get lastSeenAt;
|
||||
dynamic get status;
|
||||
SnAccountStatus? get status;
|
||||
|
||||
/// Create a copy of SnAccountStatusInfo
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@ -2163,13 +2163,13 @@ mixin _$SnAccountStatusInfo {
|
||||
other.isOnline == isOnline) &&
|
||||
(identical(other.lastSeenAt, lastSeenAt) ||
|
||||
other.lastSeenAt == lastSeenAt) &&
|
||||
const DeepCollectionEquality().equals(other.status, status));
|
||||
(identical(other.status, status) || other.status == status));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, isDisturbable, isOnline,
|
||||
lastSeenAt, const DeepCollectionEquality().hash(status));
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, isDisturbable, isOnline, lastSeenAt, status);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@ -2187,7 +2187,9 @@ abstract mixin class $SnAccountStatusInfoCopyWith<$Res> {
|
||||
{bool isDisturbable,
|
||||
bool isOnline,
|
||||
DateTime? lastSeenAt,
|
||||
dynamic status});
|
||||
SnAccountStatus? status});
|
||||
|
||||
$SnAccountStatusCopyWith<$Res>? get status;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -2224,9 +2226,23 @@ class _$SnAccountStatusInfoCopyWithImpl<$Res>
|
||||
status: freezed == status
|
||||
? _self.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as dynamic,
|
||||
as SnAccountStatus?,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of SnAccountStatusInfo
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnAccountStatusCopyWith<$Res>? get status {
|
||||
if (_self.status == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $SnAccountStatusCopyWith<$Res>(_self.status!, (value) {
|
||||
return _then(_self.copyWith(status: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -2247,7 +2263,7 @@ class _SnAccountStatusInfo implements SnAccountStatusInfo {
|
||||
@override
|
||||
final DateTime? lastSeenAt;
|
||||
@override
|
||||
final dynamic status;
|
||||
final SnAccountStatus? status;
|
||||
|
||||
/// Create a copy of SnAccountStatusInfo
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@ -2276,13 +2292,13 @@ class _SnAccountStatusInfo implements SnAccountStatusInfo {
|
||||
other.isOnline == isOnline) &&
|
||||
(identical(other.lastSeenAt, lastSeenAt) ||
|
||||
other.lastSeenAt == lastSeenAt) &&
|
||||
const DeepCollectionEquality().equals(other.status, status));
|
||||
(identical(other.status, status) || other.status == status));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, isDisturbable, isOnline,
|
||||
lastSeenAt, const DeepCollectionEquality().hash(status));
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, isDisturbable, isOnline, lastSeenAt, status);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@ -2302,7 +2318,10 @@ abstract mixin class _$SnAccountStatusInfoCopyWith<$Res>
|
||||
{bool isDisturbable,
|
||||
bool isOnline,
|
||||
DateTime? lastSeenAt,
|
||||
dynamic status});
|
||||
SnAccountStatus? status});
|
||||
|
||||
@override
|
||||
$SnAccountStatusCopyWith<$Res>? get status;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@ -2339,7 +2358,386 @@ class __$SnAccountStatusInfoCopyWithImpl<$Res>
|
||||
status: freezed == status
|
||||
? _self.status
|
||||
: status // ignore: cast_nullable_to_non_nullable
|
||||
as dynamic,
|
||||
as SnAccountStatus?,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of SnAccountStatusInfo
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnAccountStatusCopyWith<$Res>? get status {
|
||||
if (_self.status == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $SnAccountStatusCopyWith<$Res>(_self.status!, (value) {
|
||||
return _then(_self.copyWith(status: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$SnAccountStatus {
|
||||
int get id;
|
||||
DateTime get createdAt;
|
||||
DateTime get updatedAt;
|
||||
DateTime? get deletedAt;
|
||||
String get type;
|
||||
String get label;
|
||||
int get attitude;
|
||||
bool get isNoDisturb;
|
||||
bool get isInvisible;
|
||||
DateTime? get clearAt;
|
||||
int get accountId;
|
||||
|
||||
/// Create a copy of SnAccountStatus
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$SnAccountStatusCopyWith<SnAccountStatus> get copyWith =>
|
||||
_$SnAccountStatusCopyWithImpl<SnAccountStatus>(
|
||||
this as SnAccountStatus, _$identity);
|
||||
|
||||
/// Serializes this SnAccountStatus to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is SnAccountStatus &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.createdAt, createdAt) ||
|
||||
other.createdAt == createdAt) &&
|
||||
(identical(other.updatedAt, updatedAt) ||
|
||||
other.updatedAt == updatedAt) &&
|
||||
(identical(other.deletedAt, deletedAt) ||
|
||||
other.deletedAt == deletedAt) &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
(identical(other.label, label) || other.label == label) &&
|
||||
(identical(other.attitude, attitude) ||
|
||||
other.attitude == attitude) &&
|
||||
(identical(other.isNoDisturb, isNoDisturb) ||
|
||||
other.isNoDisturb == isNoDisturb) &&
|
||||
(identical(other.isInvisible, isInvisible) ||
|
||||
other.isInvisible == isInvisible) &&
|
||||
(identical(other.clearAt, clearAt) || other.clearAt == clearAt) &&
|
||||
(identical(other.accountId, accountId) ||
|
||||
other.accountId == accountId));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
deletedAt,
|
||||
type,
|
||||
label,
|
||||
attitude,
|
||||
isNoDisturb,
|
||||
isInvisible,
|
||||
clearAt,
|
||||
accountId);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SnAccountStatus(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, type: $type, label: $label, attitude: $attitude, isNoDisturb: $isNoDisturb, isInvisible: $isInvisible, clearAt: $clearAt, accountId: $accountId)';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $SnAccountStatusCopyWith<$Res> {
|
||||
factory $SnAccountStatusCopyWith(
|
||||
SnAccountStatus value, $Res Function(SnAccountStatus) _then) =
|
||||
_$SnAccountStatusCopyWithImpl;
|
||||
@useResult
|
||||
$Res call(
|
||||
{int id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
DateTime? deletedAt,
|
||||
String type,
|
||||
String label,
|
||||
int attitude,
|
||||
bool isNoDisturb,
|
||||
bool isInvisible,
|
||||
DateTime? clearAt,
|
||||
int accountId});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$SnAccountStatusCopyWithImpl<$Res>
|
||||
implements $SnAccountStatusCopyWith<$Res> {
|
||||
_$SnAccountStatusCopyWithImpl(this._self, this._then);
|
||||
|
||||
final SnAccountStatus _self;
|
||||
final $Res Function(SnAccountStatus) _then;
|
||||
|
||||
/// Create a copy of SnAccountStatus
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? createdAt = null,
|
||||
Object? updatedAt = null,
|
||||
Object? deletedAt = freezed,
|
||||
Object? type = null,
|
||||
Object? label = null,
|
||||
Object? attitude = null,
|
||||
Object? isNoDisturb = null,
|
||||
Object? isInvisible = null,
|
||||
Object? clearAt = freezed,
|
||||
Object? accountId = null,
|
||||
}) {
|
||||
return _then(_self.copyWith(
|
||||
id: null == id
|
||||
? _self.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
createdAt: null == createdAt
|
||||
? _self.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
updatedAt: null == updatedAt
|
||||
? _self.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
deletedAt: freezed == deletedAt
|
||||
? _self.deletedAt
|
||||
: deletedAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
type: null == type
|
||||
? _self.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
label: null == label
|
||||
? _self.label
|
||||
: label // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
attitude: null == attitude
|
||||
? _self.attitude
|
||||
: attitude // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
isNoDisturb: null == isNoDisturb
|
||||
? _self.isNoDisturb
|
||||
: isNoDisturb // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
isInvisible: null == isInvisible
|
||||
? _self.isInvisible
|
||||
: isInvisible // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
clearAt: freezed == clearAt
|
||||
? _self.clearAt
|
||||
: clearAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
accountId: null == accountId
|
||||
? _self.accountId
|
||||
: accountId // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _SnAccountStatus implements SnAccountStatus {
|
||||
const _SnAccountStatus(
|
||||
{required this.id,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.deletedAt,
|
||||
required this.type,
|
||||
required this.label,
|
||||
required this.attitude,
|
||||
required this.isNoDisturb,
|
||||
required this.isInvisible,
|
||||
required this.clearAt,
|
||||
required this.accountId});
|
||||
factory _SnAccountStatus.fromJson(Map<String, dynamic> json) =>
|
||||
_$SnAccountStatusFromJson(json);
|
||||
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
final DateTime createdAt;
|
||||
@override
|
||||
final DateTime updatedAt;
|
||||
@override
|
||||
final DateTime? deletedAt;
|
||||
@override
|
||||
final String type;
|
||||
@override
|
||||
final String label;
|
||||
@override
|
||||
final int attitude;
|
||||
@override
|
||||
final bool isNoDisturb;
|
||||
@override
|
||||
final bool isInvisible;
|
||||
@override
|
||||
final DateTime? clearAt;
|
||||
@override
|
||||
final int accountId;
|
||||
|
||||
/// Create a copy of SnAccountStatus
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$SnAccountStatusCopyWith<_SnAccountStatus> get copyWith =>
|
||||
__$SnAccountStatusCopyWithImpl<_SnAccountStatus>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$SnAccountStatusToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _SnAccountStatus &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.createdAt, createdAt) ||
|
||||
other.createdAt == createdAt) &&
|
||||
(identical(other.updatedAt, updatedAt) ||
|
||||
other.updatedAt == updatedAt) &&
|
||||
(identical(other.deletedAt, deletedAt) ||
|
||||
other.deletedAt == deletedAt) &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
(identical(other.label, label) || other.label == label) &&
|
||||
(identical(other.attitude, attitude) ||
|
||||
other.attitude == attitude) &&
|
||||
(identical(other.isNoDisturb, isNoDisturb) ||
|
||||
other.isNoDisturb == isNoDisturb) &&
|
||||
(identical(other.isInvisible, isInvisible) ||
|
||||
other.isInvisible == isInvisible) &&
|
||||
(identical(other.clearAt, clearAt) || other.clearAt == clearAt) &&
|
||||
(identical(other.accountId, accountId) ||
|
||||
other.accountId == accountId));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
deletedAt,
|
||||
type,
|
||||
label,
|
||||
attitude,
|
||||
isNoDisturb,
|
||||
isInvisible,
|
||||
clearAt,
|
||||
accountId);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SnAccountStatus(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, type: $type, label: $label, attitude: $attitude, isNoDisturb: $isNoDisturb, isInvisible: $isInvisible, clearAt: $clearAt, accountId: $accountId)';
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SnAccountStatusCopyWith<$Res>
|
||||
implements $SnAccountStatusCopyWith<$Res> {
|
||||
factory _$SnAccountStatusCopyWith(
|
||||
_SnAccountStatus value, $Res Function(_SnAccountStatus) _then) =
|
||||
__$SnAccountStatusCopyWithImpl;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{int id,
|
||||
DateTime createdAt,
|
||||
DateTime updatedAt,
|
||||
DateTime? deletedAt,
|
||||
String type,
|
||||
String label,
|
||||
int attitude,
|
||||
bool isNoDisturb,
|
||||
bool isInvisible,
|
||||
DateTime? clearAt,
|
||||
int accountId});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$SnAccountStatusCopyWithImpl<$Res>
|
||||
implements _$SnAccountStatusCopyWith<$Res> {
|
||||
__$SnAccountStatusCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _SnAccountStatus _self;
|
||||
final $Res Function(_SnAccountStatus) _then;
|
||||
|
||||
/// Create a copy of SnAccountStatus
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? createdAt = null,
|
||||
Object? updatedAt = null,
|
||||
Object? deletedAt = freezed,
|
||||
Object? type = null,
|
||||
Object? label = null,
|
||||
Object? attitude = null,
|
||||
Object? isNoDisturb = null,
|
||||
Object? isInvisible = null,
|
||||
Object? clearAt = freezed,
|
||||
Object? accountId = null,
|
||||
}) {
|
||||
return _then(_SnAccountStatus(
|
||||
id: null == id
|
||||
? _self.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
createdAt: null == createdAt
|
||||
? _self.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
updatedAt: null == updatedAt
|
||||
? _self.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
deletedAt: freezed == deletedAt
|
||||
? _self.deletedAt
|
||||
: deletedAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
type: null == type
|
||||
? _self.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
label: null == label
|
||||
? _self.label
|
||||
: label // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
attitude: null == attitude
|
||||
? _self.attitude
|
||||
: attitude // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
isNoDisturb: null == isNoDisturb
|
||||
? _self.isNoDisturb
|
||||
: isNoDisturb // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
isInvisible: null == isInvisible
|
||||
? _self.isInvisible
|
||||
: isInvisible // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
clearAt: freezed == clearAt
|
||||
? _self.clearAt
|
||||
: clearAt // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
accountId: null == accountId
|
||||
? _self.accountId
|
||||
: accountId // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,9 @@ _SnAccountStatusInfo _$SnAccountStatusInfoFromJson(Map<String, dynamic> json) =>
|
||||
lastSeenAt: json['last_seen_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['last_seen_at'] as String),
|
||||
status: json['status'],
|
||||
status: json['status'] == null
|
||||
? null
|
||||
: SnAccountStatus.fromJson(json['status'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SnAccountStatusInfoToJson(
|
||||
@ -219,7 +221,41 @@ Map<String, dynamic> _$SnAccountStatusInfoToJson(
|
||||
'is_disturbable': instance.isDisturbable,
|
||||
'is_online': instance.isOnline,
|
||||
'last_seen_at': instance.lastSeenAt?.toIso8601String(),
|
||||
'status': instance.status,
|
||||
'status': instance.status?.toJson(),
|
||||
};
|
||||
|
||||
_SnAccountStatus _$SnAccountStatusFromJson(Map<String, dynamic> json) =>
|
||||
_SnAccountStatus(
|
||||
id: (json['id'] as num).toInt(),
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
deletedAt: json['deleted_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['deleted_at'] as String),
|
||||
type: json['type'] as String,
|
||||
label: json['label'] as String,
|
||||
attitude: (json['attitude'] as num).toInt(),
|
||||
isNoDisturb: json['is_no_disturb'] as bool,
|
||||
isInvisible: json['is_invisible'] as bool,
|
||||
clearAt: json['clear_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['clear_at'] as String),
|
||||
accountId: (json['account_id'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SnAccountStatusToJson(_SnAccountStatus instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'created_at': instance.createdAt.toIso8601String(),
|
||||
'updated_at': instance.updatedAt.toIso8601String(),
|
||||
'deleted_at': instance.deletedAt?.toIso8601String(),
|
||||
'type': instance.type,
|
||||
'label': instance.label,
|
||||
'attitude': instance.attitude,
|
||||
'is_no_disturb': instance.isNoDisturb,
|
||||
'is_invisible': instance.isInvisible,
|
||||
'clear_at': instance.clearAt?.toIso8601String(),
|
||||
'account_id': instance.accountId,
|
||||
};
|
||||
|
||||
_SnAbuseReport _$SnAbuseReportFromJson(Map<String, dynamic> json) =>
|
||||
|
@ -25,11 +25,13 @@ abstract class SnCheckInRecord with _$SnCheckInRecord {
|
||||
required int resultTier,
|
||||
required int resultExperience,
|
||||
required double resultCoin,
|
||||
@Default(0) int currentStreak,
|
||||
required List<int> resultModifiers,
|
||||
required int accountId,
|
||||
}) = _SnCheckInRecord;
|
||||
|
||||
factory SnCheckInRecord.fromJson(Map<String, dynamic> json) => _$SnCheckInRecordFromJson(json);
|
||||
factory SnCheckInRecord.fromJson(Map<String, dynamic> json) =>
|
||||
_$SnCheckInRecordFromJson(json);
|
||||
|
||||
String get symbol => kCheckInResultTierSymbols[resultTier];
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ mixin _$SnCheckInRecord {
|
||||
int get resultTier;
|
||||
int get resultExperience;
|
||||
double get resultCoin;
|
||||
int get currentStreak;
|
||||
List<int> get resultModifiers;
|
||||
int get accountId;
|
||||
|
||||
@ -54,6 +55,8 @@ mixin _$SnCheckInRecord {
|
||||
other.resultExperience == resultExperience) &&
|
||||
(identical(other.resultCoin, resultCoin) ||
|
||||
other.resultCoin == resultCoin) &&
|
||||
(identical(other.currentStreak, currentStreak) ||
|
||||
other.currentStreak == currentStreak) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other.resultModifiers, resultModifiers) &&
|
||||
(identical(other.accountId, accountId) ||
|
||||
@ -71,12 +74,13 @@ mixin _$SnCheckInRecord {
|
||||
resultTier,
|
||||
resultExperience,
|
||||
resultCoin,
|
||||
currentStreak,
|
||||
const DeepCollectionEquality().hash(resultModifiers),
|
||||
accountId);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SnCheckInRecord(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, resultTier: $resultTier, resultExperience: $resultExperience, resultCoin: $resultCoin, resultModifiers: $resultModifiers, accountId: $accountId)';
|
||||
return 'SnCheckInRecord(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, resultTier: $resultTier, resultExperience: $resultExperience, resultCoin: $resultCoin, currentStreak: $currentStreak, resultModifiers: $resultModifiers, accountId: $accountId)';
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,6 +98,7 @@ abstract mixin class $SnCheckInRecordCopyWith<$Res> {
|
||||
int resultTier,
|
||||
int resultExperience,
|
||||
double resultCoin,
|
||||
int currentStreak,
|
||||
List<int> resultModifiers,
|
||||
int accountId});
|
||||
}
|
||||
@ -118,6 +123,7 @@ class _$SnCheckInRecordCopyWithImpl<$Res>
|
||||
Object? resultTier = null,
|
||||
Object? resultExperience = null,
|
||||
Object? resultCoin = null,
|
||||
Object? currentStreak = null,
|
||||
Object? resultModifiers = null,
|
||||
Object? accountId = null,
|
||||
}) {
|
||||
@ -150,6 +156,10 @@ class _$SnCheckInRecordCopyWithImpl<$Res>
|
||||
? _self.resultCoin
|
||||
: resultCoin // ignore: cast_nullable_to_non_nullable
|
||||
as double,
|
||||
currentStreak: null == currentStreak
|
||||
? _self.currentStreak
|
||||
: currentStreak // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
resultModifiers: null == resultModifiers
|
||||
? _self.resultModifiers
|
||||
: resultModifiers // ignore: cast_nullable_to_non_nullable
|
||||
@ -173,6 +183,7 @@ class _SnCheckInRecord extends SnCheckInRecord {
|
||||
required this.resultTier,
|
||||
required this.resultExperience,
|
||||
required this.resultCoin,
|
||||
this.currentStreak = 0,
|
||||
required final List<int> resultModifiers,
|
||||
required this.accountId})
|
||||
: _resultModifiers = resultModifiers,
|
||||
@ -194,6 +205,9 @@ class _SnCheckInRecord extends SnCheckInRecord {
|
||||
final int resultExperience;
|
||||
@override
|
||||
final double resultCoin;
|
||||
@override
|
||||
@JsonKey()
|
||||
final int currentStreak;
|
||||
final List<int> _resultModifiers;
|
||||
@override
|
||||
List<int> get resultModifiers {
|
||||
@ -238,6 +252,8 @@ class _SnCheckInRecord extends SnCheckInRecord {
|
||||
other.resultExperience == resultExperience) &&
|
||||
(identical(other.resultCoin, resultCoin) ||
|
||||
other.resultCoin == resultCoin) &&
|
||||
(identical(other.currentStreak, currentStreak) ||
|
||||
other.currentStreak == currentStreak) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._resultModifiers, _resultModifiers) &&
|
||||
(identical(other.accountId, accountId) ||
|
||||
@ -255,12 +271,13 @@ class _SnCheckInRecord extends SnCheckInRecord {
|
||||
resultTier,
|
||||
resultExperience,
|
||||
resultCoin,
|
||||
currentStreak,
|
||||
const DeepCollectionEquality().hash(_resultModifiers),
|
||||
accountId);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SnCheckInRecord(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, resultTier: $resultTier, resultExperience: $resultExperience, resultCoin: $resultCoin, resultModifiers: $resultModifiers, accountId: $accountId)';
|
||||
return 'SnCheckInRecord(id: $id, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt, resultTier: $resultTier, resultExperience: $resultExperience, resultCoin: $resultCoin, currentStreak: $currentStreak, resultModifiers: $resultModifiers, accountId: $accountId)';
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,6 +297,7 @@ abstract mixin class _$SnCheckInRecordCopyWith<$Res>
|
||||
int resultTier,
|
||||
int resultExperience,
|
||||
double resultCoin,
|
||||
int currentStreak,
|
||||
List<int> resultModifiers,
|
||||
int accountId});
|
||||
}
|
||||
@ -304,6 +322,7 @@ class __$SnCheckInRecordCopyWithImpl<$Res>
|
||||
Object? resultTier = null,
|
||||
Object? resultExperience = null,
|
||||
Object? resultCoin = null,
|
||||
Object? currentStreak = null,
|
||||
Object? resultModifiers = null,
|
||||
Object? accountId = null,
|
||||
}) {
|
||||
@ -336,6 +355,10 @@ class __$SnCheckInRecordCopyWithImpl<$Res>
|
||||
? _self.resultCoin
|
||||
: resultCoin // ignore: cast_nullable_to_non_nullable
|
||||
as double,
|
||||
currentStreak: null == currentStreak
|
||||
? _self.currentStreak
|
||||
: currentStreak // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
resultModifiers: null == resultModifiers
|
||||
? _self._resultModifiers
|
||||
: resultModifiers // ignore: cast_nullable_to_non_nullable
|
||||
|
@ -17,6 +17,7 @@ _SnCheckInRecord _$SnCheckInRecordFromJson(Map<String, dynamic> json) =>
|
||||
resultTier: (json['result_tier'] as num).toInt(),
|
||||
resultExperience: (json['result_experience'] as num).toInt(),
|
||||
resultCoin: (json['result_coin'] as num).toDouble(),
|
||||
currentStreak: (json['current_streak'] as num?)?.toInt() ?? 0,
|
||||
resultModifiers: (json['result_modifiers'] as List<dynamic>)
|
||||
.map((e) => (e as num).toInt())
|
||||
.toList(),
|
||||
@ -32,6 +33,7 @@ Map<String, dynamic> _$SnCheckInRecordToJson(_SnCheckInRecord instance) =>
|
||||
'result_tier': instance.resultTier,
|
||||
'result_experience': instance.resultExperience,
|
||||
'result_coin': instance.resultCoin,
|
||||
'current_streak': instance.currentStreak,
|
||||
'result_modifiers': instance.resultModifiers,
|
||||
'account_id': instance.accountId,
|
||||
};
|
||||
|
@ -8,9 +8,9 @@ import 'package:relative_time/relative_time.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/experience.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/screens/account/profile_page.dart';
|
||||
import 'package:surface/types/account.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/account/badge.dart';
|
||||
import 'package:surface/widgets/universal_image.dart';
|
||||
|
||||
class AccountPopoverCard extends StatelessWidget {
|
||||
@ -72,37 +72,21 @@ class AccountPopoverCard extends StatelessWidget {
|
||||
const Gap(8)
|
||||
],
|
||||
).padding(horizontal: 16),
|
||||
if (data.badges.isNotEmpty) const Gap(12),
|
||||
if (data.badges.isNotEmpty)
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
children: data.badges
|
||||
.map(
|
||||
(ele) => Tooltip(
|
||||
richMessage: TextSpan(
|
||||
children: [
|
||||
TextSpan(text: kBadgesMeta[ele.type]?.$1.tr() ?? 'unknown'.tr()),
|
||||
if (ele.metadata['title'] != null)
|
||||
TextSpan(
|
||||
text: '\n${ele.metadata['title']}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(text: '\n'),
|
||||
TextSpan(
|
||||
text: DateFormat.yMEd().format(ele.createdAt),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Icon(
|
||||
kBadgesMeta[ele.type]?.$2 ?? Symbols.question_mark,
|
||||
color: kBadgesMeta[ele.type]?.$3,
|
||||
fill: 1,
|
||||
),
|
||||
),
|
||||
(ele) => AccountBadge(badge: ele),
|
||||
)
|
||||
.toList(),
|
||||
).padding(horizontal: 24),
|
||||
const Gap(8),
|
||||
).padding(horizontal: 24, bottom: 12, top: 12),
|
||||
if (data.profile?.description.isNotEmpty ?? false)
|
||||
Text(
|
||||
data.profile?.description ?? '',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
).padding(horizontal: 26, bottom: 8),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
@ -110,7 +94,9 @@ class AccountPopoverCard extends StatelessWidget {
|
||||
const Gap(8),
|
||||
Text('Lv${getLevelFromExp(data.profile?.experience ?? 0)}'),
|
||||
const Gap(8),
|
||||
Text(calcLevelUpProgressLevel(data.profile?.experience ?? 0)).fontSize(11).opacity(0.5),
|
||||
Text(calcLevelUpProgressLevel(data.profile?.experience ?? 0))
|
||||
.fontSize(11)
|
||||
.opacity(0.5),
|
||||
const Gap(8),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
@ -126,25 +112,36 @@ class AccountPopoverCard extends StatelessWidget {
|
||||
FutureBuilder(
|
||||
future: sn.client.get('/cgi/id/users/${data.name}/status'),
|
||||
builder: (context, snapshot) {
|
||||
final SnAccountStatusInfo? status =
|
||||
snapshot.hasData ? SnAccountStatusInfo.fromJson(snapshot.data!.data) : null;
|
||||
final SnAccountStatusInfo? status = snapshot.hasData
|
||||
? SnAccountStatusInfo.fromJson(snapshot.data!.data)
|
||||
: null;
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
Symbols.circle,
|
||||
fill: 1,
|
||||
(status?.isDisturbable ?? true)
|
||||
? Symbols.circle
|
||||
: Symbols.do_not_disturb_on,
|
||||
fill: (status?.isOnline ?? false) ? 1 : 0,
|
||||
size: 16,
|
||||
color: (status?.isOnline ?? false) ? Colors.green : Colors.grey,
|
||||
color: (status?.isOnline ?? false)
|
||||
? (status?.isDisturbable ?? true)
|
||||
? Colors.green
|
||||
: Colors.red
|
||||
: Colors.grey,
|
||||
).padding(all: 4),
|
||||
const Gap(8),
|
||||
Text(
|
||||
status != null
|
||||
? status.isOnline
|
||||
? 'accountStatusOnline'.tr()
|
||||
: 'accountStatusOffline'.tr()
|
||||
? (status.status?.label.isNotEmpty ?? false)
|
||||
? status.status!.label
|
||||
: status.isOnline
|
||||
? 'accountStatusOnline'.tr()
|
||||
: 'accountStatusOffline'.tr()
|
||||
: 'loading'.tr(),
|
||||
),
|
||||
if (status != null && !status.isOnline && status.lastSeenAt != null)
|
||||
if (status != null &&
|
||||
!status.isOnline &&
|
||||
status.lastSeenAt != null)
|
||||
Text(
|
||||
'accountStatusLastSeen'.tr(args: [
|
||||
status.lastSeenAt != null
|
||||
|
391
lib/widgets/account/account_status.dart
Normal file
391
lib/widgets/account/account_status.dart
Normal file
@ -0,0 +1,391 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/types/account.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/loading_indicator.dart';
|
||||
|
||||
final Map<String, (Widget, String, String?)> kPresetStatus = {
|
||||
'online': (
|
||||
const Icon(Symbols.circle, color: Colors.green, fill: 1),
|
||||
'accountStatusOnline'.tr(),
|
||||
null,
|
||||
),
|
||||
'silent': (
|
||||
const Icon(Symbols.do_not_disturb_on, color: Colors.red),
|
||||
'accountStatusSilent'.tr(),
|
||||
'accountStatusSilentDesc'.tr(),
|
||||
),
|
||||
'invisible': (
|
||||
const Icon(Symbols.circle, color: Colors.grey),
|
||||
'accountStatusInvisible'.tr(),
|
||||
'accountStatusInvisibleDesc'.tr(),
|
||||
),
|
||||
};
|
||||
|
||||
class AccountStatusActionPopup extends StatefulWidget {
|
||||
final SnAccountStatusInfo? currentStatus;
|
||||
const AccountStatusActionPopup({super.key, this.currentStatus});
|
||||
|
||||
@override
|
||||
State<AccountStatusActionPopup> createState() =>
|
||||
_AccountStatusActionPopupState();
|
||||
}
|
||||
|
||||
class _AccountStatusActionPopupState extends State<AccountStatusActionPopup> {
|
||||
bool _isBusy = false;
|
||||
|
||||
Future<void> setStatus(
|
||||
String type,
|
||||
String? label,
|
||||
int attitude, {
|
||||
bool isUpdate = false,
|
||||
bool isSilent = false,
|
||||
bool isInvisible = false,
|
||||
DateTime? clearAt,
|
||||
}) async {
|
||||
setState(() => _isBusy = true);
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
|
||||
final payload = {
|
||||
'type': type,
|
||||
'label': label,
|
||||
'attitude': attitude,
|
||||
'is_no_disturb': isSilent,
|
||||
'is_invisible': isInvisible,
|
||||
'clear_at': clearAt?.toUtc().toIso8601String()
|
||||
};
|
||||
|
||||
try {
|
||||
await sn.client.request(
|
||||
'/cgi/id/users/me/status',
|
||||
data: payload,
|
||||
options: Options(method: isUpdate ? 'PUT' : 'POST'),
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, true);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _clearStatus() async {
|
||||
if (_isBusy) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
await sn.client.delete('/cgi/id/users/me/status');
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop(true);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Symbols.mood, size: 24),
|
||||
const Gap(16),
|
||||
Text('accountChangeStatus',
|
||||
style: Theme.of(context).textTheme.titleLarge)
|
||||
.tr(),
|
||||
],
|
||||
).padding(horizontal: 20, top: 16, bottom: 12),
|
||||
LoadingIndicator(isActive: _isBusy),
|
||||
SizedBox(
|
||||
height: 48,
|
||||
child: ListView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18),
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: kPresetStatus.entries
|
||||
.map(
|
||||
(x) => StyledWidget(ActionChip(
|
||||
avatar: x.value.$1,
|
||||
label: Text(x.value.$2),
|
||||
tooltip: x.value.$3,
|
||||
onPressed: _isBusy
|
||||
? null
|
||||
: () {
|
||||
setStatus(
|
||||
x.key,
|
||||
x.value.$2,
|
||||
0,
|
||||
isInvisible: x.key == 'invisible',
|
||||
isSilent: x.key == 'silent',
|
||||
);
|
||||
},
|
||||
)).padding(right: 6),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
const Gap(16),
|
||||
const Divider(thickness: 0.3, height: 0.3),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: widget.currentStatus != null
|
||||
? const Icon(Icons.edit)
|
||||
: const Icon(Icons.add),
|
||||
title: Text('accountCustomStatus').tr(),
|
||||
subtitle: Text('accountCustomStatusDescription').tr(),
|
||||
onTap: _isBusy
|
||||
? null
|
||||
: () async {
|
||||
final val = await showDialog(
|
||||
context: context,
|
||||
builder: (context) => _AccountStatusEditorDialog(
|
||||
currentStatus: widget.currentStatus,
|
||||
),
|
||||
);
|
||||
if (val == true && context.mounted) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
},
|
||||
),
|
||||
if (widget.currentStatus != null)
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.clear),
|
||||
title: Text('accountClearStatus').tr(),
|
||||
subtitle: Text('accountClearStatusDescription').tr(),
|
||||
onTap: _isBusy
|
||||
? null
|
||||
: () {
|
||||
_clearStatus();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AccountStatusEditorDialog extends StatefulWidget {
|
||||
final SnAccountStatusInfo? currentStatus;
|
||||
const _AccountStatusEditorDialog({this.currentStatus});
|
||||
|
||||
@override
|
||||
State<_AccountStatusEditorDialog> createState() =>
|
||||
_AccountStatusEditorDialogState();
|
||||
}
|
||||
|
||||
class _AccountStatusEditorDialogState
|
||||
extends State<_AccountStatusEditorDialog> {
|
||||
bool _isBusy = false;
|
||||
|
||||
final TextEditingController _labelController = TextEditingController();
|
||||
final TextEditingController _clearAtController = TextEditingController();
|
||||
|
||||
int _attitude = 0;
|
||||
bool _isSilent = false;
|
||||
bool _isInvisible = false;
|
||||
DateTime? _clearAt;
|
||||
|
||||
Future<void> _selectClearAt() async {
|
||||
final DateTime? pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _clearAt?.toLocal() ?? DateTime.now(),
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime.now().add(const Duration(days: 365)),
|
||||
);
|
||||
if (pickedDate == null) return;
|
||||
if (!mounted) return;
|
||||
final TimeOfDay? pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
);
|
||||
if (pickedTime == null) return;
|
||||
if (!mounted) return;
|
||||
final picked = pickedDate.copyWith(
|
||||
hour: pickedTime.hour,
|
||||
minute: pickedTime.minute,
|
||||
);
|
||||
setState(() {
|
||||
_clearAt = picked;
|
||||
_clearAtController.text = DateFormat('y/M/d HH:mm').format(_clearAt!);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _applyStatus() async {
|
||||
if (_isBusy) return;
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
try {
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
await sn.client.request(
|
||||
'/cgi/id/users/me/status',
|
||||
data: {
|
||||
'type': 'custom',
|
||||
'label': _labelController.text,
|
||||
'attitude': _attitude,
|
||||
'is_no_disturb': _isSilent,
|
||||
'is_invisible': _isInvisible,
|
||||
'clear_at': _clearAt?.toUtc().toIso8601String(),
|
||||
},
|
||||
options: Options(
|
||||
method: widget.currentStatus?.status != null ? 'PUT' : 'POST',
|
||||
),
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop(true);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _syncWidget() {
|
||||
if (widget.currentStatus?.status != null) {
|
||||
_clearAt = widget.currentStatus!.status!.clearAt;
|
||||
if (_clearAt != null) {
|
||||
_clearAtController.text = DateFormat('y/M/d HH:mm').format(_clearAt!);
|
||||
}
|
||||
|
||||
_labelController.text = widget.currentStatus!.status!.label;
|
||||
_attitude = widget.currentStatus!.status!.attitude;
|
||||
_isInvisible = widget.currentStatus!.status!.isInvisible;
|
||||
_isSilent = widget.currentStatus!.status!.isNoDisturb;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_syncWidget();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('accountCustomStatus').tr(),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
LoadingIndicator(isActive: _isBusy),
|
||||
TextField(
|
||||
controller: _labelController,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
prefixIcon: const Icon(Icons.label),
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: 'fieldAccountStatusLabel'.tr(),
|
||||
),
|
||||
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
const Gap(8),
|
||||
TextField(
|
||||
controller: _clearAtController,
|
||||
readOnly: true,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
prefixIcon: const Icon(Icons.event_busy),
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: 'fieldAccountStatusClearAt'.tr(),
|
||||
),
|
||||
onTap: () => _selectClearAt(),
|
||||
),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 0,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
avatar: Icon(
|
||||
Symbols.radio_button_unchecked,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
selected: _attitude == 2,
|
||||
label: Text('accountStatusNegative'.tr()),
|
||||
onSelected: (val) {
|
||||
if (val) setState(() => _attitude = 2);
|
||||
},
|
||||
),
|
||||
ChoiceChip(
|
||||
avatar: Icon(
|
||||
Symbols.contrast,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
selected: _attitude == 0,
|
||||
label: Text('accountStatusNeutral'.tr()),
|
||||
onSelected: (val) {
|
||||
if (val) setState(() => _attitude = 0);
|
||||
},
|
||||
),
|
||||
ChoiceChip(
|
||||
avatar: Icon(
|
||||
Symbols.circle,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
selected: _attitude == 1,
|
||||
label: Text('accountStatusPositive'.tr()),
|
||||
onSelected: (val) {
|
||||
if (val) setState(() => _attitude = 1);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(4),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 0,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
selected: _isSilent,
|
||||
label: Text('accountStatusSilent').tr(),
|
||||
onSelected: (val) {
|
||||
setState(() => _isSilent = val);
|
||||
},
|
||||
),
|
||||
ChoiceChip(
|
||||
selected: _isInvisible,
|
||||
label: Text('accountStatusInvisible').tr(),
|
||||
onSelected: (val) {
|
||||
setState(() => _isInvisible = val);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor:
|
||||
Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
|
||||
),
|
||||
onPressed: _isBusy ? null : () => Navigator.pop(context),
|
||||
child: Text('dialogCancel').tr(),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isBusy ? null : () => _applyStatus(),
|
||||
child: Text('dialogConfirm').tr(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
50
lib/widgets/account/badge.dart
Normal file
50
lib/widgets/account/badge.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:surface/screens/account/profile_page.dart' show kBadgesMeta;
|
||||
import 'package:surface/types/account.dart';
|
||||
|
||||
class AccountBadge extends StatelessWidget {
|
||||
final SnAccountBadge badge;
|
||||
final double radius;
|
||||
final EdgeInsets? padding;
|
||||
const AccountBadge({
|
||||
super.key,
|
||||
required this.badge,
|
||||
this.radius = 20,
|
||||
this.padding,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
richMessage: TextSpan(
|
||||
children: [
|
||||
TextSpan(text: kBadgesMeta[badge.type]?.$1.tr() ?? 'unknown'.tr()),
|
||||
if (badge.metadata['title'] != null)
|
||||
TextSpan(
|
||||
text: '\n${badge.metadata['title']}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(text: '\n'),
|
||||
TextSpan(
|
||||
text: DateFormat.yMEd().format(badge.createdAt),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Container(
|
||||
padding: padding ?? EdgeInsets.all(3),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
color: kBadgesMeta[badge.type]?.$3,
|
||||
),
|
||||
child: Icon(
|
||||
kBadgesMeta[badge.type]?.$2 ?? Symbols.question_mark,
|
||||
color: Colors.white,
|
||||
fill: 1,
|
||||
size: radius - 4,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -12,10 +12,10 @@ import 'package:surface/providers/config.dart';
|
||||
import 'package:surface/providers/keypair.dart';
|
||||
import 'package:surface/providers/user_directory.dart';
|
||||
import 'package:surface/providers/userinfo.dart';
|
||||
import 'package:surface/screens/account/profile_page.dart';
|
||||
import 'package:surface/types/chat.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/account/account_popover.dart';
|
||||
import 'package:surface/widgets/account/badge.dart';
|
||||
import 'package:surface/widgets/attachment/attachment_list.dart';
|
||||
import 'package:surface/widgets/context_menu.dart';
|
||||
import 'package:surface/widgets/link_preview.dart';
|
||||
@ -109,18 +109,10 @@ class ChatMessage extends StatelessWidget {
|
||||
child: AccountImage(
|
||||
content: user?.avatar,
|
||||
badge: (user?.badges.isNotEmpty ?? false)
|
||||
? Icon(
|
||||
kBadgesMeta[user!.badges.first.type]?.$2 ??
|
||||
Symbols.question_mark,
|
||||
color: kBadgesMeta[user.badges.first.type]?.$3,
|
||||
fill: 1,
|
||||
size: 18,
|
||||
shadows: [
|
||||
Shadow(
|
||||
offset: Offset(1, 1),
|
||||
blurRadius: 5.0,
|
||||
color: Color.fromARGB(200, 0, 0, 0)),
|
||||
],
|
||||
? AccountBadge(
|
||||
badge: user!.badges.first,
|
||||
radius: 16,
|
||||
padding: EdgeInsets.all(2),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
@ -29,6 +29,7 @@ import 'package:surface/types/attachment.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/types/reaction.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/account/badge.dart';
|
||||
import 'package:surface/widgets/attachment/attachment_item.dart';
|
||||
import 'package:surface/widgets/attachment/attachment_list.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
@ -43,8 +44,6 @@ import 'package:surface/widgets/post/publisher_popover.dart';
|
||||
import 'package:surface/widgets/universal_image.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
|
||||
import '../../screens/account/profile_page.dart' show kBadgesMeta;
|
||||
|
||||
class OpenablePostItem extends StatelessWidget {
|
||||
final SnPost data;
|
||||
final bool showReactions;
|
||||
@ -887,7 +886,7 @@ class _PostContentHeader extends StatelessWidget {
|
||||
'publisherId': data.publisherId,
|
||||
});
|
||||
if (!context.mounted) return;
|
||||
context.showSnackbar('postDeleted'.tr(args: ['#${data.id}']));
|
||||
onDeleted.call();
|
||||
} catch (err) {
|
||||
if (!context.mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
@ -930,19 +929,10 @@ class _PostContentHeader extends StatelessWidget {
|
||||
borderRadius:
|
||||
data.publisher.type == 1 ? (isCompact ? 4 : 8) : 20,
|
||||
badge: (user?.badges.isNotEmpty ?? false)
|
||||
? Icon(
|
||||
kBadgesMeta[user!.badges.first.type]?.$2 ??
|
||||
Symbols.question_mark,
|
||||
color: kBadgesMeta[user.badges.first.type]?.$3,
|
||||
fill: 1,
|
||||
size: 18,
|
||||
shadows: [
|
||||
Shadow(
|
||||
offset: Offset(1, 1),
|
||||
blurRadius: 5.0,
|
||||
color: Color.fromARGB(200, 0, 0, 0),
|
||||
),
|
||||
],
|
||||
? AccountBadge(
|
||||
badge: user!.badges.first,
|
||||
radius: 16,
|
||||
padding: EdgeInsets.all(2),
|
||||
)
|
||||
: null,
|
||||
)
|
||||
|
@ -9,10 +9,9 @@ import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/providers/user_directory.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/account/badge.dart';
|
||||
import 'package:surface/widgets/universal_image.dart';
|
||||
|
||||
import '../../screens/account/profile_page.dart' show kBadgesMeta;
|
||||
|
||||
class PublisherPopoverCard extends StatelessWidget {
|
||||
final SnPublisher data;
|
||||
|
||||
@ -76,39 +75,22 @@ class PublisherPopoverCard extends StatelessWidget {
|
||||
const Gap(8)
|
||||
],
|
||||
).padding(horizontal: 16),
|
||||
if (user != null && user.badges.isNotEmpty) const Gap(16),
|
||||
if (user != null && user.badges.isNotEmpty)
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
children: user.badges
|
||||
.map(
|
||||
(ele) => Tooltip(
|
||||
richMessage: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: kBadgesMeta[ele.type]?.$1.tr() ??
|
||||
'unknown'.tr()),
|
||||
if (ele.metadata['title'] != null)
|
||||
TextSpan(
|
||||
text: '\n${ele.metadata['title']}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(text: '\n'),
|
||||
TextSpan(
|
||||
text: DateFormat.yMEd().format(ele.createdAt),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Icon(
|
||||
kBadgesMeta[ele.type]?.$2 ?? Symbols.question_mark,
|
||||
color: kBadgesMeta[ele.type]?.$3,
|
||||
fill: 1,
|
||||
),
|
||||
),
|
||||
(ele) => AccountBadge(badge: ele),
|
||||
)
|
||||
.toList(),
|
||||
).padding(horizontal: 24),
|
||||
).padding(horizontal: 24, top: 16),
|
||||
const Gap(16),
|
||||
if (data.description.isNotEmpty)
|
||||
Text(
|
||||
data.description,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
).padding(horizontal: 26, bottom: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 2.4.2+77
|
||||
version: 2.4.2+78
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.4
|
||||
|
Reference in New Issue
Block a user