Merge branch 'braid/cute-events' into 'main'

feat: implement cute events

See merge request famedly/fluffychat!1031
This commit is contained in:
Krille Fear 2022-11-21 14:16:36 +00:00
commit 665f9909b1
9 changed files with 164 additions and 5 deletions

3
.gitignore vendored
View File

@ -14,7 +14,7 @@ lib/generated_plugin_registrant.dart
prime prime
# libolm package # libolm package
/assets/js/package/* /assets/js/package
# IntelliJ related # IntelliJ related
*.iml *.iml
@ -62,4 +62,3 @@ ios/Podfile.lock
/linux/out /linux/out
/macos/out /macos/out
.vs .vs
assets/js/package/olm.js

View File

View File

@ -1 +0,0 @@
// Dummy file :-)

View File

@ -103,6 +103,30 @@
"type": "text", "type": "text",
"placeholders": {} "placeholders": {}
}, },
"commandHint_googly":"Send some googly eyes",
"commandHint_cuddle": "Send a cuddle",
"commandHint_hug": "Send a hug",
"googlyEyesContent": "{senderName} sends you googly eyes",
"@googlyEyesContent": {
"type": "text",
"placeholders": {
"senderName": {}
}
},
"cuddleContent": "{senderName} cuddles you",
"@cuddleContent": {
"type": "text",
"placeholders": {
"senderName": {}
}
},
"hugContent": "{senderName} hugs you",
"@hugContent": {
"type": "text",
"placeholders": {
"senderName": {}
}
},
"answeredTheCall": "{senderName} answered the call", "answeredTheCall": "{senderName} answered the call",
"@answeredTheCall": { "@answeredTheCall": {
"type": "text", "type": "text",

View File

@ -44,6 +44,12 @@ String commandHint(L10n l10n, String command) {
return l10n.commandHint_markasdm; return l10n.commandHint_markasdm;
case 'markasgroup': case 'markasgroup':
return l10n.commandHint_markasgroup; return l10n.commandHint_markasgroup;
case 'googly':
return l10n.commandHint_googly;
case 'hug':
return l10n.commandHint_hug;
case 'cuddle':
return l10n.commandHint_cuddle;
default: default:
return ""; return "";
} }

View File

@ -0,0 +1,128 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
class CuteContent extends StatefulWidget {
final Event event;
const CuteContent(this.event, {Key? key}) : super(key: key);
@override
State<CuteContent> createState() => _CuteContentState();
}
class _CuteContentState extends State<CuteContent> {
static final List<OverlayEntry> overlays = [];
@override
void initState() {
if (AppConfig.autoplayImages && overlays.isEmpty) {
addOverlay();
}
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder<User?>(
future: widget.event.fetchSenderUser(),
builder: (context, snapshot) {
final label = generateLabel(snapshot.data);
return GestureDetector(
onTap: addOverlay,
child: SizedBox.square(
dimension: 300,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.event.text,
style: const TextStyle(fontSize: 150),
),
if (label != null) Text(label)
],
),
),
);
},
);
}
Widget overlayBuilder(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
final position = Size(
Random().nextInt(constraints.maxWidth.round() - 64).toDouble(),
Random().nextInt(constraints.maxHeight.round() - 64).toDouble());
return Padding(
padding: EdgeInsets.only(
top: position.height,
left: position.width,
bottom: constraints.maxHeight - 64 - position.height,
right: constraints.maxWidth - 64 - position.width),
child: SizedBox.square(
dimension: 64,
child: GestureDetector(
onTap: removeOverlay,
child: Text(
widget.event.text,
style: const TextStyle(fontSize: 48),
),
),
),
);
});
}
Future<void> addOverlay() async {
await Future.delayed(const Duration(milliseconds: 50));
for (int i = 0; i < 5; i++) {
final overlay = OverlayEntry(
builder: overlayBuilder,
);
Overlay.of(context)?.insert(overlay);
Future.delayed(Duration(seconds: Random().nextInt(35))).then((_) {
overlay.remove();
overlays.remove(overlay);
});
overlays.add(overlay);
}
}
void removeOverlay() {
if (overlays.isEmpty) return;
final overlay = overlays.removeLast();
overlay.remove();
}
generateLabel(User? user) {
switch (widget.event.content['cute_type']) {
case 'googly_eyes':
return L10n.of(context)?.googlyEyesContent(
user?.displayName ??
widget.event.senderFromMemoryOrFallback.displayName ??
'',
);
case 'cuddle':
return L10n.of(context)?.cuddleContent(
user?.displayName ??
widget.event.senderFromMemoryOrFallback.displayName ??
'',
);
case 'hug':
return L10n.of(context)?.hugContent(
user?.displayName ??
widget.event.senderFromMemoryOrFallback.displayName ??
'',
);
}
}
}

View File

@ -14,6 +14,7 @@ import '../../../utils/platform_infos.dart';
import '../../../utils/url_launcher.dart'; import '../../../utils/url_launcher.dart';
import '../../bootstrap/bootstrap_dialog.dart'; import '../../bootstrap/bootstrap_dialog.dart';
import 'audio_player.dart'; import 'audio_player.dart';
import 'cute_events.dart';
import 'html_message.dart'; import 'html_message.dart';
import 'image_bubble.dart'; import 'image_bubble.dart';
import 'map_bubble.dart'; import 'map_bubble.dart';
@ -108,6 +109,8 @@ class MessageContent extends StatelessWidget {
case MessageTypes.Sticker: case MessageTypes.Sticker:
if (event.redacted) continue textmessage; if (event.redacted) continue textmessage;
return Sticker(event); return Sticker(event);
case CuteEventContent.eventType:
return CuteContent(event);
case MessageTypes.Audio: case MessageTypes.Audio:
if (PlatformInfos.isMobile || PlatformInfos.isMacOS) { if (PlatformInfos.isMobile || PlatformInfos.isMacOS) {
return AudioPlayerWidget( return AudioPlayerWidget(

View File

@ -956,7 +956,7 @@ packages:
name: matrix name: matrix
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.15.2" version: "0.15.4"
matrix_api_lite: matrix_api_lite:
dependency: transitive dependency: transitive
description: description:

View File

@ -60,7 +60,7 @@ dependencies:
just_audio: ^0.9.20 just_audio: ^0.9.20
keyboard_shortcuts: ^0.1.4 keyboard_shortcuts: ^0.1.4
latlong2: ^0.8.1 latlong2: ^0.8.1
matrix: ^0.15.2 matrix: ^0.15.4
matrix_homeserver_recommendations: ^0.3.0 matrix_homeserver_recommendations: ^0.3.0
matrix_link_text: ^1.0.2 matrix_link_text: ^1.0.2
native_imaging: ^0.1.0 native_imaging: ^0.1.0