Edit message: Don't allow send unless message contents changed

This commit is contained in:
Scott Nonnenberg 2024-07-16 19:16:57 -07:00 committed by GitHub
parent 5987350dbe
commit f53e956810
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 70 additions and 8 deletions

View file

@ -3,7 +3,7 @@
/* eslint-disable @typescript-eslint/no-namespace */
import { isNumber, omit, partition } from 'lodash';
import { isEqual, isNumber, omit, orderBy, partition } from 'lodash';
import { SignalService as Proto } from '../protobuf';
import * as log from '../logging/log';
@ -849,3 +849,27 @@ export function applyRangesToText(
return state;
}
// For ease of working with draft mentions in Quill, a conversationID field is present.
function normalizeBodyRanges(bodyRanges: DraftBodyRanges) {
return orderBy(bodyRanges, ['start', 'length']).map(item => {
if (BodyRange.isMention(item)) {
return { ...item, conversationID: undefined };
}
return item;
});
}
export function areBodyRangesEqual(
left: DraftBodyRanges,
right: DraftBodyRanges
): boolean {
const normalizedLeft = normalizeBodyRanges(left);
const sortedRight = normalizeBodyRanges(right);
if (normalizedLeft.length !== sortedRight.length) {
return false;
}
return isEqual(normalizedLeft, sortedRight);
}