mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-12 10:42:35 +01:00
chore: Improve stories
This commit is contained in:
parent
8789863906
commit
105884dbe1
@ -89,6 +89,7 @@ class AddStoryView extends StatelessWidget {
|
|||||||
controller: controller.controller,
|
controller: controller.controller,
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
maxLines: 20,
|
maxLines: 20,
|
||||||
|
autofocus: true,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
|
@ -26,6 +26,7 @@ class StoriesHeader extends StatelessWidget {
|
|||||||
|
|
||||||
void _contextualActions(BuildContext context, Room room) async {
|
void _contextualActions(BuildContext context, Room room) async {
|
||||||
final action = await showModalActionSheet<ContextualRoomAction>(
|
final action = await showModalActionSheet<ContextualRoomAction>(
|
||||||
|
cancelLabel: L10n.of(context)!.cancel,
|
||||||
context: context,
|
context: context,
|
||||||
actions: [
|
actions: [
|
||||||
if (room.pushRuleState != PushRuleState.notify)
|
if (room.pushRuleState != PushRuleState.notify)
|
||||||
@ -105,19 +106,24 @@ class StoriesHeader extends StatelessWidget {
|
|||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
...client.storiesRooms.map(
|
...client.storiesRooms.map(
|
||||||
(room) => _StoryButton(
|
(room) => Opacity(
|
||||||
label: room.creatorDisplayname,
|
opacity: room.hasPosts ? 1 : 0.5,
|
||||||
child: Avatar(
|
child: _StoryButton(
|
||||||
mxContent: room
|
label: room.creatorDisplayname,
|
||||||
.getState(EventTypes.RoomCreate)!
|
child: Avatar(
|
||||||
.sender
|
mxContent: room
|
||||||
.avatarUrl,
|
.getState(EventTypes.RoomCreate)!
|
||||||
name: room.creatorDisplayname,
|
.sender
|
||||||
|
.avatarUrl,
|
||||||
|
name: room.creatorDisplayname,
|
||||||
|
),
|
||||||
|
unread: room.notificationCount > 0 ||
|
||||||
|
room.membership == Membership.invite,
|
||||||
|
onPressed: () => room.hasPosts
|
||||||
|
? _goToStoryAction(context, room.id)
|
||||||
|
: _contextualActions(context, room),
|
||||||
|
onLongPressed: () => _contextualActions(context, room),
|
||||||
),
|
),
|
||||||
unread: room.notificationCount > 0 ||
|
|
||||||
room.membership == Membership.invite,
|
|
||||||
onPressed: () => _goToStoryAction(context, room.id),
|
|
||||||
onLongPressed: () => _contextualActions(context, room),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -130,6 +136,17 @@ class StoriesHeader extends StatelessWidget {
|
|||||||
extension on Room {
|
extension on Room {
|
||||||
String get creatorDisplayname =>
|
String get creatorDisplayname =>
|
||||||
getState(EventTypes.RoomCreate)!.sender.calcDisplayname();
|
getState(EventTypes.RoomCreate)!.sender.calcDisplayname();
|
||||||
|
|
||||||
|
bool get hasPosts {
|
||||||
|
final lastEvent = this.lastEvent;
|
||||||
|
if (lastEvent == null) return false;
|
||||||
|
if (lastEvent.type != EventTypes.Message) return false;
|
||||||
|
if (DateTime.now().difference(lastEvent.originServerTs).inHours >
|
||||||
|
ClientStoriesExtension.lifeTimeInHours) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _StoryButton extends StatelessWidget {
|
class _StoryButton extends StatelessWidget {
|
||||||
|
@ -29,6 +29,12 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
Timer? _progressTimer;
|
Timer? _progressTimer;
|
||||||
bool loadingMode = false;
|
bool loadingMode = false;
|
||||||
|
|
||||||
|
final List<Event> events = [];
|
||||||
|
|
||||||
|
Event? get currentEvent => index < events.length ? events[index] : null;
|
||||||
|
|
||||||
|
final TextEditingController replyController = TextEditingController();
|
||||||
|
|
||||||
static const Duration _step = Duration(milliseconds: 50);
|
static const Duration _step = Duration(milliseconds: 50);
|
||||||
static const Duration maxProgress = Duration(seconds: 5);
|
static const Duration maxProgress = Duration(seconds: 5);
|
||||||
|
|
||||||
@ -127,11 +133,11 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
.calcDisplayname() ??
|
.calcDisplayname() ??
|
||||||
'Story not found';
|
'Story not found';
|
||||||
|
|
||||||
Future<List<Event>>? loadStory;
|
Future<void>? loadStory;
|
||||||
|
|
||||||
Future<List<Event>> _loadStory() async {
|
Future<void> _loadStory() async {
|
||||||
final room = Matrix.of(context).client.getRoomById(roomId);
|
final room = Matrix.of(context).client.getRoomById(roomId);
|
||||||
if (room == null) return [];
|
if (room == null) return;
|
||||||
if (room.membership != Membership.join) {
|
if (room.membership != Membership.join) {
|
||||||
final joinedFuture = room.client.onSync.stream
|
final joinedFuture = room.client.onSync.stream
|
||||||
.where((u) => u.rooms?.join?.containsKey(room.id) ?? false)
|
.where((u) => u.rooms?.join?.containsKey(room.id) ?? false)
|
||||||
@ -140,6 +146,7 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
await joinedFuture;
|
await joinedFuture;
|
||||||
}
|
}
|
||||||
final timeline = await room.getTimeline();
|
final timeline = await room.getTimeline();
|
||||||
|
timeline.requestKeys();
|
||||||
var events =
|
var events =
|
||||||
timeline.events.where((e) => e.type == EventTypes.Message).toList();
|
timeline.events.where((e) => e.type == EventTypes.Message).toList();
|
||||||
|
|
||||||
@ -171,7 +178,24 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
.forEach((event) => downloadAndDecryptAttachment(event,
|
.forEach((event) => downloadAndDecryptAttachment(event,
|
||||||
event.messageType == MessageTypes.Video && PlatformInfos.isMobile));
|
event.messageType == MessageTypes.Video && PlatformInfos.isMobile));
|
||||||
|
|
||||||
return events.reversed.toList();
|
if (!events.last.receipts
|
||||||
|
.any((receipt) => receipt.user.id == room.client.userID)) {
|
||||||
|
for (var j = 0; j < events.length; j++) {
|
||||||
|
if (events[j]
|
||||||
|
.receipts
|
||||||
|
.any((receipt) => receipt.user.id == room.client.userID)) {
|
||||||
|
index = j;
|
||||||
|
room.setReadMarker(
|
||||||
|
events[index].eventId,
|
||||||
|
mRead: events[index].eventId,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.events.clear();
|
||||||
|
this.events.addAll(events.reversed.toList());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -9,6 +9,7 @@ import 'package:matrix/matrix.dart';
|
|||||||
import 'package:video_player/video_player.dart';
|
import 'package:video_player/video_player.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/pages/story/story_page.dart';
|
import 'package:fluffychat/pages/story/story_page.dart';
|
||||||
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/utils/string_color.dart';
|
import 'package:fluffychat/utils/string_color.dart';
|
||||||
@ -20,6 +21,7 @@ class StoryView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final currentEvent = controller.currentEvent;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
titleSpacing: 0,
|
titleSpacing: 0,
|
||||||
@ -29,7 +31,6 @@ class StoryView extends StatelessWidget {
|
|||||||
controller.title,
|
controller.title,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 20,
|
|
||||||
shadows: [
|
shadows: [
|
||||||
Shadow(
|
Shadow(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
@ -39,6 +40,21 @@ class StoryView extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
subtitle: currentEvent != null
|
||||||
|
? Text(
|
||||||
|
currentEvent.originServerTs.localizedTime(context),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
shadows: [
|
||||||
|
Shadow(
|
||||||
|
color: Colors.black,
|
||||||
|
offset: Offset(0, 0),
|
||||||
|
blurRadius: 5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
leading: Avatar(
|
leading: Avatar(
|
||||||
mxContent: controller.avatar,
|
mxContent: controller.avatar,
|
||||||
name: controller.title,
|
name: controller.title,
|
||||||
@ -50,15 +66,15 @@ class StoryView extends StatelessWidget {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
body: FutureBuilder<List<Event>>(
|
body: FutureBuilder(
|
||||||
future: controller.loadStory,
|
future: controller.loadStory,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final error = snapshot.error;
|
final error = snapshot.error;
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return Center(child: Text(error.toLocalizedString(context)));
|
return Center(child: Text(error.toLocalizedString(context)));
|
||||||
}
|
}
|
||||||
final events = snapshot.data;
|
final events = controller.events;
|
||||||
if (events == null) {
|
if (snapshot.connectionState != ConnectionState.done) {
|
||||||
return const Center(
|
return const Center(
|
||||||
child: CircularProgressIndicator.adaptive(
|
child: CircularProgressIndicator.adaptive(
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
|
Loading…
Reference in New Issue
Block a user