2021-11-13 10:20:09 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
2021-12-22 10:04:19 +01:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2021-11-13 10:20:09 +01:00
|
|
|
import 'package:fluffychat/config/app_emojis.dart';
|
|
|
|
import 'package:fluffychat/pages/chat/chat.dart';
|
|
|
|
|
|
|
|
class ReactionsPicker extends StatelessWidget {
|
|
|
|
final ChatController controller;
|
|
|
|
const ReactionsPicker(this.controller, {Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (controller.showEmojiPicker) return Container();
|
2021-11-19 10:23:24 +01:00
|
|
|
final display = controller.editEvent == null &&
|
|
|
|
controller.replyEvent == null &&
|
|
|
|
controller.room.canSendDefaultMessages &&
|
|
|
|
controller.selectedEvents.isNotEmpty;
|
2021-11-13 10:20:09 +01:00
|
|
|
return AnimatedContainer(
|
|
|
|
duration: const Duration(milliseconds: 300),
|
2021-11-19 10:23:24 +01:00
|
|
|
height: (display) ? 56 : 0,
|
2021-11-13 10:20:09 +01:00
|
|
|
child: Material(
|
2021-12-22 10:04:19 +01:00
|
|
|
color: Colors.transparent,
|
2021-11-13 10:20:09 +01:00
|
|
|
child: Builder(builder: (context) {
|
2021-11-19 10:23:24 +01:00
|
|
|
if (!display) {
|
2021-11-13 10:20:09 +01:00
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
final emojis = List<String>.from(AppEmojis.emojis);
|
|
|
|
final allReactionEvents = controller.selectedEvents.first
|
|
|
|
.aggregatedEvents(controller.timeline, RelationshipTypes.reaction)
|
|
|
|
?.where((event) =>
|
|
|
|
event.senderId == event.room.client.userID &&
|
|
|
|
event.type == 'm.reaction');
|
|
|
|
|
|
|
|
for (final event in allReactionEvents) {
|
|
|
|
try {
|
|
|
|
emojis.remove(event.content['m.relates_to']['key']);
|
|
|
|
} catch (_) {}
|
|
|
|
}
|
2021-12-22 10:04:19 +01:00
|
|
|
return Row(children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
bottomRight:
|
|
|
|
Radius.circular(AppConfig.borderRadius))),
|
|
|
|
padding: const EdgeInsets.only(right: 1),
|
|
|
|
child: ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: emojis.length,
|
|
|
|
itemBuilder: (c, i) => InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
onTap: () => controller.sendEmojiAction(emojis[i]),
|
|
|
|
child: Container(
|
|
|
|
width: 56,
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(
|
|
|
|
emojis[i],
|
|
|
|
style: const TextStyle(fontSize: 30),
|
|
|
|
),
|
|
|
|
),
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
2021-12-22 10:04:19 +01:00
|
|
|
))),
|
|
|
|
InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
width: 36,
|
|
|
|
height: 56,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).secondaryHeaderColor,
|
|
|
|
shape: BoxShape.circle,
|
2021-11-13 10:20:09 +01:00
|
|
|
),
|
2021-12-22 10:04:19 +01:00
|
|
|
child: const Icon(Icons.add_outlined),
|
|
|
|
),
|
|
|
|
onTap: () => controller.pickEmojiAction(allReactionEvents))
|
|
|
|
]);
|
2021-11-13 10:20:09 +01:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|