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 all 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
38 changes: 38 additions & 0 deletions lib/components/chat_history/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@ class ChatHistoryMessage extends StatelessWidget {
return child;
}

String getLabel(int seconds) {
if (seconds < 60) {
return AppLocalizations.of(context)!.justNow;
} else if (seconds < 3600) {
int minutes = seconds ~/ 60;
return "$minutes ${AppLocalizations.of(context)?.minutes} ${AppLocalizations.of(context)?.agoMesssageText}"; // Customize with i18n if necessary
} else if (seconds < 86400) {
// Less than 1 day
int hours = seconds ~/ 3600;
return "$hours ${AppLocalizations.of(context)?.hours} ${AppLocalizations.of(context)?.agoMesssageText}"; // Customize with i18n if necessary
} else if (seconds < 604800) {
// Less than 1 week
int days = seconds ~/ 86400;
return "$days ${AppLocalizations.of(context)?.days} ${AppLocalizations.of(context)?.agoMesssageText}"; // Customize with i18n if necessary
} else if (seconds < 1209600) {
// Less than 2 weeks
return AppLocalizations.of(context)!.lastWeek;
} else {
int weeks = seconds ~/ 604800;
return "$weeks ${AppLocalizations.of(context)?.weeks} ${AppLocalizations.of(context)?.agoMesssageText}"; // Customize with i18n if necessary
}
}

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

return getLabel(difference.inSeconds);
}

return Material(
child: InkWell(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
Expand All @@ -93,6 +123,14 @@ 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)!.sentMesssageExpose} '
'${formatDuration(message.timestamp)} '
'${AppLocalizations.of(context)!.agoMesssageText}'),
),
Consumer<TtsModel>(
builder: (context, ttsModel, child) {
if (ttsModel.isMuted(m.author)) {
Expand Down
36 changes: 36 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -988,5 +988,41 @@
"textToSpeechDisabled": "Text to speech disabled",
"@textToSpeechDisabled": {
"description": "Message indicating that text to speech has been disabled"
},
"sentMesssageExpose" : "Sent",
"@sentMesssageExpose": {
"description": "Text label for the sent message expose"
},
"agoMesssageText" : "Ago",
"@agoMesssageText": {
"description": "Text label for the ago message text"
},
"justNow": "Just now",
"@justNow": {
"description": "Text label for the just now time"
},
"minutes" : "Minutes",
"@minutes": {
"description": "Text label for the minutes time"
},
"hours" : "Hours",
"@hours": {
"description": "Text label for the hours time"
},
"days" : "Days",
"@days": {
"description": "Text label for the days time"
},
"weeks" : "Weeks",
"@weeks": {
"description": "Text label for the weeks time"
},
"months" : "Months",
"@months": {
"description": "Text label for the months time"
},
"lastWeek" : "Last week",
"@lastWeek": {
"description": "Text label for the last week time"
}
}
Loading