2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-18 21:43:57 +00:00
|
|
|
import { BodyRangesType } from '../types/Util';
|
|
|
|
|
|
|
|
export function getTextWithMentions(
|
|
|
|
bodyRanges: BodyRangesType,
|
|
|
|
text: string
|
|
|
|
): string {
|
2020-11-03 01:19:52 +00:00
|
|
|
return bodyRanges
|
|
|
|
.sort((a, b) => b.start - a.start)
|
|
|
|
.reduce((acc, { start, length, replacementText }) => {
|
|
|
|
const left = acc.slice(0, start);
|
|
|
|
const right = acc.slice(start + length);
|
|
|
|
return `${left}@${replacementText}${right}`;
|
|
|
|
}, text);
|
2020-09-18 21:43:57 +00:00
|
|
|
}
|