| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2018 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  | import type { ReactElement } from 'react'; | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | import classNames from 'classnames'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 17:05:26 -06:00
										 |  |  | import { formatTime } from '../../util/timestamp'; | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { LocalizerType } from '../../types/Util'; | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  | import { Time } from '../Time'; | 
					
						
							| 
									
										
										
										
											2022-03-08 14:11:11 -05:00
										 |  |  | import { useNowThatUpdatesEveryMinute } from '../../hooks/useNowThatUpdatesEveryMinute'; | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | export type Props = { | 
					
						
							| 
									
										
										
										
											2022-04-07 09:58:15 -07:00
										 |  |  |   deletedForEveryone?: boolean; | 
					
						
							|  |  |  |   direction?: 'incoming' | 'outgoing'; | 
					
						
							|  |  |  |   i18n: LocalizerType; | 
					
						
							| 
									
										
										
										
											2022-05-06 15:02:44 -04:00
										 |  |  |   isRelativeTime?: boolean; | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  |   module?: string; | 
					
						
							| 
									
										
										
										
											2022-04-07 09:58:15 -07:00
										 |  |  |   timestamp: number; | 
					
						
							| 
									
										
										
										
											2018-07-17 20:25:55 -07:00
										 |  |  |   withImageNoCaption?: boolean; | 
					
						
							| 
									
										
										
										
											2019-05-16 15:32:11 -07:00
										 |  |  |   withSticker?: boolean; | 
					
						
							| 
									
										
										
										
											2019-06-26 12:33:13 -07:00
										 |  |  |   withTapToViewExpired?: boolean; | 
					
						
							| 
									
										
										
										
											2021-01-14 12:07:05 -06:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  | export function MessageTimestamp({ | 
					
						
							| 
									
										
										
										
											2022-04-07 09:58:15 -07:00
										 |  |  |   deletedForEveryone, | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  |   direction, | 
					
						
							|  |  |  |   i18n, | 
					
						
							| 
									
										
										
										
											2022-05-06 15:02:44 -04:00
										 |  |  |   isRelativeTime, | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  |   module, | 
					
						
							|  |  |  |   timestamp, | 
					
						
							|  |  |  |   withImageNoCaption, | 
					
						
							|  |  |  |   withSticker, | 
					
						
							|  |  |  |   withTapToViewExpired, | 
					
						
							| 
									
										
										
										
											2022-03-03 22:35:59 -06:00
										 |  |  | }: Readonly<Props>): ReactElement { | 
					
						
							| 
									
										
										
										
											2022-03-08 14:11:11 -05:00
										 |  |  |   const now = useNowThatUpdatesEveryMinute(); | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  |   const moduleName = module || 'module-timestamp'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Time | 
					
						
							|  |  |  |       className={classNames( | 
					
						
							|  |  |  |         moduleName, | 
					
						
							|  |  |  |         direction ? `${moduleName}--${direction}` : null, | 
					
						
							|  |  |  |         withTapToViewExpired && direction | 
					
						
							|  |  |  |           ? `${moduleName}--${direction}-with-tap-to-view-expired` | 
					
						
							|  |  |  |           : null, | 
					
						
							|  |  |  |         withImageNoCaption ? `${moduleName}--with-image-no-caption` : null, | 
					
						
							| 
									
										
										
										
											2022-04-07 09:58:15 -07:00
										 |  |  |         withSticker ? `${moduleName}--with-sticker` : null, | 
					
						
							|  |  |  |         deletedForEveryone ? `${moduleName}--deleted-for-everyone` : null | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  |       )} | 
					
						
							|  |  |  |       timestamp={timestamp} | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2022-05-06 15:02:44 -04:00
										 |  |  |       {formatTime(i18n, timestamp, now, isRelativeTime)} | 
					
						
							| 
									
										
										
										
											2022-03-03 14:23:10 -06:00
										 |  |  |     </Time> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2018-07-09 14:29:13 -07:00
										 |  |  | } |