fixup-review

pull/1175/head
Vincent 5 years ago
parent 35665f3cb6
commit 8417e3660d

@ -1,6 +1,4 @@
import * as _ from 'lodash';
import { getPairedDevicesFor } from '../../../js/modules/data'; import { getPairedDevicesFor } from '../../../js/modules/data';
import { ConversationController } from '../../window';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { import {
@ -14,11 +12,16 @@ import {
SessionRequestMessage, SessionRequestMessage,
} from '../messages/outgoing'; } from '../messages/outgoing';
import { PendingMessageCache } from './PendingMessageCache'; import { PendingMessageCache } from './PendingMessageCache';
import { JobQueue, SyncMessageUtils, TypedEventEmitter, GroupUtils } from '../utils'; import {
GroupUtils,
JobQueue,
SyncMessageUtils,
TypedEventEmitter,
} from '../utils';
import { PubKey } from '../types'; import { PubKey } from '../types';
import { MessageSender } from '.'; import { MessageSender } from '.';
import { SessionProtocol } from '../protocols'; import { SessionProtocol } from '../protocols';
import * as UserUtils from '../../util/user'; import { UserUtil } from '../../util';
export class MessageQueue implements MessageQueueInterface { export class MessageQueue implements MessageQueueInterface {
public readonly events: TypedEventEmitter<MessageQueueInterfaceEvents>; public readonly events: TypedEventEmitter<MessageQueueInterfaceEvents>;
@ -50,7 +53,7 @@ export class MessageQueue implements MessageQueueInterface {
// Sync to our devices if syncable // Sync to our devices if syncable
if (SyncMessageUtils.canSync(message)) { if (SyncMessageUtils.canSync(message)) {
const currentDevice = await UserUtils.getCurrentDevicePubKey(); const currentDevice = await UserUtil.getCurrentDevicePubKey();
if (currentDevice) { if (currentDevice) {
const otherDevices = await getPairedDevicesFor(currentDevice); const otherDevices = await getPairedDevicesFor(currentDevice);
@ -61,10 +64,9 @@ export class MessageQueue implements MessageQueueInterface {
await this.sendSyncMessage(message, ourDevices); await this.sendSyncMessage(message, ourDevices);
// Remove our devices from currentDevices // Remove our devices from currentDevices
const ourDeviceContacts = ourDevices.map(device => currentDevices = currentDevices.filter(device =>
ConversationController.get(device.key) ourDevices.some(d => PubKey.isEqual(d, device))
); );
currentDevices = _.xor(currentDevices, ourDeviceContacts);
} }
} }
@ -88,12 +90,12 @@ export class MessageQueue implements MessageQueueInterface {
// Closed groups // Closed groups
if (message instanceof ClosedGroupMessage) { if (message instanceof ClosedGroupMessage) {
// Get devices in closed group // Get devices in closed group
const conversation = ConversationController.get(message.groupId); const groupPubKey = PubKey.from(message.groupId);
const recipientsModels = conversation.contactCollection.models; if (!groupPubKey) {
const recipients: Array<PubKey> = recipientsModels.map( return false;
(recipient: any) => new PubKey(recipient.id) }
);
const recipients = await GroupUtils.getGroupMembers(groupPubKey);
await this.sendMessageToDevices(recipients, message); await this.sendMessageToDevices(recipients, message);
return true; return true;

@ -26,4 +26,8 @@ export class PubKey {
return false; return false;
} }
public static isEqual(key: PubKey, comparator: PubKey) {
return key.key === comparator.key;
}
} }

@ -1,10 +1,11 @@
import { ConversationController } from '../../window'; import { ConversationController } from '../../window';
import { PubKey } from '../types'; import { PubKey } from '../types';
export async function getGroupMembers(groupId: PubKey): Promise<Array<PubKey>> { export async function getGroupMembers(groupId: PubKey): Promise<Array<PubKey>> {
const groupConversation = ConversationController.get(groupId.key); const groupConversation = ConversationController.get(groupId.key);
const groupMembers = groupConversation.attributes.members; const groupMembers = groupConversation
? groupConversation.attributes.members
: undefined;
if (!groupMembers) { if (!groupMembers) {
return []; return [];

@ -67,4 +67,3 @@ export function generateChatMessage(): ChatMessage {
preview: undefined, preview: undefined,
}); });
} }

Loading…
Cancel
Save