Remove underscore
This commit is contained in:
parent
704107a256
commit
9d8ad21819
20 changed files with 111 additions and 226 deletions
|
@ -1,7 +1,15 @@
|
|||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { compact, has, isNumber, throttle, debounce } from 'lodash';
|
||||
import {
|
||||
compact,
|
||||
has,
|
||||
isNumber,
|
||||
throttle,
|
||||
debounce,
|
||||
head,
|
||||
sortBy,
|
||||
} from 'lodash';
|
||||
import { batch as batchDispatch } from 'react-redux';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
import PQueue from 'p-queue';
|
||||
|
@ -13,7 +21,6 @@ import type {
|
|||
MessageAttributesType,
|
||||
QuotedMessageType,
|
||||
SenderKeyInfoType,
|
||||
VerificationOptions,
|
||||
} from '../model-types.d';
|
||||
import { getInitials } from '../util/getInitials';
|
||||
import { normalizeUuid } from '../util/normalizeUuid';
|
||||
|
@ -468,7 +475,7 @@ export class ConversationModel extends window.Backbone
|
|||
return false;
|
||||
}
|
||||
|
||||
return window._.any(membersV2, item => item.uuid === uuid.toString());
|
||||
return membersV2.some(item => item.uuid === uuid.toString());
|
||||
}
|
||||
|
||||
async updateExpirationTimerInGroupV2(
|
||||
|
@ -1792,10 +1799,8 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
}
|
||||
|
||||
const typingValues = window._.values(this.contactTypingTimers || {});
|
||||
const typingMostRecent = window._.first(
|
||||
window._.sortBy(typingValues, 'timestamp')
|
||||
);
|
||||
const typingValues = Object.values(this.contactTypingTimers || {});
|
||||
const typingMostRecent = head(sortBy(typingValues, 'timestamp'));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const timestamp = this.get('timestamp')!;
|
||||
|
@ -2675,36 +2680,24 @@ export class ConversationModel extends window.Backbone
|
|||
);
|
||||
}
|
||||
|
||||
setVerifiedDefault(options?: VerificationOptions): Promise<boolean> {
|
||||
setVerifiedDefault(): Promise<boolean> {
|
||||
const { DEFAULT } = this.verifiedEnum;
|
||||
return this.queueJob('setVerifiedDefault', () =>
|
||||
this._setVerified(DEFAULT, options)
|
||||
this._setVerified(DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
setVerified(options?: VerificationOptions): Promise<boolean> {
|
||||
setVerified(): Promise<boolean> {
|
||||
const { VERIFIED } = this.verifiedEnum;
|
||||
return this.queueJob('setVerified', () =>
|
||||
this._setVerified(VERIFIED, options)
|
||||
);
|
||||
return this.queueJob('setVerified', () => this._setVerified(VERIFIED));
|
||||
}
|
||||
|
||||
setUnverified(options: VerificationOptions): Promise<boolean> {
|
||||
setUnverified(): Promise<boolean> {
|
||||
const { UNVERIFIED } = this.verifiedEnum;
|
||||
return this.queueJob('setUnverified', () =>
|
||||
this._setVerified(UNVERIFIED, options)
|
||||
);
|
||||
return this.queueJob('setUnverified', () => this._setVerified(UNVERIFIED));
|
||||
}
|
||||
|
||||
private async _setVerified(
|
||||
verified: number,
|
||||
providedOptions?: VerificationOptions
|
||||
): Promise<boolean> {
|
||||
const options = providedOptions || {};
|
||||
window._.defaults(options, {
|
||||
key: null,
|
||||
});
|
||||
|
||||
private async _setVerified(verified: number): Promise<boolean> {
|
||||
const { VERIFIED, DEFAULT } = this.verifiedEnum;
|
||||
|
||||
if (!isDirectConversation(this.attributes)) {
|
||||
|
@ -2886,13 +2879,13 @@ export class ConversationModel extends window.Backbone
|
|||
if (isDirectConversation(this.attributes)) {
|
||||
return this.safeIsUntrusted(timestampThreshold);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
if (!this.contactCollection!.length) {
|
||||
const { contactCollection } = this;
|
||||
|
||||
if (!contactCollection?.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return this.contactCollection!.any(contact => {
|
||||
return contactCollection.some(contact => {
|
||||
if (isMe(contact.attributes)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3166,7 +3159,7 @@ export class ConversationModel extends window.Backbone
|
|||
if (isDirectConversation(this.attributes) && uuid) {
|
||||
window.ConversationController.getAllGroupsInvolvingUuid(uuid).then(
|
||||
groups => {
|
||||
window._.forEach(groups, group => {
|
||||
groups.forEach(group => {
|
||||
group.addVerifiedChange(this.id, verified, options);
|
||||
});
|
||||
}
|
||||
|
@ -3303,7 +3296,7 @@ export class ConversationModel extends window.Backbone
|
|||
if (isDirectConversation(this.attributes) && uuid) {
|
||||
window.ConversationController.getAllGroupsInvolvingUuid(uuid).then(
|
||||
groups => {
|
||||
window._.forEach(groups, group => {
|
||||
groups.forEach(group => {
|
||||
group.addProfileChange(profileChange, this.id);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,14 +2,21 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import {
|
||||
groupBy,
|
||||
difference,
|
||||
isEmpty,
|
||||
isEqual,
|
||||
isNumber,
|
||||
isObject,
|
||||
mapValues,
|
||||
maxBy,
|
||||
noop,
|
||||
omit,
|
||||
partition,
|
||||
pick,
|
||||
reject,
|
||||
union,
|
||||
without,
|
||||
} from 'lodash';
|
||||
import type {
|
||||
CustomError,
|
||||
|
@ -262,8 +269,6 @@ type PropsForMessageDetail = Pick<
|
|||
| 'expirationTimestamp'
|
||||
>;
|
||||
|
||||
declare const _: typeof window._;
|
||||
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
const { Message: TypedMessage } = window.Signal.Types;
|
||||
|
@ -309,7 +314,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
cachedOutgoingStickerData?: StickerWithHydratedData;
|
||||
|
||||
override initialize(attributes: unknown): void {
|
||||
if (_.isObject(attributes)) {
|
||||
if (isObject(attributes)) {
|
||||
this.set(
|
||||
TypedMessage.initializeSchemaVersion({
|
||||
message: attributes as MessageAttributesType,
|
||||
|
@ -516,10 +521,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
// If an error has a specific number it's associated with, we'll show it next to
|
||||
// that contact. Otherwise, it will be a standalone entry.
|
||||
const errors = _.reject(allErrors, error =>
|
||||
const errors = reject(allErrors, error =>
|
||||
Boolean(error.identifier || error.number)
|
||||
);
|
||||
const errorsGroupedById = _.groupBy(allErrors, error => {
|
||||
const errorsGroupedById = groupBy(allErrors, error => {
|
||||
const identifier = error.identifier || error.number;
|
||||
if (!identifier) {
|
||||
return null;
|
||||
|
@ -747,7 +752,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
|
||||
if (groupUpdate.joined && groupUpdate.joined.length) {
|
||||
const joinedContacts = _.map(groupUpdate.joined, item =>
|
||||
const joinedContacts = groupUpdate.joined.map(item =>
|
||||
window.ConversationController.getOrCreate(item, 'private')
|
||||
);
|
||||
const joinedWithoutMe = joinedContacts.filter(
|
||||
|
@ -757,7 +762,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
if (joinedContacts.length > 1) {
|
||||
messages.push(
|
||||
window.i18n('multipleJoinedTheGroup', [
|
||||
_.map(joinedWithoutMe, contact => contact.getTitle()).join(', '),
|
||||
joinedWithoutMe.map(contact => contact.getTitle()).join(', '),
|
||||
])
|
||||
);
|
||||
|
||||
|
@ -1026,7 +1031,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
override validate(attributes: Record<string, unknown>): void {
|
||||
const required = ['conversationId', 'received_at', 'sent_at'];
|
||||
const missing = _.filter(required, attr => !attributes[attr]);
|
||||
const missing = required.filter(attr => !attributes[attr]);
|
||||
if (missing.length) {
|
||||
log.warn(`Message missing attributes: ${missing}`);
|
||||
}
|
||||
|
@ -1366,7 +1371,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
// We check instanceof second because typescript believes that anything that comes
|
||||
// through here must be an instance of Error, so e is 'never' after that check.
|
||||
if ((e.message && e.stack) || e instanceof Error) {
|
||||
return _.pick(
|
||||
return pick(
|
||||
e,
|
||||
'name',
|
||||
'message',
|
||||
|
@ -1523,7 +1528,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
removeOutgoingErrors(incomingIdentifier: string): CustomError {
|
||||
const incomingConversationId =
|
||||
window.ConversationController.getConversationId(incomingIdentifier);
|
||||
const errors = _.partition(
|
||||
const errors = partition(
|
||||
this.get('errors'),
|
||||
e =>
|
||||
window.ConversationController.getConversationId(
|
||||
|
@ -2386,12 +2391,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
});
|
||||
|
||||
const existingRevision = conversation.get('revision');
|
||||
const isFirstUpdate = !_.isNumber(existingRevision);
|
||||
const isFirstUpdate = !isNumber(existingRevision);
|
||||
|
||||
// Standard GroupV2 modification codepath
|
||||
const isV2GroupUpdate =
|
||||
initialMessage.groupV2 &&
|
||||
_.isNumber(initialMessage.groupV2.revision) &&
|
||||
isNumber(initialMessage.groupV2.revision) &&
|
||||
(isFirstUpdate ||
|
||||
initialMessage.groupV2.revision > existingRevision);
|
||||
|
||||
|
@ -2708,7 +2713,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
attributes = {
|
||||
...attributes,
|
||||
name: initialMessage.group.name,
|
||||
members: _.union(members, conversation.get('members')),
|
||||
members: union(members, conversation.get('members')),
|
||||
};
|
||||
|
||||
if (initialMessage.group.name !== conversation.get('name')) {
|
||||
|
@ -2776,14 +2781,14 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
}
|
||||
|
||||
const difference = _.difference(
|
||||
const differentMembers = difference(
|
||||
members,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
conversation.get('members')!
|
||||
);
|
||||
if (difference.length > 0) {
|
||||
if (differentMembers.length > 0) {
|
||||
// Because GroupV1 groups are based on e164 only
|
||||
const maybeE164s = map(difference, id =>
|
||||
const maybeE164s = map(differentMembers, id =>
|
||||
window.ConversationController.get(id)?.get('e164')
|
||||
);
|
||||
const e164s = filter(maybeE164s, isNotNil);
|
||||
|
@ -2813,7 +2818,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
} else {
|
||||
pendingGroupUpdate.left = sender.get('id');
|
||||
}
|
||||
attributes.members = _.without(
|
||||
attributes.members = without(
|
||||
conversation.get('members'),
|
||||
sender.get('id')
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue