Fix imports.

Fix closed group messages.
pull/1160/head
Mikunj 5 years ago
parent 3ea0689d2f
commit d1bfcd340b

@ -1,7 +1,6 @@
import { DataMessage } from './DataMessage'; import { SignalService } from '../../../../../../protobuf';
import { SignalService } from '../../../../../protobuf'; import { ChatMessage } from '../ChatMessage';
import { ChatMessage } from './ChatMessage'; import { ClosedGroupMessage } from './ClosedGroupMessage';
import { TextEncoder } from 'util';
interface ClosedGroupChatMessageParams { interface ClosedGroupChatMessageParams {
identifier?: string; identifier?: string;
@ -9,16 +8,15 @@ interface ClosedGroupChatMessageParams {
chatMessage: ChatMessage; chatMessage: ChatMessage;
} }
export class ClosedGroupChatMessage extends DataMessage { export class ClosedGroupChatMessage extends ClosedGroupMessage {
private readonly groupId: string;
private readonly chatMessage: ChatMessage; private readonly chatMessage: ChatMessage;
constructor(params: ClosedGroupChatMessageParams) { constructor(params: ClosedGroupChatMessageParams) {
super({ super({
timestamp: params.chatMessage.timestamp, timestamp: params.chatMessage.timestamp,
identifier: params.identifier, identifier: params.identifier,
groupId: params.groupId,
}); });
this.groupId = params.groupId;
this.chatMessage = params.chatMessage; this.chatMessage = params.chatMessage;
} }
@ -26,11 +24,13 @@ export class ClosedGroupChatMessage extends DataMessage {
return this.getDefaultTTL(); return this.getDefaultTTL();
} }
protected groupContextType(): SignalService.GroupContext.Type {
return SignalService.GroupContext.Type.DELIVER;
}
protected dataProto(): SignalService.DataMessage { protected dataProto(): SignalService.DataMessage {
const messageProto = this.chatMessage.dataProto(); const messageProto = this.chatMessage.dataProto();
const id = new TextEncoder().encode(this.groupId); messageProto.group = this.groupContext();
const type = SignalService.GroupContext.Type.DELIVER;
messageProto.group = new SignalService.GroupContext({ id, type });
return messageProto; return messageProto;
} }

@ -0,0 +1,36 @@
import { DataMessage } from '../DataMessage';
import { SignalService } from '../../../../../../protobuf';
import { TextEncoder } from 'util';
import { MessageParams } from '../../../Message';
interface ClosedGroupMessageParams extends MessageParams {
groupId: string;
}
export abstract class ClosedGroupMessage extends DataMessage {
protected readonly groupId: string;
constructor(params: ClosedGroupMessageParams) {
super({
timestamp: params.timestamp,
identifier: params.identifier,
});
this.groupId = params.groupId;
}
protected abstract groupContextType(): SignalService.GroupContext.Type;
protected groupContext(): SignalService.GroupContext {
const id = new TextEncoder().encode(this.groupId);
const type = this.groupContextType();
return new SignalService.GroupContext({ id, type });
}
protected dataProto(): SignalService.DataMessage {
const dataMessage = new SignalService.DataMessage();
dataMessage.group = this.groupContext();
return dataMessage;
}
}

@ -0,0 +1,2 @@
export * from './ClosedGroupMessage';
export * from './ClosedGroupChatMessage';

@ -1,5 +1,5 @@
export * from './ClosedGroupChatMessage';
export * from './DataMessage'; export * from './DataMessage';
export * from './DeviceUnlinkMessage'; export * from './DeviceUnlinkMessage';
export * from './GroupInvitationMessage'; export * from './GroupInvitationMessage';
export * from './ChatMessage'; export * from './ChatMessage';
export * from './group';

@ -2,7 +2,7 @@
// Structure of this can be changed for example sticking this all in a class // Structure of this can be changed for example sticking this all in a class
// The reason i haven't done it is to avoid having instances of the protocol, rather you should be able to call the functions directly // The reason i haven't done it is to avoid having instances of the protocol, rather you should be able to call the functions directly
import { OutgoingContentMessage } from '../messages/outgoing'; import { SessionResetMessage } from '../messages/outgoing';
export function hasSession(device: string): boolean { export function hasSession(device: string): boolean {
return false; // TODO: Implement return false; // TODO: Implement
@ -25,9 +25,8 @@ export async function sendSessionRequestIfNeeded(
return Promise.reject(new Error('Need to implement this function')); return Promise.reject(new Error('Need to implement this function'));
} }
// TODO: Replace OutgoingContentMessage with SessionReset
export async function sendSessionRequest( export async function sendSessionRequest(
message: OutgoingContentMessage message: SessionResetMessage
): Promise<void> { ): Promise<void> {
// TODO: Optimistically store timestamp of when session request was sent // TODO: Optimistically store timestamp of when session request was sent
// TODO: Send out the request via MessageSender // TODO: Send out the request via MessageSender

@ -3,7 +3,7 @@ import {
MessageQueueInterface, MessageQueueInterface,
MessageQueueInterfaceEvents, MessageQueueInterfaceEvents,
} from './MessageQueueInterface'; } from './MessageQueueInterface';
import { OpenGroupMessage, OutgoingContentMessage } from '../messages/outgoing'; import { ContentMessage, OpenGroupMessage } from '../messages/outgoing';
import { PendingMessageCache } from './PendingMessageCache'; import { PendingMessageCache } from './PendingMessageCache';
import { JobQueue, TypedEventEmitter } from '../utils'; import { JobQueue, TypedEventEmitter } from '../utils';
@ -18,16 +18,16 @@ export class MessageQueue implements MessageQueueInterface {
this.processAllPending(); this.processAllPending();
} }
public sendUsingMultiDevice(user: string, message: OutgoingContentMessage) { public sendUsingMultiDevice(user: string, message: ContentMessage) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public send(device: string, message: OutgoingContentMessage) { public send(device: string, message: ContentMessage) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public sendToGroup(message: OutgoingContentMessage | OpenGroupMessage) { public sendToGroup(message: ContentMessage | OpenGroupMessage) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
public sendSyncMessage(message: OutgoingContentMessage) { public sendSyncMessage(message: ContentMessage) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@ -39,7 +39,7 @@ export class MessageQueue implements MessageQueueInterface {
// TODO: Get all devices which are pending here // TODO: Get all devices which are pending here
} }
private queue(device: string, message: OutgoingContentMessage) { private queue(device: string, message: ContentMessage) {
// TODO: implement // TODO: implement
} }

@ -1,9 +1,12 @@
import { OpenGroupMessage, OutgoingContentMessage } from '../messages/outgoing'; import {
ClosedGroupMessage,
ContentMessage,
OpenGroupMessage,
} from '../messages/outgoing';
import { RawMessage } from '../types/RawMessage'; import { RawMessage } from '../types/RawMessage';
import { TypedEventEmitter } from '../utils'; import { TypedEventEmitter } from '../utils';
// TODO: add all group messages here, replace OutgoingContentMessage with them type GroupMessageType = OpenGroupMessage | ClosedGroupMessage;
type GroupMessageType = OpenGroupMessage | OutgoingContentMessage;
export interface MessageQueueInterfaceEvents { export interface MessageQueueInterfaceEvents {
success: (message: RawMessage) => void; success: (message: RawMessage) => void;
@ -12,8 +15,8 @@ export interface MessageQueueInterfaceEvents {
export interface MessageQueueInterface { export interface MessageQueueInterface {
events: TypedEventEmitter<MessageQueueInterfaceEvents>; events: TypedEventEmitter<MessageQueueInterfaceEvents>;
sendUsingMultiDevice(user: string, message: OutgoingContentMessage): void; sendUsingMultiDevice(user: string, message: ContentMessage): void;
send(device: string, message: OutgoingContentMessage): void; send(device: string, message: ContentMessage): void;
sendToGroup(message: GroupMessageType): void; sendToGroup(message: GroupMessageType): void;
sendSyncMessage(message: OutgoingContentMessage): void; sendSyncMessage(message: ContentMessage): void;
} }

@ -1,5 +1,5 @@
import { RawMessage } from '../types/RawMessage'; import { RawMessage } from '../types/RawMessage';
import { OutgoingContentMessage } from '../messages/outgoing'; import { ContentMessage } from '../messages/outgoing';
// TODO: We should be able to import functions straight from the db here without going through the window object // TODO: We should be able to import functions straight from the db here without going through the window object
@ -12,7 +12,7 @@ export class PendingMessageCache {
public addPendingMessage( public addPendingMessage(
device: string, device: string,
message: OutgoingContentMessage message: ContentMessage
): RawMessage { ): RawMessage {
// TODO: Maybe have a util for converting OutgoingContentMessage to RawMessage? // TODO: Maybe have a util for converting OutgoingContentMessage to RawMessage?
// TODO: Raw message has uuid, how are we going to set that? maybe use a different identifier? // TODO: Raw message has uuid, how are we going to set that? maybe use a different identifier?

Loading…
Cancel
Save