fixup-review
This commit is contained in:
parent
35665f3cb6
commit
8417e3660d
|
@ -1,6 +1,4 @@
|
|||
import * as _ from 'lodash';
|
||||
import { getPairedDevicesFor } from '../../../js/modules/data';
|
||||
import { ConversationController } from '../../window';
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import {
|
||||
|
@ -14,11 +12,16 @@ import {
|
|||
SessionRequestMessage,
|
||||
} from '../messages/outgoing';
|
||||
import { PendingMessageCache } from './PendingMessageCache';
|
||||
import { JobQueue, SyncMessageUtils, TypedEventEmitter, GroupUtils } from '../utils';
|
||||
import {
|
||||
GroupUtils,
|
||||
JobQueue,
|
||||
SyncMessageUtils,
|
||||
TypedEventEmitter,
|
||||
} from '../utils';
|
||||
import { PubKey } from '../types';
|
||||
import { MessageSender } from '.';
|
||||
import { SessionProtocol } from '../protocols';
|
||||
import * as UserUtils from '../../util/user';
|
||||
import { UserUtil } from '../../util';
|
||||
|
||||
export class MessageQueue implements MessageQueueInterface {
|
||||
public readonly events: TypedEventEmitter<MessageQueueInterfaceEvents>;
|
||||
|
@ -50,7 +53,7 @@ export class MessageQueue implements MessageQueueInterface {
|
|||
|
||||
// Sync to our devices if syncable
|
||||
if (SyncMessageUtils.canSync(message)) {
|
||||
const currentDevice = await UserUtils.getCurrentDevicePubKey();
|
||||
const currentDevice = await UserUtil.getCurrentDevicePubKey();
|
||||
|
||||
if (currentDevice) {
|
||||
const otherDevices = await getPairedDevicesFor(currentDevice);
|
||||
|
@ -61,10 +64,9 @@ export class MessageQueue implements MessageQueueInterface {
|
|||
await this.sendSyncMessage(message, ourDevices);
|
||||
|
||||
// Remove our devices from currentDevices
|
||||
const ourDeviceContacts = ourDevices.map(device =>
|
||||
ConversationController.get(device.key)
|
||||
currentDevices = currentDevices.filter(device =>
|
||||
ourDevices.some(d => PubKey.isEqual(d, device))
|
||||
);
|
||||
currentDevices = _.xor(currentDevices, ourDeviceContacts);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,12 +90,12 @@ export class MessageQueue implements MessageQueueInterface {
|
|||
// Closed groups
|
||||
if (message instanceof ClosedGroupMessage) {
|
||||
// Get devices in closed group
|
||||
const conversation = ConversationController.get(message.groupId);
|
||||
const recipientsModels = conversation.contactCollection.models;
|
||||
const recipients: Array<PubKey> = recipientsModels.map(
|
||||
(recipient: any) => new PubKey(recipient.id)
|
||||
);
|
||||
const groupPubKey = PubKey.from(message.groupId);
|
||||
if (!groupPubKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const recipients = await GroupUtils.getGroupMembers(groupPubKey);
|
||||
await this.sendMessageToDevices(recipients, message);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -26,4 +26,8 @@ export class PubKey {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static isEqual(key: PubKey, comparator: PubKey) {
|
||||
return key.key === comparator.key;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { ConversationController } from '../../window';
|
||||
import { PubKey } from '../types';
|
||||
|
||||
|
||||
export async function getGroupMembers(groupId: PubKey): Promise<Array<PubKey>> {
|
||||
const groupConversation = ConversationController.get(groupId.key);
|
||||
const groupMembers = groupConversation.attributes.members;
|
||||
const groupMembers = groupConversation
|
||||
? groupConversation.attributes.members
|
||||
: undefined;
|
||||
|
||||
if (!groupMembers) {
|
||||
return [];
|
||||
|
|
|
@ -67,4 +67,3 @@ export function generateChatMessage(): ChatMessage {
|
|||
preview: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue