From 736075322cf5401d2e91783df0f494b7cd9ab6c8 Mon Sep 17 00:00:00 2001
From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
Date: Mon, 3 May 2021 18:24:40 -0500
Subject: [PATCH] Render disappearing message timers generically
---
ACKNOWLEDGMENTS.md | 27 +++
_locales/en/messages.json | 94 +----------
package.json | 2 +
.../conversation/ConversationHeader.tsx | 34 ++--
.../TimerNotification.stories.tsx | 30 ++--
.../conversation/TimerNotification.tsx | 158 +++++++++---------
.../ConversationDetails.tsx | 29 ++--
ts/models/messages.ts | 12 +-
ts/state/ducks/user.ts | 11 +-
ts/test-both/util/expirationTimer_test.ts | 132 +++++++++++++++
.../quill/mentions/completion_test.tsx | 2 +-
ts/types/Util.ts | 8 +-
ts/util/ExpirationTimerOptions.ts | 77 ---------
ts/util/expirationTimer.ts | 49 ++++++
ts/util/lint/exceptions.json | 4 +-
yarn.lock | 10 ++
16 files changed, 372 insertions(+), 307 deletions(-)
create mode 100644 ts/test-both/util/expirationTimer_test.ts
delete mode 100644 ts/util/ExpirationTimerOptions.ts
create mode 100644 ts/util/expirationTimer.ts
diff --git a/ACKNOWLEDGMENTS.md b/ACKNOWLEDGMENTS.md
index 752bfe2d21..35102f518e 100644
--- a/ACKNOWLEDGMENTS.md
+++ b/ACKNOWLEDGMENTS.md
@@ -1538,6 +1538,33 @@ Signal Desktop makes use of the following open source projects.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+## humanize-duration
+
+ This is free and unencumbered software released into the public domain.
+
+ Anyone is free to copy, modify, publish, use, compile, sell, or
+ distribute this software, either in source code form or as a compiled
+ binary, for any purpose, commercial or non-commercial, and by any
+ means.
+
+ In jurisdictions that recognize copyright laws, the author or authors
+ of this software dedicate any and all copyright interest in the
+ software to the public domain. We make this dedication for the benefit
+ of the public at large and to the detriment of our heirs and
+ successors. We intend this dedication to be an overt act of
+ relinquishment in perpetuity of all present and future rights to this
+ software under copyright law.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ For more information, please refer to
+
## intl-tel-input
The MIT License (MIT)
diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index f0446ceb6a..ec5eb8b1a7 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -1657,106 +1657,14 @@
}
}
},
- "timerOption_0_seconds": {
+ "disappearingMessages__off": {
"message": "off",
"description": "Label for option to turn off message expiration in the timer menu"
},
- "timerOption_5_seconds": {
- "message": "5 seconds",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_10_seconds": {
- "message": "10 seconds",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_30_seconds": {
- "message": "30 seconds",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_1_minute": {
- "message": "1 minute",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_5_minutes": {
- "message": "5 minutes",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_30_minutes": {
- "message": "30 minutes",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_1_hour": {
- "message": "1 hour",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_6_hours": {
- "message": "6 hours",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_12_hours": {
- "message": "12 hours",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_1_day": {
- "message": "1 day",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
- "timerOption_1_week": {
- "message": "1 week",
- "description": "Label for a selectable option in the message expiration timer menu"
- },
"disappearingMessages": {
"message": "Disappearing messages",
"description": "Conversation menu option to enable disappearing messages"
},
- "timerOption_0_seconds_abbreviated": {
- "message": "off",
- "description": "Short format indicating current timer setting in the conversation list snippet"
- },
- "timerOption_5_seconds_abbreviated": {
- "message": "5s",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_10_seconds_abbreviated": {
- "message": "10s",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_30_seconds_abbreviated": {
- "message": "30s",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_1_minute_abbreviated": {
- "message": "1m",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_5_minutes_abbreviated": {
- "message": "5m",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_30_minutes_abbreviated": {
- "message": "30m",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_1_hour_abbreviated": {
- "message": "1h",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_6_hours_abbreviated": {
- "message": "6h",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_12_hours_abbreviated": {
- "message": "12h",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_1_day_abbreviated": {
- "message": "1d",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
- "timerOption_1_week_abbreviated": {
- "message": "1w",
- "description": "Very short format indicating current timer setting in the conversation header"
- },
"disappearingMessagesDisabled": {
"message": "Disappearing messages disabled",
"description": "Displayed in the left pane when the timer is turned off"
diff --git a/package.json b/package.json
index 90370c16d3..24efc399cb 100644
--- a/package.json
+++ b/package.json
@@ -97,6 +97,7 @@
"google-libphonenumber": "3.2.17",
"got": "8.3.2",
"history": "4.9.0",
+ "humanize-duration": "3.26.0",
"intl-tel-input": "12.1.15",
"jquery": "3.5.0",
"js-yaml": "3.13.1",
@@ -186,6 +187,7 @@
"@types/google-libphonenumber": "7.4.14",
"@types/got": "9.4.1",
"@types/history": "4.7.2",
+ "@types/humanize-duration": "^3.18.1",
"@types/jquery": "3.5.0",
"@types/js-yaml": "3.12.0",
"@types/linkify-it": "2.1.0",
diff --git a/ts/components/conversation/ConversationHeader.tsx b/ts/components/conversation/ConversationHeader.tsx
index e1605b36b7..f095d09468 100644
--- a/ts/components/conversation/ConversationHeader.tsx
+++ b/ts/components/conversation/ConversationHeader.tsx
@@ -19,10 +19,7 @@ import { InContactsIcon } from '../InContactsIcon';
import { LocalizerType } from '../../types/Util';
import { ConversationType } from '../../state/ducks/conversations';
import { MuteOption, getMuteOptions } from '../../util/getMuteOptions';
-import {
- ExpirationTimerOptions,
- TimerOption,
-} from '../../util/ExpirationTimerOptions';
+import * as expirationTimer from '../../util/expirationTimer';
import { isMuted } from '../../util/isMuted';
import { missingCaseError } from '../../util/missingCaseError';
@@ -219,16 +216,13 @@ export class ConversationHeader extends React.Component {
private renderExpirationLength(): ReactNode {
const { i18n, expireTimer } = this.props;
- const expirationSettingName = expireTimer
- ? ExpirationTimerOptions.getAbbreviated(i18n, expireTimer)
- : undefined;
- if (!expirationSettingName) {
+ if (!expireTimer) {
return null;
}
return (