From 459469998b4223c59806c3e11ef824016566663a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 28 Jun 2024 04:34:35 +0800 Subject: [PATCH] :sparkles: Call records --- lib/translations.dart | 4 +++ lib/widgets/chat/chat_event.dart | 31 ++++++++++++++++++++++-- lib/widgets/chat/chat_message_input.dart | 3 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/translations.dart b/lib/translations.dart index 6d6badb..d7f313b 100644 --- a/lib/translations.dart +++ b/lib/translations.dart @@ -168,6 +168,8 @@ class SolianMessages extends Translations { 'messageUnsyncCaption': '@count message(s) still in un-synced.', 'messageEditDesc': 'Edited message @id', 'messageDeleteDesc': 'Deleted message @id', + 'messageCallStartDesc': '@user starts a call', + 'messageCallEndDesc': 'Call last for @duration', 'messageTypeUnsupported': 'Unsupported Message: @type', 'messageInputPlaceholder': 'Message @channel', 'messageActionList': 'Actions of Message', @@ -385,6 +387,8 @@ class SolianMessages extends Translations { 'messageDecoding': '解码信息中…', 'messageEditDesc': '修改了消息 @id', 'messageDeleteDesc': '删除了消息 @id', + 'messageCallStartDesc': '@user 发起了一次童话', + 'messageCallEndDesc': '通话持续了 @duration', 'messageTypeUnsupported': '不支持的消息类型 @type', 'messageActionList': '消息的操作', 'messageDeletionConfirm': '确认删除消息', diff --git a/lib/widgets/chat/chat_event.dart b/lib/widgets/chat/chat_event.dart index 8ded72b..d3ddbba 100644 --- a/lib/widgets/chat/chat_event.dart +++ b/lib/widgets/chat/chat_event.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -30,6 +28,14 @@ class ChatEvent extends StatelessWidget { this.chatController, }); + String _formatDuration(Duration duration) { + String negativeSign = duration.isNegative ? '-' : ''; + String twoDigits(int n) => n.toString().padLeft(2, '0'); + String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60).abs()); + String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60).abs()); + return '$negativeSign${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds'; + } + Widget buildQuote() { return FutureBuilder( future: chatController!.getEvent( @@ -75,6 +81,27 @@ class ChatEvent extends StatelessWidget { isHasMerged: isHasMerged, isQuote: isQuote, ); + case 'calls.start': + return ChatEventMessageActionLog( + icon: const Icon(Icons.call_made, size: 16), + text: 'messageCallStartDesc' + .trParams({'user': '@${item.sender.account.name}'}), + isMerged: isMerged, + isHasMerged: isHasMerged, + isQuote: isQuote, + ); + case 'calls.end': + return ChatEventMessageActionLog( + icon: const Icon(Icons.call_received, size: 16), + text: 'messageCallEndDesc'.trParams({ + 'duration': _formatDuration( + Duration(milliseconds: item.body['last']), + ), + }), + isMerged: isMerged, + isHasMerged: isHasMerged, + isQuote: isQuote, + ); case 'system.changes': return ChatEventMessageActionLog( icon: const Icon(Icons.manage_history, size: 16), diff --git a/lib/widgets/chat/chat_message_input.dart b/lib/widgets/chat/chat_message_input.dart index fa31fc1..8093df0 100644 --- a/lib/widgets/chat/chat_message_input.dart +++ b/lib/widgets/chat/chat_message_input.dart @@ -65,8 +65,9 @@ class _ChatMessageInputState extends State { // TODO Deal with the @ ping (query uid with username), and then add into related_user and replace the @ with internal link in body + const uuid = Uuid(); final payload = { - 'uuid': const Uuid().v4(), + 'uuid': uuid.v4(), 'type': _editTo == null ? 'messages.new' : 'messages.edit', 'body': { 'text': _textController.value.text,