Skip to content

Commit

Permalink
TW-1827: online status is not updated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn committed Jun 19, 2024
1 parent 025fa9d commit 8de41a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 12 additions & 1 deletion 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,7 +1377,11 @@
"type": "text",
"placeholders": {}
},
"aWhileAgo": "A while ago",
"aWhileAgo": "a while ago",
"@aWhileAgo": {
"type": "text",
"placeholders": {}
},
"ok": "Ok",
"@ok": {
"type": "text",
Expand Down Expand Up @@ -2567,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);
}

String _formatDateWithLocale(BuildContext context, String pattern) {
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/room_status_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ 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

0 comments on commit 8de41a9

Please sign in to comment.