Realm basis

This commit is contained in:
LittleSheep 2024-05-05 23:01:08 +08:00
parent cf0d473a40
commit 384d861d56
26 changed files with 851 additions and 147 deletions

View File

@ -2,6 +2,7 @@
"appName": "Solar Network", "appName": "Solar Network",
"explore": "Explore", "explore": "Explore",
"chat": "Chat", "chat": "Chat",
"realm": "Realm",
"account": "Account", "account": "Account",
"riskDetection": "Risk Detection", "riskDetection": "Risk Detection",
"signIn": "Sign In", "signIn": "Sign In",
@ -74,6 +75,18 @@
"postEditNotify": "You are about editing a post that already published.", "postEditNotify": "You are about editing a post that already published.",
"reactionAdded": "Your reaction has been added.", "reactionAdded": "Your reaction has been added.",
"reactionRemoved": "Your reaction has been removed.", "reactionRemoved": "Your reaction has been removed.",
"realmNew": "New Realm",
"realmNewCreate": "Create a realm",
"realmNewJoin": "Join a exists realm",
"realmUsage": "Realm",
"realmUsageCaption": "Realm is a place to organize your posts, channels and more. It will be much easier if you build community with realm!",
"realmEstablish": "Establish a realm",
"realmEditNotify": "You are about editing a existing realm.",
"realmAliasLabel": "Realm Alias",
"realmNameLabel": "Realm Name",
"realmDescriptionLabel": "Realm Description",
"realmPublicLabel": "It's public",
"realmCommunityLabel": "It's community realm",
"chatNew": "New Chat", "chatNew": "New Chat",
"chatNewCreate": "Create a channel", "chatNewCreate": "Create a channel",
"chatNewJoin": "Join a exists channel", "chatNewJoin": "Join a exists channel",

View File

@ -5,6 +5,7 @@ import 'package:solian/providers/chat.dart';
import 'package:solian/providers/friend.dart'; import 'package:solian/providers/friend.dart';
import 'package:solian/providers/navigation.dart'; import 'package:solian/providers/navigation.dart';
import 'package:solian/providers/notify.dart'; import 'package:solian/providers/notify.dart';
import 'package:solian/providers/realm.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/utils/theme.dart'; import 'package:solian/utils/theme.dart';
import 'package:solian/utils/timeago.dart'; import 'package:solian/utils/timeago.dart';
@ -43,6 +44,7 @@ class SolianApp extends StatelessWidget {
ChangeNotifierProvider(create: (_) => ChatProvider()), ChangeNotifierProvider(create: (_) => ChatProvider()),
ChangeNotifierProvider(create: (_) => NotifyProvider()), ChangeNotifierProvider(create: (_) => NotifyProvider()),
ChangeNotifierProvider(create: (_) => FriendProvider()), ChangeNotifierProvider(create: (_) => FriendProvider()),
ChangeNotifierProvider(create: (_) => RealmProvider()),
], ],
child: Overlay( child: Overlay(
initialEntries: [ initialEntries: [

View File

@ -9,7 +9,7 @@ class Notification {
bool isImportant; bool isImportant;
bool isRealtime; bool isRealtime;
DateTime? readAt; DateTime? readAt;
int senderId; int? senderId;
int recipientId; int recipientId;
Notification({ Notification({
@ -23,7 +23,7 @@ class Notification {
required this.isImportant, required this.isImportant,
required this.isRealtime, required this.isRealtime,
this.readAt, this.readAt,
required this.senderId, this.senderId,
required this.recipientId, required this.recipientId,
}); });
@ -34,9 +34,7 @@ class Notification {
deletedAt: json['deleted_at'], deletedAt: json['deleted_at'],
subject: json['subject'], subject: json['subject'],
content: json['content'], content: json['content'],
links: json['links'] != null links: json['links'] != null ? List<Link>.from(json['links'].map((x) => Link.fromJson(x))) : List.empty(),
? List<Link>.from(json['links'].map((x) => Link.fromJson(x)))
: List.empty(),
isImportant: json['is_important'], isImportant: json['is_important'],
isRealtime: json['is_realtime'], isRealtime: json['is_realtime'],
readAt: json['read_at'], readAt: json['read_at'],
@ -51,9 +49,7 @@ class Notification {
'deleted_at': deletedAt, 'deleted_at': deletedAt,
'subject': subject, 'subject': subject,
'content': content, 'content': content,
'links': links != null 'links': links != null ? List<dynamic>.from(links!.map((x) => x.toJson())) : List.empty(),
? List<dynamic>.from(links!.map((x) => x.toJson()))
: List.empty(),
'is_important': isImportant, 'is_important': isImportant,
'is_realtime': isRealtime, 'is_realtime': isRealtime,
'read_at': readAt, 'read_at': readAt,

55
lib/models/realm.dart Normal file
View File

@ -0,0 +1,55 @@
class Realm {
int id;
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
String alias;
String name;
String description;
dynamic members;
bool isPublic;
bool isCommunity;
int accountId;
Realm({
required this.id,
required this.createdAt,
required this.updatedAt,
this.deletedAt,
required this.alias,
required this.name,
required this.description,
required this.members,
required this.isPublic,
required this.isCommunity,
required this.accountId,
});
factory Realm.fromJson(Map<String, dynamic> json) => Realm(
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,
alias: json['alias'],
name: json['name'],
description: json['description'],
members: json['members'],
isPublic: json['is_public'],
isCommunity: json['is_community'],
accountId: json['account_id'],
);
Map<String, dynamic> toJson() => {
'id': id,
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'alias': alias,
'name': name,
'description': description,
'members': members,
'is_public': isPublic,
'is_community': isCommunity,
'account_id': accountId,
};
}

View File

@ -44,10 +44,10 @@ class ChatProvider extends ChangeNotifier {
return channel; return channel;
} }
Future<Channel> fetchChannel(String alias) async { Future<Channel> fetchChannel(String alias, String realm) async {
final Client client = Client(); final Client client = Client();
var uri = getRequestUri('messaging', '/api/channels/global/$alias'); var uri = getRequestUri('messaging', '/api/channels/$realm/$alias');
var res = await client.get(uri); var res = await client.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes)); final result = jsonDecode(utf8.decode(res.bodyBytes));
@ -60,10 +60,10 @@ class ChatProvider extends ChangeNotifier {
} }
} }
Future<Call?> fetchOngoingCall(String alias) async { Future<Call?> fetchOngoingCall(String alias, String realm) async {
final Client client = Client(); final Client client = Client();
var uri = getRequestUri('messaging', '/api/channels/global/$alias/calls/ongoing'); var uri = getRequestUri('messaging', '/api/channels/$realm/$alias/calls/ongoing');
var res = await client.get(uri); var res = await client.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes)); final result = jsonDecode(utf8.decode(res.bodyBytes));

42
lib/providers/realm.dart Normal file
View File

@ -0,0 +1,42 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/utils/service_url.dart';
class RealmProvider with ChangeNotifier {
List<Realm> realms = List.empty();
Realm? focusRealm;
Future<void> fetch(AuthProvider auth) async {
if (!await auth.isAuthorized()) return;
var uri = getRequestUri('passport', '/api/realms/me/available');
var res = await auth.client!.get(uri);
if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes)) as List<dynamic>;
realms = result.map((x) => Realm.fromJson(x)).toList();
notifyListeners();
} else {
var message = utf8.decode(res.bodyBytes);
throw Exception(message);
}
}
Future<Realm> fetchSingle(AuthProvider auth, String alias) async {
var uri = getRequestUri('passport', '/api/realms/$alias');
var res = await auth.client!.get(uri);
if (res.statusCode == 200) {
final result = jsonDecode(utf8.decode(res.bodyBytes));
focusRealm = Realm.fromJson(result);
notifyListeners();
return focusRealm!;
} else {
var message = utf8.decode(res.bodyBytes);
throw Exception(message);
}
}
}

View File

@ -3,6 +3,7 @@ import 'package:go_router/go_router.dart';
import 'package:solian/models/call.dart'; import 'package:solian/models/call.dart';
import 'package:solian/models/channel.dart'; import 'package:solian/models/channel.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/screens/account.dart'; import 'package:solian/screens/account.dart';
import 'package:solian/screens/account/friend.dart'; import 'package:solian/screens/account/friend.dart';
import 'package:solian/screens/account/personalize.dart'; import 'package:solian/screens/account/personalize.dart';
@ -19,6 +20,9 @@ import 'package:solian/screens/posts/comment_editor.dart';
import 'package:solian/screens/posts/moment_editor.dart'; import 'package:solian/screens/posts/moment_editor.dart';
import 'package:solian/screens/posts/screen.dart'; import 'package:solian/screens/posts/screen.dart';
import 'package:solian/screens/auth/signin.dart'; import 'package:solian/screens/auth/signin.dart';
import 'package:solian/screens/realms/realm.dart';
import 'package:solian/screens/realms/realm_editor.dart';
import 'package:solian/screens/realms/realm_list.dart';
import 'package:solian/screens/users/userinfo.dart'; import 'package:solian/screens/users/userinfo.dart';
import 'package:solian/utils/theme.dart'; import 'package:solian/utils/theme.dart';
import 'package:solian/widgets/empty.dart'; import 'package:solian/widgets/empty.dart';
@ -65,7 +69,7 @@ abstract class SolianRouter {
), ),
GoRoute( GoRoute(
path: '/posts/:dataset/:alias', path: '/posts/:dataset/:alias',
name: 'posts.screen', name: 'posts.details',
builder: (context, state) => PostScreen( builder: (context, state) => PostScreen(
alias: state.pathParameters['alias'] as String, alias: state.pathParameters['alias'] as String,
dataset: state.pathParameters['dataset'] as String, dataset: state.pathParameters['dataset'] as String,
@ -73,6 +77,73 @@ abstract class SolianRouter {
), ),
], ],
), ),
ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder(
context,
state,
SolianTheme.isLargeScreen(context)
? TwoColumnLayout(
sideChild: const RealmListScreen(),
mainChild: child,
)
: child,
),
routes: [
GoRoute(
path: '/realms',
name: 'realms',
builder: (context, state) =>
!SolianTheme.isLargeScreen(context) ? const RealmListScreen() : const PageEmptyWidget(),
),
GoRoute(
path: '/realms/editor',
name: 'realms.editor',
builder: (context, state) => RealmEditorScreen(
editing: state.extra as Realm?,
realm: state.uri.queryParameters['realm'],
),
),
GoRoute(
path: '/realms/:realm/posts/:dataset/:alias',
name: 'realms.posts.details',
builder: (context, state) => PostScreen(
alias: state.pathParameters['alias'] as String,
dataset: state.pathParameters['dataset'] as String,
),
),
GoRoute(
path: '/realms/:realm',
name: 'realms.details',
builder: (context, state) => !SolianTheme.isLargeScreen(context)
? RealmScreen(alias: state.pathParameters['realm'] as String)
: const PageEmptyWidget(),
),
GoRoute(
path: '/realms/:realm/chat/:channel',
name: 'realms.chat.channel',
builder: (context, state) => ChatScreen(
alias: state.pathParameters['channel'] as String,
realm: state.pathParameters['realm'] as String,
),
),
GoRoute(
path: '/realms/:realm/chat/:channel/manage',
name: 'realms.chat.channel.manage',
builder: (context, state) => ChatDetailScreen(
channel: state.extra as Channel,
realm: state.pathParameters['realm'] as String,
),
),
GoRoute(
path: '/realms/:realm/chat/:channel/member',
name: 'realms.chat.channel.member',
builder: (context, state) => ChatMemberScreen(
channel: state.extra as Channel,
realm: state.pathParameters['realm'] as String,
),
),
],
),
ShellRoute( ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder( pageBuilder: (context, state, child) => defaultPageBuilder(
context, context,
@ -92,32 +163,35 @@ abstract class SolianRouter {
!SolianTheme.isLargeScreen(context) ? const ChatListScreen() : const PageEmptyWidget(), !SolianTheme.isLargeScreen(context) ? const ChatListScreen() : const PageEmptyWidget(),
), ),
GoRoute( GoRoute(
path: '/chat/create', path: '/chat/editor',
name: 'chat.channel.editor', name: 'chat.channel.editor',
builder: (context, state) => ChannelEditorScreen(editing: state.extra as Channel?), builder: (context, state) => ChannelEditorScreen(
editing: state.extra as Channel?,
realm: state.uri.queryParameters['realm'],
),
), ),
GoRoute( GoRoute(
path: '/chat/c/:channel', path: '/chat/:channel',
name: 'chat.channel', name: 'chat.channel',
builder: (context, state) => ChatScreen(alias: state.pathParameters['channel'] as String), builder: (context, state) => ChatScreen(alias: state.pathParameters['channel'] as String),
), ),
GoRoute( GoRoute(
path: '/chat/c/:channel/call', path: '/chat/:channel/manage',
name: 'chat.channel.call',
builder: (context, state) => ChatCall(call: state.extra as Call),
),
GoRoute(
path: '/chat/c/:channel/manage',
name: 'chat.channel.manage', name: 'chat.channel.manage',
builder: (context, state) => ChatDetailScreen(channel: state.extra as Channel), builder: (context, state) => ChatDetailScreen(channel: state.extra as Channel),
), ),
GoRoute( GoRoute(
path: '/chat/c/:channel/member', path: '/chat/:channel/member',
name: 'chat.channel.member', name: 'chat.channel.member',
builder: (context, state) => ChatMemberScreen(channel: state.extra as Channel), builder: (context, state) => ChatMemberScreen(channel: state.extra as Channel),
), ),
], ],
), ),
GoRoute(
path: '/chat/:channel/call',
name: 'chat.channel.call',
builder: (context, state) => ChatCall(call: state.extra as Call),
),
ShellRoute( ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder( pageBuilder: (context, state, child) => defaultPageBuilder(
context, context,

View File

@ -15,8 +15,9 @@ import 'package:uuid/uuid.dart';
class ChannelEditorScreen extends StatefulWidget { class ChannelEditorScreen extends StatefulWidget {
final Channel? editing; final Channel? editing;
final String? realm;
const ChannelEditorScreen({super.key, this.editing}); const ChannelEditorScreen({super.key, this.editing, this.realm});
@override @override
State<ChannelEditorScreen> createState() => _ChannelEditorScreenState(); State<ChannelEditorScreen> createState() => _ChannelEditorScreenState();
@ -39,8 +40,8 @@ class _ChannelEditorScreenState extends State<ChannelEditorScreen> {
} }
final uri = widget.editing == null final uri = widget.editing == null
? getRequestUri('messaging', '/api/channels/global') ? getRequestUri('messaging', '/api/channels/${widget.realm ?? 'global'}')
: getRequestUri('messaging', '/api/channels/global/${widget.editing!.id}'); : getRequestUri('messaging', '/api/channels/${widget.realm ?? 'global'}/${widget.editing!.id}');
final req = Request(widget.editing == null ? 'POST' : 'PUT', uri); final req = Request(widget.editing == null ? 'POST' : 'PUT', uri);
req.headers['Content-Type'] = 'application/json'; req.headers['Content-Type'] = 'application/json';

View File

@ -15,8 +15,9 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ChatMemberScreen extends StatefulWidget { class ChatMemberScreen extends StatefulWidget {
final Channel channel; final Channel channel;
final String realm;
const ChatMemberScreen({super.key, required this.channel}); const ChatMemberScreen({super.key, required this.channel, this.realm = 'global'});
@override @override
State<ChatMemberScreen> createState() => _ChatMemberScreenState(); State<ChatMemberScreen> createState() => _ChatMemberScreenState();
@ -36,8 +37,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
_selfId = prof['id']; _selfId = prof['id'];
var uri = getRequestUri( var uri = getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel.alias}/members');
'messaging', '/api/channels/global/${widget.channel.alias}/members');
var res = await auth.client!.get(uri); var res = await auth.client!.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
@ -51,7 +51,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
} }
} }
Future<void> kickMember(ChannelMember item) async { Future<void> removeMember(ChannelMember item) async {
setState(() => _isSubmitting = true); setState(() => _isSubmitting = true);
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
@ -60,10 +60,9 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
return; return;
} }
var uri = getRequestUri( var uri = getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}');
'messaging', '/api/channels/global/${widget.channel.alias}/kick');
var res = await auth.client!.post( var res = await auth.client!.delete(
uri, uri,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -82,7 +81,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
setState(() => _isSubmitting = false); setState(() => _isSubmitting = false);
} }
Future<void> inviteMember(String username) async { Future<void> addMember(String username) async {
setState(() => _isSubmitting = true); setState(() => _isSubmitting = true);
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
@ -91,8 +90,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
return; return;
} }
var uri = getRequestUri( var uri = getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel.alias}');
'messaging', '/api/channels/global/${widget.channel.alias}/invite');
var res = await auth.client!.post( var res = await auth.client!.post(
uri, uri,
@ -122,10 +120,10 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
); );
if (input == null) return; if (input == null) return;
await inviteMember((input as Account).name); await addMember((input as Account).name);
} }
bool getKickable(ChannelMember item) { bool getRemovable(ChannelMember item) {
if (_selfId != widget.channel.account.externalId) return false; if (_selfId != widget.channel.account.externalId) return false;
if (item.accountId == widget.channel.accountId) return false; if (item.accountId == widget.channel.accountId) return false;
if (item.account.externalId == _selfId) return false; if (item.account.externalId == _selfId) return false;
@ -156,9 +154,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
child: CustomScrollView( child: CustomScrollView(
slivers: [ slivers: [
SliverToBoxAdapter( SliverToBoxAdapter(
child: _isSubmitting child: _isSubmitting ? const LinearProgressIndicator().animate().scaleX() : Container(),
? const LinearProgressIndicator().animate().scaleX()
: Container(),
), ),
SliverList.builder( SliverList.builder(
itemCount: _members.length, itemCount: _members.length,
@ -169,9 +165,7 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
return Dismissible( return Dismissible(
key: Key(randomId.toString()), key: Key(randomId.toString()),
direction: getKickable(element) direction: getRemovable(element) ? DismissDirection.startToEnd : DismissDirection.none,
? DismissDirection.startToEnd
: DismissDirection.none,
background: Container( background: Container(
color: Colors.red, color: Colors.red,
padding: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.symmetric(horizontal: 20),
@ -179,13 +173,12 @@ class _ChatMemberScreenState extends State<ChatMemberScreen> {
child: const Icon(Icons.remove, color: Colors.white), child: const Icon(Icons.remove, color: Colors.white),
), ),
child: ListTile( child: ListTile(
leading: AccountAvatar( leading: AccountAvatar(source: element.account.avatar, direct: true),
source: element.account.avatar, direct: true),
title: Text(element.account.nick), title: Text(element.account.nick),
subtitle: Text(element.account.name), subtitle: Text(element.account.name),
), ),
onDismissed: (_) { onDismissed: (_) {
kickMember(element); removeMember(element);
}, },
); );
}, },

View File

@ -21,8 +21,9 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ChatScreen extends StatelessWidget { class ChatScreen extends StatelessWidget {
final String alias; final String alias;
final String realm;
const ChatScreen({super.key, required this.alias}); const ChatScreen({super.key, required this.alias, this.realm = 'global'});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -37,31 +38,35 @@ class ChatScreen extends StatelessWidget {
ChannelCallAction( ChannelCallAction(
call: chat.ongoingCall, call: chat.ongoingCall,
channel: chat.focusChannel!, channel: chat.focusChannel!,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias), realm: realm,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias, realm),
), ),
ChannelManageAction( ChannelManageAction(
channel: chat.focusChannel!, channel: chat.focusChannel!,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias), realm: realm,
onUpdate: () => chat.fetchChannel(chat.focusChannel!.alias, realm),
), ),
] ]
: [], : [],
child: ChatScreenWidget( child: ChatWidget(
alias: alias, alias: alias,
realm: realm,
), ),
); );
} }
} }
class ChatScreenWidget extends StatefulWidget { class ChatWidget extends StatefulWidget {
final String alias; final String alias;
final String realm;
const ChatScreenWidget({super.key, required this.alias}); const ChatWidget({super.key, required this.alias, required this.realm});
@override @override
State<ChatScreenWidget> createState() => _ChatScreenWidgetState(); State<ChatWidget> createState() => _ChatWidgetState();
} }
class _ChatScreenWidgetState extends State<ChatScreenWidget> { class _ChatWidgetState extends State<ChatWidget> {
bool _isReady = false; bool _isReady = false;
final PagingController<int, Message> _pagingController = PagingController(firstPageKey: 0); final PagingController<int, Message> _pagingController = PagingController(firstPageKey: 0);
@ -77,7 +82,7 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
var uri = getRequestUri( var uri = getRequestUri(
'messaging', 'messaging',
'/api/channels/global/${widget.alias}/messages?take=$take&offset=$offset', '/api/channels/${widget.realm}/${widget.alias}/messages?take=$take&offset=$offset',
); );
var res = await auth.client!.get(uri); var res = await auth.client!.get(uri);
@ -147,8 +152,8 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
super.initState(); super.initState();
Future.delayed(Duration.zero, () { Future.delayed(Duration.zero, () {
_chat.fetchOngoingCall(widget.alias); _chat.fetchOngoingCall(widget.alias, widget.realm);
_chat.fetchChannel(widget.alias); _chat.fetchChannel(widget.alias, widget.realm);
}); });
} }
@ -232,6 +237,7 @@ class _ChatScreenWidgetState extends State<ChatScreenWidget> {
), ),
), ),
ChatMessageEditor( ChatMessageEditor(
realm: widget.realm,
channel: widget.alias, channel: widget.alias,
editing: _editingItem, editing: _editingItem,
replying: _replyingItem, replying: _replyingItem,

View File

@ -9,8 +9,9 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ChatDetailScreen extends StatefulWidget { class ChatDetailScreen extends StatefulWidget {
final Channel channel; final Channel channel;
final String realm;
const ChatDetailScreen({super.key, required this.channel}); const ChatDetailScreen({super.key, required this.channel, this.realm = 'global'});
@override @override
State<ChatDetailScreen> createState() => _ChatDetailScreenState(); State<ChatDetailScreen> createState() => _ChatDetailScreenState();
@ -24,6 +25,7 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
context: context, context: context,
builder: (context) => ChannelDeletion( builder: (context) => ChannelDeletion(
channel: widget.channel, channel: widget.channel,
realm: widget.realm,
isOwned: _isOwned, isOwned: _isOwned,
), ),
); );

View File

@ -23,29 +23,15 @@ class ChatListScreen extends StatelessWidget {
title: AppLocalizations.of(context)!.chat, title: AppLocalizations.of(context)!.chat,
appBarActions: const [NotificationButton()], appBarActions: const [NotificationButton()],
fixedAppBarColor: SolianTheme.isLargeScreen(context), fixedAppBarColor: SolianTheme.isLargeScreen(context),
child: ChatListWidget( child: const ChatListWidget(),
onSelect: (item) {
if (SolianRouter.currentRoute.name == 'chat.channel') {
SolianRouter.router.pushReplacementNamed(
'chat.channel',
pathParameters: {'channel': item.alias},
);
} else {
SolianRouter.router.pushNamed(
'chat.channel',
pathParameters: {'channel': item.alias},
);
}
},
),
); );
} }
} }
class ChatListWidget extends StatefulWidget { class ChatListWidget extends StatefulWidget {
final Function(Channel item)? onSelect; final String? realm;
const ChatListWidget({super.key, this.onSelect}); const ChatListWidget({super.key, this.realm});
@override @override
State<ChatListWidget> createState() => _ChatListWidgetState(); State<ChatListWidget> createState() => _ChatListWidgetState();
@ -58,7 +44,12 @@ class _ChatListWidgetState extends State<ChatListWidget> {
final auth = context.read<AuthProvider>(); final auth = context.read<AuthProvider>();
if (!await auth.isAuthorized()) return; if (!await auth.isAuthorized()) return;
var uri = getRequestUri('messaging', '/api/channels/global/me/available'); Uri uri;
if (widget.realm == null) {
uri = getRequestUri('messaging', '/api/channels/global/me/available');
} else {
uri = getRequestUri('messaging', '/api/channels/${widget.realm}');
}
var res = await auth.client!.get(uri); var res = await auth.client!.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
@ -75,7 +66,10 @@ class _ChatListWidgetState extends State<ChatListWidget> {
void viewNewChatAction() { void viewNewChatAction() {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
builder: (context) => ChatNewAction(onUpdate: () => fetchChannels()), builder: (context) => ChatNewAction(
onUpdate: () => fetchChannels(),
realm: widget.realm,
),
); );
} }
@ -128,17 +122,24 @@ class _ChatListWidgetState extends State<ChatListWidget> {
title: Text(element.name), title: Text(element.name),
subtitle: Text(element.description), subtitle: Text(element.description),
onTap: () async { onTap: () async {
if (widget.onSelect != null) { String? result;
widget.onSelect!(element); if (SolianRouter.currentRoute.name == 'chat.channel') {
return; result = await SolianRouter.router.pushReplacementNamed(
} widget.realm == null ? 'chat.channel' : 'realms.chat.channel',
final result = await SolianRouter.router.pushNamed(
'chat.channel',
pathParameters: { pathParameters: {
'channel': element.alias, 'channel': element.alias,
...(widget.realm == null ? {} : {'realm': widget.realm!}),
}, },
); );
} else {
result = await SolianRouter.router.pushNamed(
widget.realm == null ? 'chat.channel' : 'realms.chat.channel',
pathParameters: {
'channel': element.alias,
...(widget.realm == null ? {} : {'realm': widget.realm!}),
},
);
}
switch (result) { switch (result) {
case 'refresh': case 'refresh':
fetchChannels(); fetchChannels();

View File

@ -25,25 +25,15 @@ class ExplorePostScreen extends StatelessWidget {
fixedAppBarColor: SolianTheme.isLargeScreen(context), fixedAppBarColor: SolianTheme.isLargeScreen(context),
appBarActions: const [NotificationButton()], appBarActions: const [NotificationButton()],
title: AppLocalizations.of(context)!.explore, title: AppLocalizations.of(context)!.explore,
child: ExplorePostWidget( child: const ExplorePostWidget(),
onSelect: (item) {
SolianRouter.router.pushNamed(
'posts.screen',
pathParameters: {
'alias': item.alias,
'dataset': item.dataset,
},
);
},
),
); );
} }
} }
class ExplorePostWidget extends StatefulWidget { class ExplorePostWidget extends StatefulWidget {
final Function(Post item) onSelect; final String? realm;
const ExplorePostWidget({super.key, required this.onSelect}); const ExplorePostWidget({super.key, this.realm});
@override @override
State<ExplorePostWidget> createState() => _ExplorePostWidgetState(); State<ExplorePostWidget> createState() => _ExplorePostWidgetState();
@ -58,7 +48,12 @@ class _ExplorePostWidgetState extends State<ExplorePostWidget> {
final offset = pageKey; final offset = pageKey;
const take = 5; const take = 5;
var uri = getRequestUri('interactive', '/api/feed?take=$take&offset=$offset'); Uri uri;
if (widget.realm == null) {
uri = getRequestUri('interactive', '/api/feed?take=$take&offset=$offset');
} else {
uri = getRequestUri('interactive', '/api/feed?realm=${widget.realm}&take=$take&offset=$offset');
}
var res = await _client.get(uri); var res = await _client.get(uri);
if (res.statusCode == 200) { if (res.statusCode == 200) {
@ -95,7 +90,10 @@ class _ExplorePostWidgetState extends State<ExplorePostWidget> {
return FloatingActionButton( return FloatingActionButton(
child: const Icon(Icons.edit), child: const Icon(Icons.edit),
onPressed: () async { onPressed: () async {
final did = await SolianRouter.router.pushNamed('posts.moments.editor'); final did = await SolianRouter.router.pushNamed(
'posts.moments.editor',
queryParameters: {'realm': widget.realm},
);
if (did == true) _pagingController.refresh(); if (did == true) _pagingController.refresh();
}, },
); );
@ -114,7 +112,16 @@ class _ExplorePostWidgetState extends State<ExplorePostWidget> {
itemBuilder: (context, item, index) => PostItem( itemBuilder: (context, item, index) => PostItem(
item: item, item: item,
onUpdate: () => _pagingController.refresh(), onUpdate: () => _pagingController.refresh(),
onTap: () => widget.onSelect(item), onTap: () {
SolianRouter.router.pushNamed(
widget.realm == null ? 'posts.details' : 'realms.posts.details',
pathParameters: {
'alias': item.alias,
'dataset': item.dataset,
...(widget.realm == null ? {} : {'realm': widget.realm!}),
},
);
},
), ),
), ),
), ),

View File

@ -37,12 +37,16 @@ class _NotificationScreenState extends State<NotificationScreen> {
markList.add(element.id); markList.add(element.id);
} }
nty.clearRealtime();
if(markList.isNotEmpty) {
var uri = getRequestUri('passport', '/api/notifications/batch/read'); var uri = getRequestUri('passport', '/api/notifications/batch/read');
await auth.client!.put( await auth.client!.put(
uri, uri,
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: jsonEncode({'messages': markList}), body: jsonEncode({'messages': markList}),
); );
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.notifyMarkAllReadDone), content: Text(AppLocalizations.of(context)!.notifyMarkAllReadDone),
@ -195,19 +199,7 @@ class NotificationItem extends StatelessWidget {
onDismissed: (direction) { onDismissed: (direction) {
markAsRead(item, context).then((value) { markAsRead(item, context).then((value) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(content: Text('${item.subject} is marked as read')),
content: RichText(
text: TextSpan(
children: [
TextSpan(
text: item.subject,
style: const TextStyle(fontWeight: FontWeight.bold),
),
const TextSpan(text: ' is marked as read')
],
),
),
),
); );
}); });
if (onDismiss != null) { if (onDismiss != null) {

View File

@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/realm.dart';
import 'package:solian/screens/chat/chat_list.dart';
import 'package:solian/screens/explore.dart';
import 'package:solian/utils/theme.dart';
import 'package:solian/widgets/scaffold.dart';
class RealmScreen extends StatelessWidget {
final String alias;
const RealmScreen({super.key, required this.alias});
@override
Widget build(BuildContext context) {
final realm = context.watch<RealmProvider>();
return IndentScaffold(
title: realm.focusRealm?.name ?? 'Loading...',
hideDrawer: !SolianTheme.isLargeScreen(context),
noSafeArea: true,
fixedAppBarColor: SolianTheme.isLargeScreen(context),
child: RealmWidget(
alias: alias,
),
);
}
}
class RealmWidget extends StatefulWidget {
final String alias;
const RealmWidget({super.key, required this.alias});
@override
State<RealmWidget> createState() => _RealmWidgetState();
}
class _RealmWidgetState extends State<RealmWidget> {
bool _isReady = false;
late RealmProvider _realm;
@override
void initState() {
super.initState();
Future.delayed(Duration.zero, () {
final auth = context.read<AuthProvider>();
if (_realm.focusRealm?.alias != widget.alias) {
_realm.fetchSingle(auth, widget.alias);
}
});
}
@override
Widget build(BuildContext context) {
if (!_isReady) {
_realm = context.watch<RealmProvider>();
_isReady = true;
}
return DefaultTabController(
length: 2,
child: Column(
children: [
TabBar(
isScrollable: !SolianTheme.isLargeScreen(context),
tabs: const [
Tab(icon: Icon(Icons.newspaper)),
Tab(icon: Icon(Icons.message)),
],
),
Expanded(
child: TabBarView(
children: [
ExplorePostWidget(realm: widget.alias),
ChatListWidget(realm: widget.alias),
],
),
)
],
),
);
}
}

View File

@ -0,0 +1,208 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:http/http.dart';
import 'package:provider/provider.dart';
import 'package:solian/models/realm.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
import 'package:solian/utils/service_url.dart';
import 'package:solian/widgets/exts.dart';
import 'package:solian/widgets/scaffold.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class RealmEditorScreen extends StatefulWidget {
final Realm? editing;
final String? realm;
const RealmEditorScreen({super.key, this.editing, this.realm});
@override
State<RealmEditorScreen> createState() => _RealmEditorScreenState();
}
class _RealmEditorScreenState extends State<RealmEditorScreen> {
final _aliasController = TextEditingController();
final _nameController = TextEditingController();
final _descriptionController = TextEditingController();
bool _isPublic = false;
bool _isCommunity = false;
bool _isSubmitting = false;
Future<void> applyChannel(BuildContext context) async {
setState(() => _isSubmitting = true);
final auth = context.read<AuthProvider>();
if (!await auth.isAuthorized()) {
setState(() => _isSubmitting = false);
return;
}
final uri = widget.editing == null
? getRequestUri('passport', '/api/realms')
: getRequestUri('passport', '/api/realms/${widget.editing!.id}');
final req = Request(widget.editing == null ? 'POST' : 'PUT', uri);
req.headers['Content-Type'] = 'application/json';
req.body = jsonEncode(<String, dynamic>{
'alias': _aliasController.value.text.toLowerCase(),
'name': _nameController.value.text,
'description': _descriptionController.value.text,
'is_public': _isPublic,
'is_community': _isCommunity,
'realm': widget.realm,
});
var res = await Response.fromStream(await auth.client!.send(req));
if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes);
context.showErrorDialog(message);
} else {
if (SolianRouter.router.canPop()) {
SolianRouter.router.pop(true);
}
}
setState(() => _isSubmitting = false);
}
void randomizeAlias() {
_aliasController.text = const Uuid().v4().replaceAll('-', '').substring(0, 16);
}
void cancelEditing() {
if (SolianRouter.router.canPop()) {
SolianRouter.router.pop(false);
}
}
@override
void initState() {
if (widget.editing != null) {
_aliasController.text = widget.editing!.alias;
_nameController.text = widget.editing!.name;
_descriptionController.text = widget.editing!.description;
_isPublic = widget.editing!.isPublic;
_isCommunity = widget.editing!.isCommunity;
}
super.initState();
}
@override
Widget build(BuildContext context) {
final editingBanner = MaterialBanner(
padding: const EdgeInsets.only(top: 4, bottom: 4, left: 20),
leading: const Icon(Icons.edit_note),
backgroundColor: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.9),
dividerColor: const Color.fromARGB(1, 0, 0, 0),
content: Text(AppLocalizations.of(context)!.realmEditNotify),
actions: [
TextButton(
child: Text(AppLocalizations.of(context)!.cancel),
onPressed: () => cancelEditing(),
),
],
);
return IndentScaffold(
hideDrawer: true,
title: AppLocalizations.of(context)!.realmEstablish,
appBarActions: <Widget>[
TextButton(
onPressed: !_isSubmitting ? () => applyChannel(context) : null,
child: Text(AppLocalizations.of(context)!.apply.toUpperCase()),
),
],
child: Column(
children: [
_isSubmitting ? const LinearProgressIndicator().animate().scaleX() : Container(),
widget.editing != null ? editingBanner : Container(),
ListTile(
title: Text(AppLocalizations.of(context)!.realmUsage),
subtitle: Text(AppLocalizations.of(context)!.realmUsageCaption),
leading: const CircleAvatar(
backgroundColor: Colors.teal,
child: Icon(Icons.supervised_user_circle, color: Colors.white),
),
),
const Divider(thickness: 0.3),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
child: Row(
children: [
Expanded(
child: TextField(
autofocus: true,
controller: _aliasController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!.realmAliasLabel,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
),
),
TextButton(
style: TextButton.styleFrom(
shape: const CircleBorder(),
visualDensity: const VisualDensity(horizontal: -2, vertical: -2),
),
onPressed: () => randomizeAlias(),
child: const Icon(Icons.refresh),
)
],
),
),
const Divider(thickness: 0.3),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: TextField(
autocorrect: true,
controller: _nameController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!.realmNameLabel,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
),
),
const Divider(thickness: 0.3),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: TextField(
minLines: 5,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.multiline,
controller: _descriptionController,
decoration: InputDecoration.collapsed(
hintText: AppLocalizations.of(context)!.realmDescriptionLabel,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
),
),
),
const Divider(thickness: 0.3),
CheckboxListTile(
title: Text(AppLocalizations.of(context)!.realmPublicLabel),
value: _isPublic,
onChanged: (newValue) {
setState(() => _isPublic = newValue ?? false);
},
controlAffinity: ListTileControlAffinity.leading,
),
CheckboxListTile(
title: Text(AppLocalizations.of(context)!.realmCommunityLabel),
value: _isCommunity,
onChanged: (newValue) {
setState(() => _isCommunity = newValue ?? false);
},
controlAffinity: ListTileControlAffinity.leading,
)
],
),
);
}
}

View File

@ -0,0 +1,132 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/realm.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/realms/realm.dart';
import 'package:solian/utils/theme.dart';
import 'package:solian/widgets/notification_notifier.dart';
import 'package:solian/widgets/realms/realm_new.dart';
import 'package:solian/widgets/scaffold.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:solian/widgets/signin_required.dart';
class RealmListScreen extends StatelessWidget {
const RealmListScreen({super.key});
@override
Widget build(BuildContext context) {
final realm = context.watch<RealmProvider>();
return realm.focusRealm == null
? IndentScaffold(
title: AppLocalizations.of(context)!.realm,
appBarActions: const [NotificationButton()],
fixedAppBarColor: SolianTheme.isLargeScreen(context),
child: const RealmListWidget(),
)
: RealmScreen(alias: realm.focusRealm!.alias);
}
}
class RealmListWidget extends StatefulWidget {
const RealmListWidget({super.key});
@override
State<RealmListWidget> createState() => _RealmListWidgetState();
}
class _RealmListWidgetState extends State<RealmListWidget> {
void viewNewRealmAction() {
final auth = context.read<AuthProvider>();
final realms = context.read<RealmProvider>();
showModalBottomSheet(
context: context,
builder: (context) => RealmNewAction(onUpdate: () => realms.fetch(auth)),
);
}
@override
void initState() {
Future.delayed(Duration.zero, () {
final auth = context.read<AuthProvider>();
final realms = context.read<RealmProvider>();
realms.fetch(auth);
});
super.initState();
}
@override
Widget build(BuildContext context) {
final auth = context.read<AuthProvider>();
final realms = context.watch<RealmProvider>();
return Scaffold(
floatingActionButton: FutureBuilder(
future: auth.isAuthorized(),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data!) {
return FloatingActionButton.extended(
icon: const Icon(Icons.add),
label: Text(AppLocalizations.of(context)!.realmNew),
onPressed: () => viewNewRealmAction(),
);
} else {
return Container();
}
},
),
body: FutureBuilder(
future: auth.isAuthorized(),
builder: (context, snapshot) {
if (!snapshot.hasData || !snapshot.data!) {
return const SignInRequiredScreen();
}
return RefreshIndicator(
onRefresh: () => realms.fetch(auth),
child: ListView.builder(
itemCount: realms.realms.length,
itemBuilder: (context, index) {
final element = realms.realms[index];
return ListTile(
leading: const CircleAvatar(
backgroundColor: Colors.indigo,
child: Icon(Icons.supervisor_account, color: Colors.white),
),
title: Text(element.name),
subtitle: Text(element.description),
onTap: () async {
realms.fetchSingle(auth, element.alias);
String? result;
if (SolianRouter.currentRoute.name == 'chat.channel') {
result = await SolianRouter.router.pushReplacementNamed(
'realms.details',
pathParameters: {
'realm': element.alias,
},
);
} else {
result = await SolianRouter.router.pushNamed(
'realms.details',
pathParameters: {
'realm': element.alias,
},
);
}
switch (result) {
case 'refresh':
realms.fetch(auth);
}
},
);
},
),
);
},
),
);
}
}

View File

@ -13,9 +13,16 @@ import 'package:solian/widgets/exts.dart';
class ChannelCallAction extends StatefulWidget { class ChannelCallAction extends StatefulWidget {
final Call? call; final Call? call;
final Channel channel; final Channel channel;
final String realm;
final Function onUpdate; final Function onUpdate;
const ChannelCallAction({super.key, this.call, required this.channel, required this.onUpdate}); const ChannelCallAction({
super.key,
this.call,
required this.channel,
required this.onUpdate,
this.realm = 'global',
});
@override @override
State<ChannelCallAction> createState() => _ChannelCallActionState(); State<ChannelCallAction> createState() => _ChannelCallActionState();
@ -33,7 +40,7 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
return; return;
} }
var uri = getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}/calls'); var uri = getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel.alias}/calls');
var res = await auth.client!.post(uri); var res = await auth.client!.post(uri);
if (res.statusCode != 200) { if (res.statusCode != 200) {
@ -54,7 +61,7 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
return; return;
} }
var uri = getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}/calls/ongoing'); var uri = getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel.alias}/calls/ongoing');
var res = await auth.client!.delete(uri); var res = await auth.client!.delete(uri);
if (res.statusCode != 200) { if (res.statusCode != 200) {
@ -90,17 +97,26 @@ class _ChannelCallActionState extends State<ChannelCallAction> {
class ChannelManageAction extends StatelessWidget { class ChannelManageAction extends StatelessWidget {
final Channel channel; final Channel channel;
final Function onUpdate; final Function onUpdate;
final String realm;
const ChannelManageAction({super.key, required this.channel, required this.onUpdate}); const ChannelManageAction({
super.key,
required this.channel,
required this.onUpdate,
this.realm = 'global',
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return IconButton( return IconButton(
onPressed: () async { onPressed: () async {
final result = await SolianRouter.router.pushNamed( final result = await SolianRouter.router.pushNamed(
'chat.channel.manage', realm == 'global' ? 'chat.channel.manage' : 'realms.chat.channel.manage',
extra: channel, extra: channel,
pathParameters: {'channel': channel.alias}, pathParameters: {
'channel': channel.alias,
...(realm == 'global' ? {} : {'realm': realm}),
},
); );
switch (result) { switch (result) {
case 'disposed': case 'disposed':

View File

@ -10,10 +10,15 @@ import 'package:solian/widgets/exts.dart';
class ChannelDeletion extends StatefulWidget { class ChannelDeletion extends StatefulWidget {
final Channel channel; final Channel channel;
final String realm;
final bool isOwned; final bool isOwned;
const ChannelDeletion( const ChannelDeletion({
{super.key, required this.channel, required this.isOwned}); super.key,
required this.channel,
required this.realm,
required this.isOwned,
});
@override @override
State<ChannelDeletion> createState() => _ChannelDeletionState(); State<ChannelDeletion> createState() => _ChannelDeletionState();
@ -32,7 +37,7 @@ class _ChannelDeletionState extends State<ChannelDeletion> {
} }
var res = await auth.client!.delete( var res = await auth.client!.delete(
getRequestUri('messaging', '/api/channels/global/${widget.channel.id}'), getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel.id}'),
); );
if (res.statusCode != 200) { if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes); var message = utf8.decode(res.bodyBytes);
@ -53,8 +58,8 @@ class _ChannelDeletionState extends State<ChannelDeletion> {
return; return;
} }
var res = await auth.client!.post( var res = await auth.client!.delete(
getRequestUri('messaging', '/api/channels/global/${widget.channel.alias}/leave'), getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel.alias}/me'),
); );
if (res.statusCode != 200) { if (res.statusCode != 200) {
var message = utf8.decode(res.bodyBytes); var message = utf8.decode(res.bodyBytes);

View File

@ -4,8 +4,9 @@ import 'package:solian/router.dart';
class ChatNewAction extends StatelessWidget { class ChatNewAction extends StatelessWidget {
final Function onUpdate; final Function onUpdate;
final String? realm;
const ChatNewAction({super.key, required this.onUpdate}); const ChatNewAction({super.key, required this.onUpdate, this.realm});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -29,7 +30,10 @@ class ChatNewAction extends StatelessWidget {
leading: const Icon(Icons.add), leading: const Icon(Icons.add),
title: Text(AppLocalizations.of(context)!.chatNewCreate), title: Text(AppLocalizations.of(context)!.chatNewCreate),
onTap: () { onTap: () {
SolianRouter.router.pushNamed('chat.channel.editor').then((did) { SolianRouter.router.pushNamed(
'chat.channel.editor',
queryParameters: {'realm': realm},
).then((did) {
if (did == true) { if (did == true) {
onUpdate(); onUpdate();
if (Navigator.canPop(context)) { if (Navigator.canPop(context)) {

View File

@ -14,11 +14,19 @@ import 'package:badges/badges.dart' as badge;
class ChatMessageEditor extends StatefulWidget { class ChatMessageEditor extends StatefulWidget {
final String channel; final String channel;
final String realm;
final Message? editing; final Message? editing;
final Message? replying; final Message? replying;
final Function? onReset; final Function? onReset;
const ChatMessageEditor({super.key, required this.channel, this.editing, this.replying, this.onReset}); const ChatMessageEditor({
super.key,
required this.channel,
this.realm = 'global',
this.editing,
this.replying,
this.onReset,
});
@override @override
State<ChatMessageEditor> createState() => _ChatMessageEditorState(); State<ChatMessageEditor> createState() => _ChatMessageEditorState();
@ -53,8 +61,8 @@ class _ChatMessageEditorState extends State<ChatMessageEditor> {
if (!await auth.isAuthorized()) return; if (!await auth.isAuthorized()) return;
final uri = widget.editing == null final uri = widget.editing == null
? getRequestUri('messaging', '/api/channels/global/${widget.channel}/messages') ? getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel}/messages')
: getRequestUri('messaging', '/api/channels/global/${widget.channel}/messages/${widget.editing!.id}'); : getRequestUri('messaging', '/api/channels/${widget.realm}/${widget.channel}/messages/${widget.editing!.id}');
final req = Request(widget.editing == null ? 'POST' : 'PUT', uri); final req = Request(widget.editing == null ? 'POST' : 'PUT', uri);
req.headers['Content-Type'] = 'application/json'; req.headers['Content-Type'] = 'application/json';

View File

@ -42,6 +42,13 @@ class _SolianNavigationDrawerState extends State<SolianNavigationDrawer> {
), ),
'explore', 'explore',
), ),
(
NavigationDrawerDestination(
icon: const Icon(Icons.supervised_user_circle),
label: Text(AppLocalizations.of(context)!.realm),
),
'realms',
),
( (
NavigationDrawerDestination( NavigationDrawerDestination(
icon: const Icon(Icons.send), icon: const Icon(Icons.send),

View File

@ -1,4 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:solian/utils/platform.dart';
class AttachmentScreen extends StatelessWidget { class AttachmentScreen extends StatelessWidget {
final String url; final String url;
@ -17,7 +19,7 @@ class AttachmentScreen extends StatelessWidget {
maxScale: 16, maxScale: 16,
panEnabled: true, panEnabled: true,
scaleEnabled: true, scaleEnabled: true,
child: Image.network(url, fit: BoxFit.contain), child: PlatformInfo.canCacheImage ? CachedNetworkImage(imageUrl: url, fit: BoxFit.contain) : Image.network(url),
), ),
); );

View File

@ -1,9 +1,10 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:markdown/markdown.dart' as markdown; import 'package:markdown/markdown.dart' as markdown;
import 'package:solian/utils/platform.dart';
import 'package:solian/utils/service_url.dart'; import 'package:solian/utils/service_url.dart';
import 'package:solian/widgets/posts/content/attachment.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
class ArticleContent extends StatelessWidget { class ArticleContent extends StatelessWidget {
@ -61,10 +62,9 @@ class ArticleContent extends StatelessWidget {
uri = url; uri = url;
} }
return AttachmentItem( return PlatformInfo.canCacheImage
type: 1, ? CachedNetworkImage(imageUrl: uri.toString())
url: uri.toString(), : Image.network(uri.toString());
);
}, },
), ),
], ],

View File

@ -1,6 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';

View File

@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:solian/router.dart';
class RealmNewAction extends StatelessWidget {
final Function onUpdate;
const RealmNewAction({super.key, required this.onUpdate});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 320,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(left: 20, top: 20, bottom: 8),
child: Text(
AppLocalizations.of(context)!.realmNew,
style: Theme.of(context).textTheme.headlineSmall,
),
),
Expanded(
child: ListView(
children: [
ListTile(
leading: const Icon(Icons.add),
title: Text(AppLocalizations.of(context)!.realmNewCreate),
onTap: () {
SolianRouter.router.pushNamed('realms.editor').then((did) {
if (did == true) {
onUpdate();
if (Navigator.canPop(context)) {
Navigator.pop(context);
}
}
});
},
),
ListTile(
leading: const Icon(Icons.travel_explore),
title: Text(AppLocalizations.of(context)!.realmNewJoin),
),
],
),
),
],
),
);
}
}