Support for receiving formatted messages
Co-authored-by: Alvaro Carrasco <alvaro@signal.org>
This commit is contained in:
parent
d34d187f1e
commit
d9d820e72a
72 changed files with 3421 additions and 858 deletions
|
@ -14,11 +14,8 @@ import { MentionCompletion } from '../quill/mentions/completion';
|
|||
import { EmojiBlot, EmojiCompletion } from '../quill/emoji';
|
||||
import type { EmojiPickDataType } from './emoji/EmojiPicker';
|
||||
import { convertShortName } from './emoji/lib';
|
||||
import type {
|
||||
LocalizerType,
|
||||
DraftBodyRangesType,
|
||||
ThemeType,
|
||||
} from '../types/Util';
|
||||
import type { DraftBodyRangeMention } from '../types/BodyRange';
|
||||
import type { LocalizerType, ThemeType } from '../types/Util';
|
||||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
|
||||
import { isValidUuid } from '../types/UUID';
|
||||
|
@ -64,7 +61,7 @@ export type InputApi = {
|
|||
insertEmoji: (e: EmojiPickDataType) => void;
|
||||
setContents: (
|
||||
text: string,
|
||||
draftBodyRanges?: DraftBodyRangesType,
|
||||
draftBodyRanges?: ReadonlyArray<DraftBodyRangeMention>,
|
||||
cursorToEnd?: boolean
|
||||
) => void;
|
||||
reset: () => void;
|
||||
|
@ -82,7 +79,7 @@ export type Props = Readonly<{
|
|||
sendCounter: number;
|
||||
skinTone?: EmojiPickDataType['skinTone'];
|
||||
draftText?: string;
|
||||
draftBodyRanges?: DraftBodyRangesType;
|
||||
draftBodyRanges?: ReadonlyArray<DraftBodyRangeMention>;
|
||||
moduleClassName?: string;
|
||||
theme: ThemeType;
|
||||
placeholder?: string;
|
||||
|
@ -90,7 +87,7 @@ export type Props = Readonly<{
|
|||
scrollerRef?: React.RefObject<HTMLDivElement>;
|
||||
onDirtyChange?(dirty: boolean): unknown;
|
||||
onEditorStateChange?(options: {
|
||||
bodyRanges: DraftBodyRangesType;
|
||||
bodyRanges: ReadonlyArray<DraftBodyRangeMention>;
|
||||
caretLocation?: number;
|
||||
conversationId: string | undefined;
|
||||
messageText: string;
|
||||
|
@ -100,7 +97,7 @@ export type Props = Readonly<{
|
|||
onPickEmoji(o: EmojiPickDataType): unknown;
|
||||
onSubmit(
|
||||
message: string,
|
||||
mentions: DraftBodyRangesType,
|
||||
mentions: ReadonlyArray<DraftBodyRangeMention>,
|
||||
timestamp: number
|
||||
): unknown;
|
||||
onScroll?: (ev: React.UIEvent<HTMLElement>) => void;
|
||||
|
@ -164,16 +161,19 @@ export function CompositionInput(props: Props): React.ReactElement {
|
|||
|
||||
const generateDelta = (
|
||||
text: string,
|
||||
bodyRanges: DraftBodyRangesType
|
||||
mentions: ReadonlyArray<DraftBodyRangeMention>
|
||||
): Delta => {
|
||||
const initialOps = [{ insert: text }];
|
||||
const opsWithMentions = insertMentionOps(initialOps, bodyRanges);
|
||||
const opsWithMentions = insertMentionOps(initialOps, mentions);
|
||||
const opsWithEmojis = insertEmojiOps(opsWithMentions);
|
||||
|
||||
return new Delta(opsWithEmojis);
|
||||
};
|
||||
|
||||
const getTextAndMentions = (): [string, DraftBodyRangesType] => {
|
||||
const getTextAndMentions = (): [
|
||||
string,
|
||||
ReadonlyArray<DraftBodyRangeMention>
|
||||
] => {
|
||||
const quill = quillRef.current;
|
||||
|
||||
if (quill === undefined) {
|
||||
|
@ -251,7 +251,7 @@ export function CompositionInput(props: Props): React.ReactElement {
|
|||
|
||||
const setContents = (
|
||||
text: string,
|
||||
bodyRanges?: DraftBodyRangesType,
|
||||
mentions?: ReadonlyArray<DraftBodyRangeMention>,
|
||||
cursorToEnd?: boolean
|
||||
) => {
|
||||
const quill = quillRef.current;
|
||||
|
@ -260,7 +260,7 @@ export function CompositionInput(props: Props): React.ReactElement {
|
|||
return;
|
||||
}
|
||||
|
||||
const delta = generateDelta(text || '', bodyRanges || []);
|
||||
const delta = generateDelta(text || '', mentions || []);
|
||||
|
||||
canSendRef.current = true;
|
||||
// We need to cast here because we use @types/quill@1.3.10 which has types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue