Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose sent at for messages #1140

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/components/chat_history/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:rtchat/components/chat_history/ad.dart';
import 'package:rtchat/components/chat_history/auxiliary/realtimecash_donation.dart';
Expand Down Expand Up @@ -94,6 +95,12 @@ class ChatHistoryMessage extends StatelessWidget {
primary: false,
children: [
if (kDebugMode) Text("DEBUG: id=${m.messageId}"),
ListTile(
leading:
const Icon(Icons.timer, color: Colors.grey),
title: Text(
'${AppLocalizations.of(context)!.sentAt}: ${formatDuration(message.timestamp)}'),
),
Consumer<TtsModel>(
builder: (context, ttsModel, child) {
if (ttsModel.isMuted(m.author)) {
Expand Down Expand Up @@ -307,4 +314,19 @@ class ChatHistoryMessage extends StatelessWidget {
throw AssertionError("invalid message type $m");
}
}

String formatDuration(DateTime timestamp) {
final now = DateTime.now();
final difference = now.difference(timestamp);

if (difference.inMinutes < 1) {
return 'now';
} else if (difference.inMinutes < 60) {
return '${difference.inMinutes} minutes ago';
} else if (difference.inHours < 24) {
return '${difference.inHours} hours ago';
} else {
return DateFormat('yyyy-mm-dd').format(timestamp);
}
}
}
57 changes: 56 additions & 1 deletion lib/components/chat_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:rtchat/components/chat_history/message.dart';
import 'package:rtchat/components/chat_history/separator.dart';
Expand Down Expand Up @@ -84,6 +85,21 @@ class _RebuildableWidgetState extends State<RebuildableWidget> {
}
}

String formatDuration(DateTime timestamp) {
final now = DateTime.now();
final difference = now.difference(timestamp);

if (difference.inMinutes < 1) {
return 'now';
} else if (difference.inMinutes < 60) {
return '${difference.inMinutes} minutes ago';
} else if (difference.inHours < 24) {
return '${difference.inHours} hours ago';
} else {
return DateFormat('dd/MM/yyyy').format(timestamp);
}
}

DateTime? _getExpiration(
MessageModel model,
EventSubConfigurationModel eventSubConfigurationModel,
Expand Down Expand Up @@ -216,6 +232,7 @@ class _ChatPanelWidgetState extends State<ChatPanelWidget>
var _atBottom = true;
var _refreshPending = false;
var _showScrollNotification = true;
bool _showTimeForLastMessage = false;

@override
void initState() {
Expand Down Expand Up @@ -386,8 +403,9 @@ class _ChatPanelWidgetState extends State<ChatPanelWidget>
}
}
}
final messageWidget = ChatHistoryMessage(
Widget messageWidget = ChatHistoryMessage(
message: message, channel: widget.channel);
final isLastMessage = index == messages.length - 1;
final showSeparator = messagesModel.separators
.contains(messages.length - index - 1);
// only show separators after the first 50.
Expand All @@ -401,6 +419,43 @@ class _ChatPanelWidgetState extends State<ChatPanelWidget>
],
);
}
if (isLastMessage) {
messageWidget = GestureDetector(
onHorizontalDragEnd: (details) {
// When the user swipes on the last message, we toggle the visibility of the time.
setState(() {
_showTimeForLastMessage = true;
});
},
onTap: () {
//hide the duratrion when someone taps on the message

setState(() {
_showTimeForLastMessage = false;
});
},
child: Stack(
alignment: Alignment.centerRight,
children: [
messageWidget,
Positioned(
right: 8.0,
child: AnimatedOpacity(
opacity:
_showTimeForLastMessage ? 1.0 : 0.0,
duration:
const Duration(milliseconds: 300),
child: Text(
formatDuration(message.timestamp),
style: const TextStyle(
color: Colors.grey),
),
),
),
],
),
);
}
return messageWidget;
})),
findChildIndexCallback: (key) => messages.indexWhere(
Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_bn.arb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"invalidUrlErrorText": "অবৈধ URL এর ত্রুটি টেক্সট",
"duplicateUrlErrorText": "ডুপ্লিকেট URL ত্রুটি টেক্সট",
"or": "অথবা",
"activityFeed": "অ্যাক্টিভিটি ফিড",
"clearCookies": "কুকিজ ক্লিয়ার করুন",
"disabled": "অক্ষম",
"twitchActivityFeed": "টুইচ এর একটিভিটি ফিড",
Expand Down Expand Up @@ -112,5 +113,6 @@
"durationOneDayTimeoutPrompt": "1 দিনের জন্য সময়সীমা",
"durationTwoDaysTimeoutPrompt": "2 দিনের জন্য সময়সীমা",
"durationOneWeekTimeoutPrompt": "1 সপ্তাহের জন্য সময়সীমা",
"durationTwoWeeksTimeoutPrompt": "2 সপ্তাহের জন্য সময়সীমা"
"durationTwoWeeksTimeoutPrompt": "2 সপ্তাহের জন্য সময়সীমা",
"sentAt": "এ পাঠানো হয়েছে"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"invalidUrlErrorText": "Dieser Link scheint ungültig zu sein.",
"duplicateUrlErrorText": "Dieser Link existiert schon",
"or": "oder",
"activityFeed": "Aktivitäts-Feed",
SputNikPlop marked this conversation as resolved.
Show resolved Hide resolved
"clearCookies": "cookies löschen",
"disabled": "deaktiviert",
"twitchActivityFeed": "Twitch Aktivitäts-Feed",
Expand Down Expand Up @@ -112,5 +113,6 @@
"durationOneDayTimeoutPrompt": "Timeout für 1 tag",
"durationTwoDaysTimeoutPrompt": "Timeout für 2 tage",
"durationOneWeekTimeoutPrompt": "Timeout für 1 woche",
"durationTwoWeeksTimeoutPrompt": "Timeout für 2 wochen"
"durationTwoWeeksTimeoutPrompt": "Timeout für 2 wochen",
"sentAt": "Gesendet um"
}
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -574,5 +574,9 @@
"durationTwoWeeksTimeoutPrompt": "Timeout for 2 weeks",
"@durationTwoWeeksTimeoutPrompt": {
"descriptionTimeoutPrompt": "Button label to timeout for a two week duration"
},
"sentAt": "Sent at",
"@sentAt": {
"sentAt": "Text label to show when a message was last sent at"
}
}
4 changes: 3 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"invalidUrlErrorText": "Este no parece ser un enlace válido",
"duplicateUrlErrorText": "Este enlace ya existe",
"or": "o",
"activityFeed": "Feed de actividades",
"clearCookies": "Limpiar cookies",
"disabled": "Desactivado",
"twitchActivityFeed": "Feed de actividades de Twitch",
Expand Down Expand Up @@ -112,5 +113,6 @@
"durationOneDayTimeoutPrompt": "Suspender por 1 día",
"durationTwoDaysTimeoutPrompt": "Suspender por 2 días",
"durationOneWeekTimeoutPrompt": "Suspender por 1 semana",
"durationTwoWeeksTimeoutPrompt": "Suspender por 2 semanas"
"durationTwoWeeksTimeoutPrompt": "Suspender por 2 semanas",
"sentAt": "Enviado a las"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"invalidUrlErrorText": "Ce lien semble indisponible.",
"duplicateUrlErrorText": "Ce lien existe déjà.",
"or": "ou",
"activityFeed": "Fil d'actualité",
"clearCookies": "supprimer les cookies",
"disabled": "déactivé",
"twitchActivityFeed": "Fil d'actualité twitch",
Expand Down Expand Up @@ -112,5 +113,6 @@
"durationOneDayTimeoutPrompt": "Délai d'attente pour 1 jour",
"durationTwoDaysTimeoutPrompt": "Délai d'attente pour 2 jours",
"durationOneWeekTimeoutPrompt": "Délai d'attente pour 1 semaine",
"durationTwoWeeksTimeoutPrompt": "Délai d'attente pour 2 semaines"
"durationTwoWeeksTimeoutPrompt": "Délai d'attente pour 2 semaines",
"sentAt": "Envoyé à :"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"invalidUrlErrorText": "Dit ziet er niet uit als een geldige URL",
"duplicateUrlErrorText": "Deze link bestaat all",
"or": "of",
"activityFeed": "Activiteitenfeed",
"clearCookies": "Cookies ",
"newMessageCount": "{count,plural, =0{Geen nieuwe berichten} =1{1 nieuw bericht} other{{count} nieuwe berichten}}",
"streamOnline": "Stream online op {date}, {time}",
Expand Down Expand Up @@ -112,5 +113,6 @@
"durationOneDayTimeoutPrompt": "Time-out voor 1 dag",
"durationTwoDaysTimeoutPrompt": "Time-out voor 2 dagen",
"durationOneWeekTimeoutPrompt": "Time-out voor 1 week",
"durationTwoWeeksTimeoutPrompt": "Time-out voor 2 weken"
"durationTwoWeeksTimeoutPrompt": "Time-out voor 2 weken",
"sentAt": "Verzonden op"
}
3 changes: 2 additions & 1 deletion lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@
"durationOneDayTimeoutPrompt": "Timeout de 1 dia",
"durationTwoDaysTimeoutPrompt": "Timeout de 2 dias",
"durationOneWeekTimeoutPrompt": "Timeout de 1 semana",
"durationTwoWeeksTimeoutPrompt": "Timeout de 2 semanas"
"durationTwoWeeksTimeoutPrompt": "Timeout de 2 semanas",
"sentAt": "Enviado às"
}
6 changes: 4 additions & 2 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"invalidUrlErrorText": "这看起来不像是有效的网址",
"duplicateUrlErrorText": "此链接已存在",
"or": "或者",
"activityFeed": "活动提要",
"clearCookies": "清除Cookies",
"disabled": "禁用",
"twitchActivityFeed": "Twitch活动提要",
Expand Down Expand Up @@ -112,5 +113,6 @@
"durationOneDayTimeoutPrompt": "暂停1天",
"durationTwoDaysTimeoutPrompt": "暂停2天",
"durationOneWeekTimeoutPrompt": "暂停1周",
"durationTwoWeeksTimeoutPrompt": "暂停2周"
}
"durationTwoWeeksTimeoutPrompt": "暂停2周",
"sentAt": "發送於 :"
}
5 changes: 3 additions & 2 deletions lib/l10n/app_zh_Hant.arb
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@
"durationOneDayTimeoutPrompt": "封鎖1天",
"durationTwoDaysTimeoutPrompt": "封鎖2天",
"durationOneWeekTimeoutPrompt": "封鎖1週",
"durationTwoWeeksTimeoutPrompt": "封鎖2週"
}
"durationTwoWeeksTimeoutPrompt": "封鎖2週",
"sentAt": "发送于 :"
}
Loading