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

TW-1827: online status is not updated correctly #1879

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@
"type": "text",
"placeholders": {}
},
"loading": "Loading status...",
"loadMore": "Load more…",
"@loadMore": {
"type": "text",
Expand Down Expand Up @@ -1376,6 +1377,11 @@
"type": "text",
"placeholders": {}
},
"aWhileAgo": "a while ago",
"@aWhileAgo": {
"type": "text",
"placeholders": {}
},
"ok": "Ok",
"@ok": {
"type": "text",
Expand Down Expand Up @@ -2566,6 +2572,12 @@
"hour": {}
}
},
"onlineDayAgo": "online {day} day ago",
"@onlineDayAgo": {
"placeholders": {
"day": {}
}
},
"noMessageHereYet": "No message here yet...",
"@noMessageHereYet": {},
"sendMessageGuide": "Send a message or tap on the greeting bellow.",
Expand Down
9 changes: 7 additions & 2 deletions lib/utils/date_time_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ extension DateTimeExtension on DateTime {
return other.difference(this) < const Duration(hours: 1);
}

bool isLessThanTenHoursAgo({DateTime? other}) {
bool isLessThanADayAgo({DateTime? other}) {
other ??= DateTime.now();
return other.difference(this) < const Duration(hours: 10);
return other.difference(this) < const Duration(hours: 24);
}

bool isLessThan30DaysAgo({DateTime? other}) {
other ??= DateTime.now();
return other.difference(this) < const Duration(days: 30);
hieutbui marked this conversation as resolved.
Show resolved Hide resolved
}

String _formatDateWithLocale(BuildContext context, String pattern) {
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/room_status_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ extension RoomStatusExtension on Room {
return L10n.of(context)!.onlineMinAgo(
currentDateTime.difference(lastActiveDateTime).inMinutes,
);
} else if (lastActiveDateTime.isLessThanTenHoursAgo()) {
} else if (lastActiveDateTime.isLessThanADayAgo()) {
final timeOffline = currentDateTime.difference(lastActiveDateTime);
return L10n.of(context)!.onlineHourAgo(
(timeOffline.inMinutes / 60).round(),
);
} else if (lastActiveDateTime.isLessThan30DaysAgo()) {
return L10n.of(context)!.onlineDayAgo(
currentDateTime.difference(lastActiveDateTime).inDays,
);
} else {
return L10n.of(context)!.aWhileAgo;
}
}
}
Expand Down
Loading