✨ Status basis
This commit is contained in:
parent
7c35323279
commit
d91680ada7
@ -15,6 +15,7 @@ import 'package:solian/providers/content/channel.dart';
|
|||||||
import 'package:solian/providers/content/post.dart';
|
import 'package:solian/providers/content/post.dart';
|
||||||
import 'package:solian/providers/content/realm.dart';
|
import 'package:solian/providers/content/realm.dart';
|
||||||
import 'package:solian/providers/friend.dart';
|
import 'package:solian/providers/friend.dart';
|
||||||
|
import 'package:solian/providers/status.dart';
|
||||||
import 'package:solian/router.dart';
|
import 'package:solian/router.dart';
|
||||||
import 'package:solian/theme.dart';
|
import 'package:solian/theme.dart';
|
||||||
import 'package:solian/translations.dart';
|
import 'package:solian/translations.dart';
|
||||||
@ -79,6 +80,7 @@ class SolianApp extends StatelessWidget {
|
|||||||
Get.lazyPut(() => AttachmentProvider());
|
Get.lazyPut(() => AttachmentProvider());
|
||||||
Get.lazyPut(() => ChatProvider());
|
Get.lazyPut(() => ChatProvider());
|
||||||
Get.lazyPut(() => AccountProvider());
|
Get.lazyPut(() => AccountProvider());
|
||||||
|
Get.lazyPut(() => StatusController());
|
||||||
Get.lazyPut(() => ChannelProvider());
|
Get.lazyPut(() => ChannelProvider());
|
||||||
Get.lazyPut(() => RealmProvider());
|
Get.lazyPut(() => RealmProvider());
|
||||||
Get.lazyPut(() => ChatCallProvider());
|
Get.lazyPut(() => ChatCallProvider());
|
||||||
|
27
lib/models/account_status.dart
Normal file
27
lib/models/account_status.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
class AccountStatus {
|
||||||
|
bool isDisturbable;
|
||||||
|
bool isOnline;
|
||||||
|
DateTime? lastSeenAt;
|
||||||
|
dynamic status;
|
||||||
|
|
||||||
|
AccountStatus({
|
||||||
|
required this.isDisturbable,
|
||||||
|
required this.isOnline,
|
||||||
|
required this.lastSeenAt,
|
||||||
|
required this.status,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AccountStatus.fromJson(Map<String, dynamic> json) => AccountStatus(
|
||||||
|
isDisturbable: json['is_disturbable'],
|
||||||
|
isOnline: json['is_online'],
|
||||||
|
lastSeenAt: json['last_seen_at'] != null ? DateTime.parse(json['last_seen_at']) : null,
|
||||||
|
status: json['status'],
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'is_disturbable': isDisturbable,
|
||||||
|
'is_online': isOnline,
|
||||||
|
'last_seen_at': lastSeenAt?.toIso8601String(),
|
||||||
|
'status': status,
|
||||||
|
};
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
class PersonalPage {
|
|
||||||
int id;
|
|
||||||
DateTime createdAt;
|
|
||||||
DateTime updatedAt;
|
|
||||||
DateTime? deletedAt;
|
|
||||||
String content;
|
|
||||||
String script;
|
|
||||||
String style;
|
|
||||||
Map<String, String>? links;
|
|
||||||
int accountId;
|
|
||||||
|
|
||||||
PersonalPage({
|
|
||||||
required this.id,
|
|
||||||
required this.createdAt,
|
|
||||||
required this.updatedAt,
|
|
||||||
required this.deletedAt,
|
|
||||||
required this.content,
|
|
||||||
required this.script,
|
|
||||||
required this.style,
|
|
||||||
required this.links,
|
|
||||||
required this.accountId,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory PersonalPage.fromJson(Map<String, dynamic> json) => PersonalPage(
|
|
||||||
id: json['id'],
|
|
||||||
createdAt: DateTime.parse(json['created_at']),
|
|
||||||
updatedAt: DateTime.parse(json['updated_at']),
|
|
||||||
deletedAt: json['deleted_at'] != null
|
|
||||||
? DateTime.parse(json['deleted_at'])
|
|
||||||
: null,
|
|
||||||
content: json['content'],
|
|
||||||
script: json['script'],
|
|
||||||
style: json['style'],
|
|
||||||
links: json['links'],
|
|
||||||
accountId: json['account_id'],
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
|
||||||
'id': id,
|
|
||||||
'created_at': createdAt.toIso8601String(),
|
|
||||||
'updated_at': updatedAt.toIso8601String(),
|
|
||||||
'deleted_at': deletedAt?.toIso8601String(),
|
|
||||||
'content': content,
|
|
||||||
'script': script,
|
|
||||||
'style': style,
|
|
||||||
'links': links,
|
|
||||||
'account_id': accountId,
|
|
||||||
};
|
|
||||||
}
|
|
56
lib/providers/status.dart
Normal file
56
lib/providers/status.dart
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:solian/models/account_status.dart';
|
||||||
|
import 'package:solian/providers/auth.dart';
|
||||||
|
import 'package:solian/services.dart';
|
||||||
|
|
||||||
|
class StatusController extends GetConnect {
|
||||||
|
static Map<String, (Widget, String, String?)> presetStatuses = {
|
||||||
|
'online': (
|
||||||
|
const Icon(Icons.circle, color: Colors.green),
|
||||||
|
'accountStatusOnline'.tr,
|
||||||
|
null,
|
||||||
|
),
|
||||||
|
'silent': (
|
||||||
|
const Icon(Icons.do_not_disturb_on, color: Colors.red),
|
||||||
|
'accountStatusSilent'.tr,
|
||||||
|
'accountStatusSilentDesc'.tr,
|
||||||
|
),
|
||||||
|
'invisible': (
|
||||||
|
const Icon(Icons.circle, color: Colors.grey),
|
||||||
|
'accountStatusInvisible'.tr,
|
||||||
|
'accountStatusInvisibleDesc'.tr,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
final AuthProvider auth = Get.find();
|
||||||
|
|
||||||
|
httpClient.baseUrl = ServiceFinder.services['passport'];
|
||||||
|
httpClient.addAuthenticator(auth.requestAuthenticator);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Response> getCurrentStatus() => get('/api/users/me/status');
|
||||||
|
|
||||||
|
Future<Response> getSomeoneStatus(String name) =>
|
||||||
|
get('/api/users/$name/status');
|
||||||
|
|
||||||
|
static (Widget, String) determineStatus(AccountStatus status,
|
||||||
|
{double size = 14}) {
|
||||||
|
Widget icon;
|
||||||
|
String? text = status.status?.label;
|
||||||
|
|
||||||
|
if (status.isDisturbable && status.isOnline) {
|
||||||
|
icon = Icon(Icons.circle, color: Colors.green, size: size);
|
||||||
|
text ??= 'accountStatusOnline'.tr;
|
||||||
|
} else if (!status.isDisturbable && status.isOnline) {
|
||||||
|
icon = Icon(Icons.do_not_disturb_on, color: Colors.red, size: size);
|
||||||
|
text ??= 'accountStatusSilent'.tr;
|
||||||
|
} else {
|
||||||
|
icon = Icon(Icons.circle, color: Colors.grey, size: size);
|
||||||
|
text ??= 'accountStatusOffline'.tr;
|
||||||
|
}
|
||||||
|
return (icon, text);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:solian/models/account.dart';
|
import 'package:solian/models/account.dart';
|
||||||
import 'package:solian/providers/auth.dart';
|
import 'package:solian/providers/auth.dart';
|
||||||
|
import 'package:solian/providers/status.dart';
|
||||||
import 'package:solian/router.dart';
|
import 'package:solian/router.dart';
|
||||||
import 'package:solian/screens/auth/signin.dart';
|
import 'package:solian/screens/auth/signin.dart';
|
||||||
import 'package:solian/screens/auth/signup.dart';
|
import 'package:solian/screens/auth/signup.dart';
|
||||||
@ -132,6 +133,7 @@ class AccountHeading extends StatelessWidget {
|
|||||||
name: prof.body['name'],
|
name: prof.body['name'],
|
||||||
nick: prof.body['nick'],
|
nick: prof.body['nick'],
|
||||||
desc: prof.body['description'],
|
desc: prof.body['description'],
|
||||||
|
status: Get.find<StatusController>().getCurrentStatus(),
|
||||||
badges: prof.body['badges']
|
badges: prof.body['badges']
|
||||||
?.map((e) => AccountBadge.fromJson(e))
|
?.map((e) => AccountBadge.fromJson(e))
|
||||||
.toList()
|
.toList()
|
||||||
|
@ -216,6 +216,15 @@ class SolianMessages extends Translations {
|
|||||||
'pushNotifyRegisterDone': 'Push notifications has been activated.',
|
'pushNotifyRegisterDone': 'Push notifications has been activated.',
|
||||||
'pushNotifyRegisterFailed':
|
'pushNotifyRegisterFailed':
|
||||||
'Unable to active push notification... @reason',
|
'Unable to active push notification... @reason',
|
||||||
|
'accountChangeStatus': 'Change Status',
|
||||||
|
'accountCustomStatus': 'Set Custom Status',
|
||||||
|
'accountClearStatus': 'Clear Status',
|
||||||
|
'accountStatusOnline': 'Online',
|
||||||
|
'accountStatusSilent': 'Do not Disturb',
|
||||||
|
'accountStatusSilentDesc': 'The notification will stop popping up',
|
||||||
|
'accountStatusInvisible': 'Invisible',
|
||||||
|
'accountStatusInvisibleDesc': 'Will show as offline, but all features still remain normal',
|
||||||
|
'accountStatusOffline': 'Offline',
|
||||||
},
|
},
|
||||||
'zh_CN': {
|
'zh_CN': {
|
||||||
'hide': '隐藏',
|
'hide': '隐藏',
|
||||||
@ -415,6 +424,15 @@ class SolianMessages extends Translations {
|
|||||||
'激活推送通知便可以让你在应用程序完全关闭的时候仍然获取到我们最新的通知。在 iOS/macOS 设备上我们使用 Apple 官方的推送服务;其他设备则通过 Google Firebase 提供推送通知。要注册推送通知设备,您可能需要连接到 Google 的服务器(在中国大陆不可用)并在您的设备上安装 Google Framework。即使您关闭此对话框,下次启动应用程序时仍会自动执行此注册。',
|
'激活推送通知便可以让你在应用程序完全关闭的时候仍然获取到我们最新的通知。在 iOS/macOS 设备上我们使用 Apple 官方的推送服务;其他设备则通过 Google Firebase 提供推送通知。要注册推送通知设备,您可能需要连接到 Google 的服务器(在中国大陆不可用)并在您的设备上安装 Google Framework。即使您关闭此对话框,下次启动应用程序时仍会自动执行此注册。',
|
||||||
'pushNotifyRegisterDone': '推送通知已成功激活',
|
'pushNotifyRegisterDone': '推送通知已成功激活',
|
||||||
'pushNotifyRegisterFailed': '推送通知激活失败…… @reason',
|
'pushNotifyRegisterFailed': '推送通知激活失败…… @reason',
|
||||||
|
'accountChangeStatus': '变更状态',
|
||||||
|
'accountCustomStatus': '自定义状态',
|
||||||
|
'accountClearStatus': '清除状态',
|
||||||
|
'accountStatusOnline': '在线',
|
||||||
|
'accountStatusSilent': '请勿打扰',
|
||||||
|
'accountStatusSilentDesc': '将会暂停所有通知推送',
|
||||||
|
'accountStatusInvisible': '隐身',
|
||||||
|
'accountStatusInvisibleDesc': '将会在他人界面显示离线,但不影响功能使用',
|
||||||
|
'accountStatusOffline': '离线',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:solian/models/account.dart';
|
import 'package:solian/models/account.dart';
|
||||||
|
import 'package:solian/models/account_status.dart';
|
||||||
import 'package:solian/platform.dart';
|
import 'package:solian/platform.dart';
|
||||||
|
import 'package:solian/providers/status.dart';
|
||||||
import 'package:solian/widgets/account/account_avatar.dart';
|
import 'package:solian/widgets/account/account_avatar.dart';
|
||||||
import 'package:solian/widgets/account/account_badge.dart';
|
import 'package:solian/widgets/account/account_badge.dart';
|
||||||
|
import 'package:solian/widgets/account/account_status_action.dart';
|
||||||
|
|
||||||
class AccountHeadingWidget extends StatelessWidget {
|
class AccountHeadingWidget extends StatelessWidget {
|
||||||
final dynamic avatar;
|
final dynamic avatar;
|
||||||
@ -13,6 +16,9 @@ class AccountHeadingWidget extends StatelessWidget {
|
|||||||
final String? desc;
|
final String? desc;
|
||||||
final List<AccountBadge>? badges;
|
final List<AccountBadge>? badges;
|
||||||
|
|
||||||
|
final Future<Response>? status;
|
||||||
|
final Function? onEditStatus;
|
||||||
|
|
||||||
const AccountHeadingWidget({
|
const AccountHeadingWidget({
|
||||||
super.key,
|
super.key,
|
||||||
this.avatar,
|
this.avatar,
|
||||||
@ -21,8 +27,18 @@ class AccountHeadingWidget extends StatelessWidget {
|
|||||||
required this.nick,
|
required this.nick,
|
||||||
required this.desc,
|
required this.desc,
|
||||||
required this.badges,
|
required this.badges,
|
||||||
|
this.status,
|
||||||
|
this.onEditStatus,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
void showStatusAction(BuildContext context, bool hasStatus) {
|
||||||
|
showModalBottomSheet(
|
||||||
|
useRootNavigator: true,
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AccountStatusAction(hasStatus: hasStatus),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Material(
|
return Material(
|
||||||
@ -55,23 +71,59 @@ class AccountHeadingWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
||||||
textBaseline: TextBaseline.alphabetic,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Row(
|
||||||
nick,
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||||
style: const TextStyle(
|
textBaseline: TextBaseline.alphabetic,
|
||||||
fontSize: 17,
|
children: [
|
||||||
fontWeight: FontWeight.bold,
|
Text(
|
||||||
),
|
nick,
|
||||||
).paddingOnly(right: 4),
|
style: const TextStyle(
|
||||||
Text(
|
fontSize: 17,
|
||||||
'@$name',
|
fontWeight: FontWeight.bold,
|
||||||
style: const TextStyle(
|
),
|
||||||
fontSize: 15,
|
).paddingOnly(right: 4),
|
||||||
),
|
Text(
|
||||||
|
'@$name',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
if (status != null)
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: FutureBuilder(
|
||||||
|
future: status,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (!snapshot.hasData || snapshot.data!.body == null) {
|
||||||
|
return Text('loading'.tr);
|
||||||
|
}
|
||||||
|
|
||||||
|
final info = StatusController.determineStatus(
|
||||||
|
AccountStatus.fromJson(snapshot.data!.body),
|
||||||
|
);
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(info.$2),
|
||||||
|
info.$1.paddingSymmetric(horizontal: 6),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
showStatusAction(
|
||||||
|
context,
|
||||||
|
snapshot.data!.body['status'] != null,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
).paddingOnly(left: 116, top: 6),
|
).paddingOnly(left: 116, top: 6),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:solian/exts.dart';
|
import 'package:solian/exts.dart';
|
||||||
import 'package:solian/models/account.dart';
|
import 'package:solian/models/account.dart';
|
||||||
|
import 'package:solian/providers/status.dart';
|
||||||
import 'package:solian/services.dart';
|
import 'package:solian/services.dart';
|
||||||
import 'package:solian/widgets/account/account_heading.dart';
|
import 'package:solian/widgets/account/account_heading.dart';
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ class _AccountProfilePopupState extends State<AccountProfilePopup> {
|
|||||||
nick: _userinfo!.nick,
|
nick: _userinfo!.nick,
|
||||||
desc: _userinfo!.description,
|
desc: _userinfo!.description,
|
||||||
badges: _userinfo!.badges,
|
badges: _userinfo!.badges,
|
||||||
|
status: Get.find<StatusController>().getSomeoneStatus(_userinfo!.name),
|
||||||
).paddingOnly(top: 16),
|
).paddingOnly(top: 16),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
62
lib/widgets/account/account_status_action.dart
Normal file
62
lib/widgets/account/account_status_action.dart
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:solian/providers/status.dart';
|
||||||
|
|
||||||
|
class AccountStatusAction extends StatelessWidget {
|
||||||
|
final bool hasStatus;
|
||||||
|
|
||||||
|
const AccountStatusAction({super.key, this.hasStatus = false});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'accountChangeStatus'.tr,
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
||||||
|
Expanded(
|
||||||
|
child: ListView(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
height: 48,
|
||||||
|
child: ListView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
children: StatusController.presetStatuses.entries
|
||||||
|
.map(
|
||||||
|
(x) => ActionChip(
|
||||||
|
avatar: x.value.$1,
|
||||||
|
label: Text(x.value.$2),
|
||||||
|
tooltip: x.value.$3,
|
||||||
|
onPressed: () {},
|
||||||
|
).paddingOnly(right: 6),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
).paddingSymmetric(horizontal: 18),
|
||||||
|
),
|
||||||
|
const Divider(thickness: 0.3, height: 0.3)
|
||||||
|
.paddingSymmetric(vertical: 16),
|
||||||
|
ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
leading: hasStatus
|
||||||
|
? const Icon(Icons.edit)
|
||||||
|
: const Icon(Icons.add),
|
||||||
|
title: Text('accountCustomStatus'.tr),
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
leading: const Icon(Icons.clear),
|
||||||
|
title: Text('accountClearStatus'.tr),
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -31,7 +31,6 @@ class _PostQuickActionState extends State<PostQuickAction> {
|
|||||||
void showReactMenu() {
|
void showReactMenu() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
isScrollControlled: true,
|
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => PostReactionPopup(
|
builder: (context) => PostReactionPopup(
|
||||||
item: widget.item,
|
item: widget.item,
|
||||||
|
@ -12,7 +12,6 @@ class PostReactionPopup extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: MediaQuery.of(context).size.height * 0.85,
|
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
Loading…
Reference in New Issue
Block a user