Page MenuHomePhabricator

D7177.diff
No OneTemporary

D7177.diff

diff --git a/keyserver/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js
--- a/keyserver/src/creators/thread-creator.js
+++ b/keyserver/src/creators/thread-creator.js
@@ -7,8 +7,8 @@
import {
generatePendingThreadColor,
generateRandomColor,
- getThreadTypeParentRequirement,
-} from 'lib/shared/thread-utils.js';
+} from 'lib/shared/color-utils.js';
+import { getThreadTypeParentRequirement } from 'lib/shared/thread-utils.js';
import { hasMinCodeVersion } from 'lib/shared/version-utils.js';
import type { Shape } from 'lib/types/core.js';
import { messageTypes } from 'lib/types/message-types.js';
diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js
--- a/lib/shared/avatar-utils.js
+++ b/lib/shared/avatar-utils.js
@@ -2,7 +2,7 @@
import stringHash from 'string-hash';
-import { selectedThreadColors } from './thread-utils.js';
+import { selectedThreadColors } from './color-utils.js';
import type { ClientEmojiAvatar, ClientAvatar } from '../types/avatar-types.js';
const defaultAnonymousUserEmojiAvatar: ClientEmojiAvatar = {
diff --git a/lib/shared/color-utils.js b/lib/shared/color-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/color-utils.js
@@ -0,0 +1,47 @@
+// @flow
+
+import stringHash from 'string-hash';
+import tinycolor from 'tinycolor2';
+
+import { values } from '../utils/objects.js';
+
+function colorIsDark(color: string): boolean {
+ return tinycolor(`#${color}`).isDark();
+}
+
+const selectedThreadColorsObj = Object.freeze({
+ a: '4b87aa',
+ b: '5c9f5f',
+ c: 'b8753d',
+ d: 'aa4b4b',
+ e: '6d49ab',
+ f: 'c85000',
+ g: '008f83',
+ h: '648caa',
+ i: '57697f',
+ j: '575757',
+});
+
+const selectedThreadColors: $ReadOnlyArray<string> = values(
+ selectedThreadColorsObj,
+);
+export type SelectedThreadColors = $Values<typeof selectedThreadColorsObj>;
+
+function generateRandomColor(): string {
+ return selectedThreadColors[
+ Math.floor(Math.random() * selectedThreadColors.length)
+ ];
+}
+
+function generatePendingThreadColor(userIDs: $ReadOnlyArray<string>): string {
+ const ids = [...userIDs].sort().join('#');
+ const colorIdx = stringHash(ids) % selectedThreadColors.length;
+ return selectedThreadColors[colorIdx];
+}
+
+export {
+ colorIsDark,
+ generateRandomColor,
+ generatePendingThreadColor,
+ selectedThreadColors,
+};
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -3,9 +3,8 @@
import invariant from 'invariant';
import _find from 'lodash/fp/find.js';
import * as React from 'react';
-import stringHash from 'string-hash';
-import tinycolor from 'tinycolor2';
+import { generatePendingThreadColor } from './color-utils.js';
import { type ParserRules } from './markdown.js';
import { extractMentionsFromText } from './mention-utils.js';
import { getMessageTitle } from './message-utils.js';
@@ -88,7 +87,6 @@
getEntityTextAsString,
type ThreadEntity,
} from '../utils/entity-text.js';
-import { values } from '../utils/objects.js';
import { useSelector } from '../utils/redux-utils.js';
import { firstLine } from '../utils/string-utils.js';
import { trimText } from '../utils/text-utils.js';
@@ -99,40 +97,6 @@
const validChatNameRegexString = `^.${secondCharRange}$`;
const validChatNameRegex: RegExp = new RegExp(validChatNameRegexString);
-function colorIsDark(color: string): boolean {
- return tinycolor(`#${color}`).isDark();
-}
-
-const selectedThreadColorsObj = Object.freeze({
- a: '4b87aa',
- b: '5c9f5f',
- c: 'b8753d',
- d: 'aa4b4b',
- e: '6d49ab',
- f: 'c85000',
- g: '008f83',
- h: '648caa',
- i: '57697f',
- j: '575757',
-});
-
-const selectedThreadColors: $ReadOnlyArray<string> = values(
- selectedThreadColorsObj,
-);
-export type SelectedThreadColors = $Values<typeof selectedThreadColorsObj>;
-
-function generateRandomColor(): string {
- return selectedThreadColors[
- Math.floor(Math.random() * selectedThreadColors.length)
- ];
-}
-
-function generatePendingThreadColor(userIDs: $ReadOnlyArray<string>): string {
- const ids = [...userIDs].sort().join('#');
- const colorIdx = stringHash(ids) % selectedThreadColors.length;
- return selectedThreadColors[colorIdx];
-}
-
function threadHasPermission(
threadInfo: ?(ThreadInfo | RawThreadInfo),
permission: ThreadPermission,
@@ -1582,9 +1546,6 @@
}
export {
- colorIsDark,
- generateRandomColor,
- generatePendingThreadColor,
threadHasPermission,
viewerIsMember,
threadInChatList,
@@ -1646,7 +1607,6 @@
removeMemberFromThread,
switchMemberAdminRoleInThread,
getAvailableThreadMemberActions,
- selectedThreadColors,
threadMembersWithoutAddedAshoat,
validChatNameRegex,
chatNameMaxLength,
diff --git a/native/calendar/entry.react.js b/native/calendar/entry.react.js
--- a/native/calendar/entry.react.js
+++ b/native/calendar/entry.react.js
@@ -29,8 +29,9 @@
concurrentModificationResetActionType,
} from 'lib/actions/entry-actions.js';
import { registerFetchKey } from 'lib/reducers/loading-reducer.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import { entryKey } from 'lib/shared/entry-utils.js';
-import { colorIsDark, threadHasPermission } from 'lib/shared/thread-utils.js';
+import { threadHasPermission } from 'lib/shared/thread-utils.js';
import type { Shape } from 'lib/types/core.js';
import type {
CreateEntryInfo,
diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js
--- a/native/chat/chat-input-bar.react.js
+++ b/native/chat/chat-input-bar.react.js
@@ -30,6 +30,7 @@
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
import { userStoreSearchIndex } from 'lib/selectors/user-selectors.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import {
getTypeaheadUserSuggestions,
getTypeaheadRegexMatches,
@@ -45,7 +46,6 @@
threadActualMembers,
checkIfDefaultMembersAreVoiced,
draftKeyFromThreadID,
- colorIsDark,
} from 'lib/shared/thread-utils.js';
import type { CalendarQuery } from 'lib/types/entry-types.js';
import type { LoadingStatus } from 'lib/types/loading-types.js';
diff --git a/native/chat/inner-text-message.react.js b/native/chat/inner-text-message.react.js
--- a/native/chat/inner-text-message.react.js
+++ b/native/chat/inner-text-message.react.js
@@ -4,7 +4,7 @@
import { View, StyleSheet, TouchableWithoutFeedback } from 'react-native';
import Animated from 'react-native-reanimated';
-import { colorIsDark } from 'lib/shared/thread-utils.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import { useComposedMessageMaxWidth } from './composed-message-width.js';
import { useTextMessageMarkdownRules } from './message-list-types.js';
diff --git a/native/chat/utils.js b/native/chat/utils.js
--- a/native/chat/utils.js
+++ b/native/chat/utils.js
@@ -7,8 +7,9 @@
import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js';
import { useMessageListData } from 'lib/selectors/chat-selectors.js';
import type { ChatMessageItem } from 'lib/selectors/chat-selectors.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import { messageKey } from 'lib/shared/message-utils.js';
-import { colorIsDark, viewerIsMember } from 'lib/shared/thread-utils.js';
+import { viewerIsMember } from 'lib/shared/thread-utils.js';
import type { ThreadInfo } from 'lib/types/thread-types.js';
import { clusterEndHeight, inlineEngagementStyle } from './chat-constants.js';
diff --git a/native/components/color-selector.react.js b/native/components/color-selector.react.js
--- a/native/components/color-selector.react.js
+++ b/native/components/color-selector.react.js
@@ -4,7 +4,7 @@
import { Text, TouchableOpacity, View } from 'react-native';
import tinycolor from 'tinycolor2';
-import { selectedThreadColors } from 'lib/shared/thread-utils.js';
+import { selectedThreadColors } from 'lib/shared/color-utils.js';
import ColorSelectorButton from './color-selector-button.react.js';
import { useStyles } from '../themes/colors.js';
diff --git a/web/calendar/entry.react.js b/web/calendar/entry.react.js
--- a/web/calendar/entry.react.js
+++ b/web/calendar/entry.react.js
@@ -19,8 +19,9 @@
type PushModal,
} from 'lib/components/modal-provider.react.js';
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import { entryKey } from 'lib/shared/entry-utils.js';
-import { colorIsDark, threadHasPermission } from 'lib/shared/thread-utils.js';
+import { threadHasPermission } from 'lib/shared/thread-utils.js';
import type { Shape } from 'lib/types/core.js';
import {
type EntryInfo,
diff --git a/web/chat/text-message.react.js b/web/chat/text-message.react.js
--- a/web/chat/text-message.react.js
+++ b/web/chat/text-message.react.js
@@ -5,8 +5,8 @@
import * as React from 'react';
import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import { onlyEmojiRegex } from 'lib/shared/emojis.js';
-import { colorIsDark } from 'lib/shared/thread-utils.js';
import { messageTypes } from 'lib/types/message-types.js';
import { type ThreadInfo } from 'lib/types/thread-types.js';
diff --git a/web/modals/history/history-entry.react.js b/web/modals/history/history-entry.react.js
--- a/web/modals/history/history-entry.react.js
+++ b/web/modals/history/history-entry.react.js
@@ -11,7 +11,7 @@
import { useENSNames } from 'lib/hooks/ens-cache.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
-import { colorIsDark } from 'lib/shared/thread-utils.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import {
type EntryInfo,
type RestoreEntryInfo,
diff --git a/web/modals/history/history-revision.react.js b/web/modals/history/history-revision.react.js
--- a/web/modals/history/history-revision.react.js
+++ b/web/modals/history/history-revision.react.js
@@ -7,7 +7,7 @@
import { useENSNames } from 'lib/hooks/ens-cache.js';
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
-import { colorIsDark } from 'lib/shared/thread-utils.js';
+import { colorIsDark } from 'lib/shared/color-utils.js';
import type { HistoryRevisionInfo } from 'lib/types/history-types.js';
import css from './history.css';
diff --git a/web/modals/threads/color-selector.react.js b/web/modals/threads/color-selector.react.js
--- a/web/modals/threads/color-selector.react.js
+++ b/web/modals/threads/color-selector.react.js
@@ -2,7 +2,7 @@
import * as React from 'react';
-import { selectedThreadColors } from 'lib/shared/thread-utils.js';
+import { selectedThreadColors } from 'lib/shared/color-utils.js';
import ColorSelectorButton from './color-selector-button.react.js';
import css from './color-selector.css';

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 2:43 AM (22 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2582159
Default Alt Text
D7177.diff (10 KB)

Event Timeline