Merge branch 'krille/share-stories' into 'main'

feat: Share to story

See merge request famedly/fluffychat!644
This commit is contained in:
Krille Fear 2021-12-25 18:06:57 +00:00
commit 5f8001ec35
4 changed files with 70 additions and 16 deletions

View File

@ -2667,5 +2667,6 @@
"publish": "Publish",
"whoCanSeeMyStories": "Who can see my stories?",
"unsubscribeStories": "Unsubscribe stories",
"thisUserHasNotPostedAnythingYet": "This user has not posted anything in their story yet"
"thisUserHasNotPostedAnythingYet": "This user has not posted anything in their story yet",
"yourStory": "Your story"
}

View File

@ -152,6 +152,41 @@ class AddStoryController extends State<AddStoryPage> {
final text = Matrix.of(context).client.userID!;
backgroundColor = text.color;
backgroundColorDark = text.darkColor;
final shareContent = Matrix.of(context).shareContent;
// ignore: unnecessary_null_comparison
if (shareContent != null) {
image = shareContent.tryGet<MatrixFile>('file');
controller.text = shareContent.tryGet<String>('body') ?? '';
if (shareContent.tryGet<String>('msgtype') == MessageTypes.Image) {
Event(
content: shareContent,
type: EventTypes.Message,
room: Room(id: '!tmproom', client: Matrix.of(context).client),
eventId: 'tmpevent',
senderId: '@tmpsender:example',
originServerTs: DateTime.now(),
).downloadAndDecryptAttachment().then((file) {
setState(() {
image = file;
});
});
} else if (shareContent.tryGet<String>('msgtype') == MessageTypes.Video) {
Event(
content: shareContent,
type: EventTypes.Message,
room: Room(id: '!tmproom', client: Matrix.of(context).client),
eventId: 'tmpevent',
senderId: '@tmpsender:example',
originServerTs: DateTime.now(),
).downloadAndDecryptAttachment().then((file) {
setState(() {
video = file;
});
});
}
Matrix.of(context).shareContent = null;
}
}
@override

View File

@ -308,7 +308,7 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> {
controller: widget.controller.scrollController,
itemCount: rooms.length + 1,
itemBuilder: (BuildContext context, int i) {
if (i == 0) {
if (i == 0 && widget.controller.activeSpaceId == null) {
return const StoriesHeader();
}
i--;
@ -332,6 +332,10 @@ class _ChatListViewBodyState extends State<_ChatListViewBody> {
),
);
}
child = Material(
color: Theme.of(context).scaffoldBackgroundColor,
child: child,
);
return PageTransitionSwitcher(
reverse: reversed,
transitionBuilder: (

View File

@ -13,7 +13,11 @@ import 'package:fluffychat/utils/matrix_sdk_extensions.dart/client_stories_exten
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
enum ContextualRoomAction { mute, unmute, leave }
enum ContextualRoomAction {
mute,
unmute,
leave,
}
class StoriesHeader extends StatelessWidget {
const StoriesHeader({Key? key}) : super(key: key);
@ -82,7 +86,8 @@ class StoriesHeader extends StatelessWidget {
if (client.storiesRooms.isEmpty && client.contacts.isEmpty) {
return Container();
}
if (client.storiesRooms.isEmpty) {
if (client.storiesRooms.isEmpty ||
Matrix.of(context).shareContent != null) {
return ListTile(
leading: CircleAvatar(
radius: Avatar.defaultSize / 2,
@ -95,13 +100,13 @@ class StoriesHeader extends StatelessWidget {
);
}
return SizedBox(
height: 82,
height: 98,
child: ListView(
padding: const EdgeInsets.symmetric(horizontal: 2),
scrollDirection: Axis.horizontal,
children: [
_StoryButton(
label: 'Add to story',
label: L10n.of(context)!.yourStory,
onPressed: () => _addToStoryAction(context),
child: const Icon(Icons.add),
),
@ -116,6 +121,7 @@ class StoriesHeader extends StatelessWidget {
.sender
.avatarUrl,
name: room.creatorDisplayname,
size: 100,
),
unread: room.notificationCount > 0 ||
room.membership == Membership.invite,
@ -168,13 +174,13 @@ class _StoryButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 74,
width: 78,
child: InkWell(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
onTap: onPressed,
onLongPress: onLongPressed,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Column(
children: [
const SizedBox(height: 8),
@ -192,24 +198,32 @@ class _StoryButton extends StatelessWidget {
end: Alignment.bottomRight,
)
: null,
color: unread ? null : Theme.of(context).colorScheme.surface,
color: unread ? null : Theme.of(context).dividerColor,
borderRadius: BorderRadius.circular(Avatar.defaultSize),
),
child: Material(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(Avatar.defaultSize),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: CircleAvatar(
radius: Avatar.defaultSize / 2,
radius: 30,
backgroundColor: Theme.of(context).colorScheme.surface,
foregroundColor: Theme.of(context).textTheme.bodyText1?.color,
foregroundColor:
Theme.of(context).textTheme.bodyText1?.color,
child: child,
),
),
),
),
const SizedBox(height: 8),
Text(
label,
maxLines: 1,
textAlign: TextAlign.center,
style: const TextStyle(
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
fontWeight: unread ? FontWeight.bold : null,
),
),
],