feat: Implement send reactions

This commit is contained in:
Christian Pauly 2020-09-20 20:13:42 +02:00
parent 43dd22251c
commit 6bf25b709f
3 changed files with 96 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import 'package:famedlysdk/famedlysdk.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'dialogs/simple_dialogs.dart';
import 'matrix.dart'; import 'matrix.dart';
class MessageReactions extends StatelessWidget { class MessageReactions extends StatelessWidget {
@ -47,10 +48,12 @@ class MessageReactions extends StatelessWidget {
e.content['m.relates_to']['key'] == r.key, e.content['m.relates_to']['key'] == r.key,
orElse: () => null); orElse: () => null);
if (evt != null) { if (evt != null) {
evt.redact(); SimpleDialogs(context)
.tryRequestWithLoadingDialog(evt.redact());
} }
} else { } else {
event.room.sendReaction(event.eventId, r.key); SimpleDialogs(context).tryRequestWithLoadingDialog(
event.room.sendReaction(event.eventId, r.key));
} }
}, },
)) ))
@ -69,8 +72,9 @@ class _Reaction extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final borderColor = final borderColor = reacted
reacted ? Colors.red : Theme.of(context).secondaryHeaderColor; ? Theme.of(context).primaryColor
: Theme.of(context).secondaryHeaderColor;
final textColor = Theme.of(context).brightness == Brightness.dark final textColor = Theme.of(context).brightness == Brightness.dark
? Colors.white ? Colors.white
: Colors.black; : Colors.black;
@ -116,10 +120,10 @@ class _Reaction extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
color: color, color: color,
border: Border.all( border: Border.all(
width: fontSize / 20, width: 1,
color: borderColor, color: borderColor,
), ),
borderRadius: BorderRadius.all(Radius.circular(padding * 2)), borderRadius: BorderRadius.circular(8),
), ),
padding: EdgeInsets.all(padding), padding: EdgeInsets.all(padding),
child: content, child: content,

View File

@ -0,0 +1,30 @@
abstract class AppEmojis {
static const List<String> emojis = [
'👍',
'😊',
'😀',
'❤️',
'😍',
'😘',
'😇',
'😅',
'😭',
'😜',
'😱',
'😆',
'😉',
'😡',
'👋',
'🤔',
'🙁',
'🥳',
'😟',
'😄',
'😁',
'🙄',
'😂',
'🤣',
'😌',
'😬',
];
}

View File

@ -1,8 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/config/app_emojis.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:fluffychat/components/adaptive_page_layout.dart'; import 'package:fluffychat/components/adaptive_page_layout.dart';
import 'package:fluffychat/components/avatar.dart'; import 'package:fluffychat/components/avatar.dart';
@ -689,6 +689,61 @@ class _ChatState extends State<_Chat> {
}, },
), ),
), ),
AnimatedContainer(
duration: Duration(milliseconds: 300),
height: (editEvent == null &&
replyEvent == null &&
selectedEvents.length == 1)
? 56
: 0,
child: Material(
color: Theme.of(context).secondaryHeaderColor,
child: Builder(builder: (context) {
if (!(editEvent == null &&
replyEvent == null &&
selectedEvents.length == 1)) {
return Container();
}
var emojis = List<String>.from(AppEmojis.emojis);
final allReactionEvents = selectedEvents.first
.aggregatedEvents(timeline, RelationshipTypes.Reaction)
?.where((event) =>
event.senderId == event.room.client.userID &&
event.type == 'm.reaction');
allReactionEvents.forEach((event) {
try {
emojis.remove(event.content['m.relates_to']['key']);
} catch (_) {}
});
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: emojis.length,
itemBuilder: (c, i) => InkWell(
borderRadius: BorderRadius.circular(8),
onTap: () {
SimpleDialogs(context).tryRequestWithLoadingDialog(
room.sendReaction(
selectedEvents.first.eventId,
emojis[i],
),
);
setState(() => selectedEvents.clear());
},
child: Container(
width: 56,
height: 56,
alignment: Alignment.center,
child: Text(
emojis[i],
style: TextStyle(fontSize: 30),
),
),
),
);
}),
),
),
AnimatedContainer( AnimatedContainer(
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),
height: editEvent != null || replyEvent != null ? 56 : 0, height: editEvent != null || replyEvent != null ? 56 : 0,