feat: end polls

This commit is contained in:
OfficialDakari 2025-10-14 11:46:33 +05:00
parent c9cf4e90bf
commit 7bac9f8a85
4 changed files with 38 additions and 3 deletions

View File

@ -6,6 +6,7 @@
"longPressToRecordVoiceMessage": "Long press to record voice message.",
"pause": "Pause",
"resume": "Resume",
"endPoll": "End poll",
"anonymousPoll": "Anonymous",
"publicPoll": "Public",
"endedPoll": "Ended",

View File

@ -30,6 +30,7 @@
"pleaseEnterQuestion": "Введите вопрос",
"atLeastTwoAnswersRequired": "Требуется хотя бы 2 ответа",
"maxSelections": "Количество ответов",
"endPoll": "Завершить опрос",
"createPoll": "Создать опрос",
"alwaysUse24HourFormat": "нет",
"@alwaysUse24HourFormat": {

View File

@ -551,8 +551,7 @@ class ChatController extends State<ChatPageWithRoom>
void sendPollAction() async {
await showAdaptiveDialog(
context: context,
builder: (c) => SendPollDialog(room: room, outerContext: context)
);
builder: (c) => SendPollDialog(room: room, outerContext: context));
replyEvent = null;
}
@ -872,6 +871,22 @@ class ChatController extends State<ChatPageWithRoom>
}
}
void endPollAction() async {
final event = selectedEvents.first;
if (event == null) return;
final client = currentRoomBundle.firstWhere(
(cl) => selectedEvents.first.senderId == cl!.userID,
orElse: () => null,
);
if (client == null) return;
if (event.senderId != client!.userID) return;
await room.sendEvent({
'org.matrix.msc1767.text': 'Ended poll',
'm.relates_to': {'rel_type': 'm.reference', 'event_id': event.eventId},
'body': 'Ended poll'
}, type: 'org.matrix.msc3381.poll.end');
}
void redactEventsAction() async {
final reasonInput = selectedEvents.any((event) => event.status.isSent)
? await showTextInputDialog(

View File

@ -27,7 +27,7 @@ import '../../utils/stream_extension.dart';
import 'chat_emoji_picker.dart';
import 'chat_input_row.dart';
enum _EventContextAction { info, recover, translate, report }
enum _EventContextAction { info, recover, translate, report, endPoll }
class ChatView extends StatelessWidget {
final ChatController controller;
@ -92,6 +92,9 @@ class ChatView extends StatelessWidget {
case _EventContextAction.translate:
controller.translateEventAction();
break;
case _EventContextAction.endPoll:
controller.endPollAction();
break;
}
},
itemBuilder: (context) => [
@ -115,6 +118,21 @@ class ChatView extends StatelessWidget {
Text(L10n.of(context).recoverMessage),
]),
),
if (controller.selectedEvents.single.type == 'org.matrix.msc3381.poll.start' && controller.selectedEvents.single.senderId == Matrix.of(context).client.userID)
PopupMenuItem(
value: _EventContextAction.endPoll,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.check,
),
const SizedBox(width: 12),
Text(L10n.of(context).endPoll),
],
),
),
if (controller.selectedEvents.single.status.isSent)
PopupMenuItem(
value: _EventContextAction.report,