@@ -1880,14 +1880,11 @@ String formatHeaderDate(
1880
1880
}
1881
1881
}
1882
1882
1883
- // TODO(i18n): web seems to ignore locale in formatting time, but we could do better
1884
- final _kMessageTimestampFormat = DateFormat ('h:mm aa' , 'en_US' );
1885
-
1886
1883
class SenderRow extends StatelessWidget {
1887
- const SenderRow ({super .key, required this .message, required this .showTimestamp });
1884
+ const SenderRow ({super .key, required this .message, required this .timestampStyle });
1888
1885
1889
1886
final MessageBase message;
1890
- final bool showTimestamp ;
1887
+ final MessageTimestampStyle timestampStyle ;
1891
1888
1892
1889
bool _showAsMuted (BuildContext context, PerAccountStore store) {
1893
1890
final message = this .message;
@@ -1908,8 +1905,7 @@ class SenderRow extends StatelessWidget {
1908
1905
final designVariables = DesignVariables .of (context);
1909
1906
1910
1907
final sender = store.getUser (message.senderId);
1911
- final time = _kMessageTimestampFormat
1912
- .format (DateTime .fromMillisecondsSinceEpoch (1000 * message.timestamp));
1908
+ final timestamp = timestampStyle.format (message.timestamp);
1913
1909
1914
1910
final showAsMuted = _showAsMuted (context, store);
1915
1911
@@ -1955,9 +1951,9 @@ class SenderRow extends StatelessWidget {
1955
1951
),
1956
1952
],
1957
1953
]))),
1958
- if (showTimestamp ) ...[
1954
+ if (timestamp != null ) ...[
1959
1955
const SizedBox (width: 4 ),
1960
- Text (time ,
1956
+ Text (timestamp ,
1961
1957
style: TextStyle (
1962
1958
color: messageListTheme.labelTime,
1963
1959
fontSize: 16 ,
@@ -1969,6 +1965,27 @@ class SenderRow extends StatelessWidget {
1969
1965
}
1970
1966
}
1971
1967
1968
+ // TODO centralize on this for wherever we show message timestamps
1969
+ enum MessageTimestampStyle {
1970
+ none,
1971
+ timeOnly,
1972
+ ;
1973
+
1974
+ static final _timeOnlyFormat = DateFormat ('h:mm aa' , 'en_US' );
1975
+
1976
+ /// Format a [Message.timestamp] for this mode.
1977
+ // TODO(i18n): locale-specific formatting (see #45 for a plan with ffi)
1978
+ String ? format (int messageTimestamp) {
1979
+ final asDateTime =
1980
+ DateTime .fromMillisecondsSinceEpoch (1000 * messageTimestamp);
1981
+
1982
+ switch (this ) {
1983
+ case none: return null ;
1984
+ case timeOnly: return _timeOnlyFormat.format (asDateTime);
1985
+ }
1986
+ }
1987
+ }
1988
+
1972
1989
/// A Zulip message, showing the sender's name and avatar if specified.
1973
1990
// Design referenced from:
1974
1991
// - https://github.com/zulip/zulip-mobile/issues/5511
@@ -2059,7 +2076,8 @@ class MessageWithPossibleSender extends StatelessWidget {
2059
2076
padding: const EdgeInsets .only (top: 4 ),
2060
2077
child: Column (children: [
2061
2078
if (item.showSender)
2062
- SenderRow (message: message, showTimestamp: true ),
2079
+ SenderRow (message: message,
2080
+ timestampStyle: MessageTimestampStyle .timeOnly),
2063
2081
Row (
2064
2082
crossAxisAlignment: CrossAxisAlignment .baseline,
2065
2083
textBaseline: localizedTextBaseline (context),
@@ -2222,7 +2240,7 @@ class OutboxMessageWithPossibleSender extends StatelessWidget {
2222
2240
padding: const EdgeInsets .only (top: 4 ),
2223
2241
child: Column (children: [
2224
2242
if (item.showSender)
2225
- SenderRow (message: message, showTimestamp : false ),
2243
+ SenderRow (message: message, timestampStyle : MessageTimestampStyle .none ),
2226
2244
Padding (
2227
2245
padding: const EdgeInsets .symmetric (horizontal: 16 ),
2228
2246
child: Column (crossAxisAlignment: CrossAxisAlignment .stretch,
0 commit comments