mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 15:02:33 +01:00
Merge branch 'krille/betterstories' into 'main'
followup: Improve stories See merge request famedly/fluffychat!636
This commit is contained in:
commit
65698f1731
@ -97,7 +97,7 @@ class AddStoryController extends State<AddStoryPage> {
|
|||||||
|
|
||||||
void postStory() async {
|
void postStory() async {
|
||||||
final client = Matrix.of(context).client;
|
final client = Matrix.of(context).client;
|
||||||
final storiesRoom = await client.getStoriesRoom(context);
|
var storiesRoom = await client.getStoriesRoom(context);
|
||||||
|
|
||||||
// Invite contacts if necessary
|
// Invite contacts if necessary
|
||||||
final undecided = await showFutureLoadingDialog(
|
final undecided = await showFutureLoadingDialog(
|
||||||
@ -113,6 +113,7 @@ class AddStoryController extends State<AddStoryPage> {
|
|||||||
builder: (context) => InviteStoryPage(storiesRoom: storiesRoom),
|
builder: (context) => InviteStoryPage(storiesRoom: storiesRoom),
|
||||||
);
|
);
|
||||||
if (created != true) return;
|
if (created != true) return;
|
||||||
|
storiesRoom ??= await client.getStoriesRoom(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post story
|
// Post story
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//@dart=2.12
|
//@dart=2.12
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:video_player/video_player.dart';
|
import 'package:video_player/video_player.dart';
|
||||||
@ -17,9 +18,23 @@ class AddStoryView extends StatelessWidget {
|
|||||||
final video = controller.videoPlayerController;
|
final video = controller.videoPlayerController;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor:
|
systemOverlayStyle: SystemUiOverlayStyle.light,
|
||||||
Theme.of(context).appBarTheme.backgroundColor?.withOpacity(0.5),
|
backgroundColor: Colors.transparent,
|
||||||
title: Text(L10n.of(context)!.addToStory),
|
elevation: 0,
|
||||||
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
|
title: Text(
|
||||||
|
L10n.of(context)!.addToStory,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
shadows: [
|
||||||
|
Shadow(
|
||||||
|
color: Colors.black,
|
||||||
|
offset: Offset(0, 0),
|
||||||
|
blurRadius: 5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
actions: controller.hasMedia
|
actions: controller.hasMedia
|
||||||
? null
|
? null
|
||||||
: [
|
: [
|
||||||
@ -62,12 +77,11 @@ class AddStoryView extends StatelessWidget {
|
|||||||
? null
|
? null
|
||||||
: LinearGradient(
|
: LinearGradient(
|
||||||
colors: [
|
colors: [
|
||||||
controller.backgroundColor,
|
|
||||||
controller.backgroundColorDark,
|
controller.backgroundColorDark,
|
||||||
controller.backgroundColor,
|
controller.backgroundColor,
|
||||||
],
|
],
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topCenter,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomCenter,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
|
@ -14,6 +14,7 @@ import 'package:vrouter/vrouter.dart';
|
|||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
|
import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
|
||||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||||
|
import 'package:fluffychat/utils/matrix_sdk_extensions.dart/client_stories_extension.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import '../../../utils/account_bundles.dart';
|
import '../../../utils/account_bundles.dart';
|
||||||
import '../../main.dart';
|
import '../../main.dart';
|
||||||
@ -205,6 +206,10 @@ class ChatListController extends State<ChatList> {
|
|||||||
if (room.isSpace && room.membership == Membership.join && !room.isUnread) {
|
if (room.isSpace && room.membership == Membership.join && !room.isUnread) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (room.getState(EventTypes.RoomCreate)?.content?.tryGet<String>('type') ==
|
||||||
|
ClientStoriesExtension.storiesRoomType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (activeSpaceId != null) {
|
if (activeSpaceId != null) {
|
||||||
final space = Matrix.of(context).client.getRoomById(activeSpaceId);
|
final space = Matrix.of(context).client.getRoomById(activeSpaceId);
|
||||||
if (space.spaceChildren?.any((child) => child.roomId == room.id) ??
|
if (space.spaceChildren?.any((child) => child.roomId == room.id) ??
|
||||||
|
@ -204,7 +204,6 @@ class ChatListView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (controller.waitForFirstSync) const StoriesHeader(),
|
|
||||||
Expanded(child: _ChatListViewBody(controller)),
|
Expanded(child: _ChatListViewBody(controller)),
|
||||||
]),
|
]),
|
||||||
floatingActionButton: selectMode == SelectMode.normal
|
floatingActionButton: selectMode == SelectMode.normal
|
||||||
@ -307,8 +306,12 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> {
|
|||||||
key: ValueKey(Matrix.of(context).client.userID.toString() +
|
key: ValueKey(Matrix.of(context).client.userID.toString() +
|
||||||
widget.controller.activeSpaceId.toString()),
|
widget.controller.activeSpaceId.toString()),
|
||||||
controller: widget.controller.scrollController,
|
controller: widget.controller.scrollController,
|
||||||
itemCount: rooms.length,
|
itemCount: rooms.length + 1,
|
||||||
itemBuilder: (BuildContext context, int i) {
|
itemBuilder: (BuildContext context, int i) {
|
||||||
|
if (i == 0) {
|
||||||
|
return const StoriesHeader();
|
||||||
|
}
|
||||||
|
i--;
|
||||||
return ChatListItem(
|
return ChatListItem(
|
||||||
rooms[i],
|
rooms[i],
|
||||||
selected: widget.controller.selectedRoomIds.contains(rooms[i].id),
|
selected: widget.controller.selectedRoomIds.contains(rooms[i].id),
|
||||||
|
@ -114,7 +114,8 @@ class StoriesHeader extends StatelessWidget {
|
|||||||
.avatarUrl,
|
.avatarUrl,
|
||||||
name: room.creatorDisplayname,
|
name: room.creatorDisplayname,
|
||||||
),
|
),
|
||||||
unread: room.notificationCount > 0,
|
unread: room.notificationCount > 0 ||
|
||||||
|
room.membership == Membership.invite,
|
||||||
onPressed: () => _goToStoryAction(context, room.id),
|
onPressed: () => _goToStoryAction(context, room.id),
|
||||||
onLongPressed: () => _contextualActions(context, room),
|
onLongPressed: () => _contextualActions(context, room),
|
||||||
),
|
),
|
||||||
|
@ -65,7 +65,7 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
|
|
||||||
void skip() {
|
void skip() {
|
||||||
if (index + 1 >= max) {
|
if (index + 1 >= max) {
|
||||||
VRouter.of(context).pop();
|
VRouter.of(context).to('/rooms');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -111,6 +111,13 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
Uri? get avatar => Matrix.of(context)
|
||||||
|
.client
|
||||||
|
.getRoomById(roomId)
|
||||||
|
?.getState(EventTypes.RoomCreate)
|
||||||
|
?.sender
|
||||||
|
.avatarUrl;
|
||||||
|
|
||||||
String get title =>
|
String get title =>
|
||||||
Matrix.of(context)
|
Matrix.of(context)
|
||||||
.client
|
.client
|
||||||
@ -125,6 +132,13 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
Future<List<Event>> _loadStory() async {
|
Future<List<Event>> _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) {
|
||||||
|
final joinedFuture = room.client.onSync.stream
|
||||||
|
.where((u) => u.rooms?.join?.containsKey(room.id) ?? false)
|
||||||
|
.first;
|
||||||
|
await room.join();
|
||||||
|
await joinedFuture;
|
||||||
|
}
|
||||||
final timeline = await room.getTimeline();
|
final timeline = await room.getTimeline();
|
||||||
var events =
|
var events =
|
||||||
timeline.events.where((e) => e.type == EventTypes.Message).toList();
|
timeline.events.where((e) => e.type == EventTypes.Message).toList();
|
||||||
@ -149,12 +163,15 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
if (events.isNotEmpty) {
|
if (events.isNotEmpty) {
|
||||||
_restartTimer();
|
_restartTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preload images and videos
|
||||||
events
|
events
|
||||||
.where((event) => {MessageTypes.Image, MessageTypes.Video}
|
.where((event) => {MessageTypes.Image, MessageTypes.Video}
|
||||||
.contains(event.messageType))
|
.contains(event.messageType))
|
||||||
.forEach((event) => downloadAndDecryptAttachment(event,
|
.forEach((event) => downloadAndDecryptAttachment(event,
|
||||||
event.messageType == MessageTypes.Video && PlatformInfos.isMobile));
|
event.messageType == MessageTypes.Video && PlatformInfos.isMobile));
|
||||||
return events;
|
|
||||||
|
return events.reversed.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//@dart=2.12
|
//@dart=2.12
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
import 'package:flutter_blurhash/flutter_blurhash.dart';
|
import 'package:flutter_blurhash/flutter_blurhash.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
@ -11,6 +12,7 @@ import 'package:fluffychat/pages/story/story_page.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';
|
||||||
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
|
|
||||||
class StoryView extends StatelessWidget {
|
class StoryView extends StatelessWidget {
|
||||||
final StoryPageController controller;
|
final StoryPageController controller;
|
||||||
@ -20,9 +22,32 @@ class StoryView extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(controller.title),
|
titleSpacing: 0,
|
||||||
backgroundColor:
|
title: ListTile(
|
||||||
Theme.of(context).appBarTheme.backgroundColor?.withOpacity(0.5),
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: Text(
|
||||||
|
controller.title,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20,
|
||||||
|
shadows: [
|
||||||
|
Shadow(
|
||||||
|
color: Colors.black,
|
||||||
|
offset: Offset(0, 0),
|
||||||
|
blurRadius: 5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
leading: Avatar(
|
||||||
|
mxContent: controller.avatar,
|
||||||
|
name: controller.title,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
systemOverlayStyle: SystemUiOverlayStyle.light,
|
||||||
|
iconTheme: const IconThemeData(color: Colors.white),
|
||||||
|
elevation: 0,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
),
|
),
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
body: FutureBuilder<List<Event>>(
|
body: FutureBuilder<List<Event>>(
|
||||||
@ -40,13 +65,25 @@ class StoryView extends StatelessWidget {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (events.isEmpty) {
|
if (events.isEmpty) {
|
||||||
return Padding(
|
return Center(
|
||||||
padding: const EdgeInsets.all(8.0),
|
child: Column(
|
||||||
child: Center(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
child: Text(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Avatar(
|
||||||
|
mxContent: controller.avatar,
|
||||||
|
name: controller.title,
|
||||||
|
size: 128,
|
||||||
|
fontSize: 64,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
Text(
|
||||||
L10n.of(context)!.thisUserHasNotPostedAnythingYet,
|
L10n.of(context)!.thisUserHasNotPostedAnythingYet,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
)),
|
style: const TextStyle(fontSize: 20),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final event = events[controller.index];
|
final event = events[controller.index];
|
||||||
@ -115,12 +152,11 @@ class StoryView extends StatelessWidget {
|
|||||||
gradient: event.messageType == MessageTypes.Text
|
gradient: event.messageType == MessageTypes.Text
|
||||||
? LinearGradient(
|
? LinearGradient(
|
||||||
colors: [
|
colors: [
|
||||||
backgroundColor,
|
|
||||||
backgroundColorDark,
|
backgroundColorDark,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
],
|
],
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topCenter,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomCenter,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
@ -140,40 +176,35 @@ class StoryView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 8,
|
top: 4,
|
||||||
left: 8,
|
left: 4,
|
||||||
right: 8,
|
right: 4,
|
||||||
|
child: SafeArea(
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
for (var i = 0; i < events.length; i++)
|
for (var i = 0; i < events.length; i++)
|
||||||
Container(
|
Expanded(
|
||||||
margin: const EdgeInsets.all(4),
|
child: i == controller.index
|
||||||
width: 8,
|
? LinearProgressIndicator(
|
||||||
height: 8,
|
color: Colors.white,
|
||||||
decoration: BoxDecoration(
|
minHeight: 2,
|
||||||
border: Border.all(color: Colors.black, width: 1),
|
backgroundColor: Colors.grey.shade600,
|
||||||
color: i == controller.index
|
|
||||||
? Colors.white
|
|
||||||
: Colors.grey.shade400,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
child: SafeArea(
|
|
||||||
child: LinearProgressIndicator(
|
|
||||||
color: Theme.of(context).primaryColor,
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
||||||
value: controller.loadingMode
|
value: controller.loadingMode
|
||||||
? null
|
? null
|
||||||
: controller.progress.inMilliseconds /
|
: controller.progress.inMilliseconds /
|
||||||
StoryPageController.maxProgress.inMilliseconds,
|
StoryPageController
|
||||||
|
.maxProgress.inMilliseconds,
|
||||||
|
)
|
||||||
|
: Container(
|
||||||
|
margin: const EdgeInsets.all(4),
|
||||||
|
height: 2,
|
||||||
|
color: i < controller.index
|
||||||
|
? Colors.white
|
||||||
|
: Colors.grey.shade600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -6,8 +6,8 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
extension ClientStoriesExtension on Client {
|
extension ClientStoriesExtension on Client {
|
||||||
static const String _storiesRoomType = 'msc3588.stories.stories-room';
|
static const String storiesRoomType = 'msc3588.stories.stories-room';
|
||||||
static const String _storiesBlockListType = 'msc3588.stories.block-list';
|
static const String storiesBlockListType = 'msc3588.stories.block-list';
|
||||||
|
|
||||||
static const int lifeTimeInHours = 24;
|
static const int lifeTimeInHours = 24;
|
||||||
static const int maxPostsPerStory = 20;
|
static const int maxPostsPerStory = 20;
|
||||||
@ -23,7 +23,7 @@ extension ClientStoriesExtension on Client {
|
|||||||
.getState(EventTypes.RoomCreate)
|
.getState(EventTypes.RoomCreate)
|
||||||
?.content
|
?.content
|
||||||
.tryGet<String>('type') ==
|
.tryGet<String>('type') ==
|
||||||
_storiesRoomType)
|
storiesRoomType)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
Future<List<User>> getUndecidedContactsForStories(Room? storiesRoom) async {
|
Future<List<User>> getUndecidedContactsForStories(Room? storiesRoom) async {
|
||||||
@ -37,12 +37,12 @@ extension ClientStoriesExtension on Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> get storiesBlockList =>
|
List<String> get storiesBlockList =>
|
||||||
accountData[_storiesBlockListType]?.content.tryGetList<String>('users') ??
|
accountData[storiesBlockListType]?.content.tryGetList<String>('users') ??
|
||||||
[];
|
[];
|
||||||
|
|
||||||
Future<void> setStoriesBlockList(List<String> users) => setAccountData(
|
Future<void> setStoriesBlockList(List<String> users) => setAccountData(
|
||||||
userID!,
|
userID!,
|
||||||
_storiesBlockListType,
|
storiesBlockListType,
|
||||||
{'users': users},
|
{'users': users},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ extension ClientStoriesExtension on Client {
|
|||||||
Future<Room?> getStoriesRoom(BuildContext context) async {
|
Future<Room?> getStoriesRoom(BuildContext context) async {
|
||||||
final candidates = rooms.where((room) =>
|
final candidates = rooms.where((room) =>
|
||||||
room.getState(EventTypes.RoomCreate)?.content.tryGet<String>('type') ==
|
room.getState(EventTypes.RoomCreate)?.content.tryGet<String>('type') ==
|
||||||
_storiesRoomType &&
|
storiesRoomType &&
|
||||||
room.ownPowerLevel >= 100);
|
room.ownPowerLevel >= 100);
|
||||||
if (candidates.isEmpty) return null;
|
if (candidates.isEmpty) return null;
|
||||||
if (candidates.length == 1) return candidates.single;
|
if (candidates.length == 1) return candidates.single;
|
||||||
|
Loading…
Reference in New Issue
Block a user