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

@ -2,7 +2,7 @@
// 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
import { OutgoingContentMessage } from '../messages/outgoing';
import { SessionResetMessage } from '../messages/outgoing';
export function hasSession(device: string): boolean {
return false; // TODO: Implement
@ -25,9 +25,8 @@ export async function sendSessionRequestIfNeeded(
return Promise.reject(new Error('Need to implement this function'));
}
// TODO: Replace OutgoingContentMessage with SessionReset
export async function sendSessionRequest(
message: OutgoingContentMessage
message: SessionResetMessage
): Promise<void> {
// TODO: Optimistically store timestamp of when session request was sent
// TODO: Send out the request via MessageSender

@ -3,7 +3,7 @@ import {
MessageQueueInterface,
MessageQueueInterfaceEvents,
} from './MessageQueueInterface';
import { OpenGroupMessage, OutgoingContentMessage } from '../messages/outgoing';
import { ContentMessage, OpenGroupMessage } from '../messages/outgoing';
import { PendingMessageCache } from './PendingMessageCache';
import { JobQueue, TypedEventEmitter } from '../utils';
@ -18,16 +18,16 @@ export class MessageQueue implements MessageQueueInterface {
this.processAllPending();
}
public sendUsingMultiDevice(user: string, message: OutgoingContentMessage) {
public sendUsingMultiDevice(user: string, message: ContentMessage) {
throw new Error('Method not implemented.');
}
public send(device: string, message: OutgoingContentMessage) {
public send(device: string, message: ContentMessage) {
throw new Error('Method not implemented.');
}
public sendToGroup(message: OutgoingContentMessage | OpenGroupMessage) {
public sendToGroup(message: ContentMessage | OpenGroupMessage) {
throw new Error('Method not implemented.');
}
public sendSyncMessage(message: OutgoingContentMessage) {
public sendSyncMessage(message: ContentMessage) {
throw new Error('Method not implemented.');
}
@ -39,7 +39,7 @@ export class MessageQueue implements MessageQueueInterface {
// TODO: Get all devices which are pending here
}
private queue(device: string, message: OutgoingContentMessage) {
private queue(device: string, message: ContentMessage) {
// 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 { TypedEventEmitter } from '../utils';
// TODO: add all group messages here, replace OutgoingContentMessage with them
type GroupMessageType = OpenGroupMessage | OutgoingContentMessage;
type GroupMessageType = OpenGroupMessage | ClosedGroupMessage;
export interface MessageQueueInterfaceEvents {
success: (message: RawMessage) => void;
@ -12,8 +15,8 @@ export interface MessageQueueInterfaceEvents {
export interface MessageQueueInterface {
events: TypedEventEmitter<MessageQueueInterfaceEvents>;
sendUsingMultiDevice(user: string, message: OutgoingContentMessage): void;
send(device: string, message: OutgoingContentMessage): void;
sendUsingMultiDevice(user: string, message: ContentMessage): void;
send(device: string, message: ContentMessage): void;
sendToGroup(message: GroupMessageType): void;
sendSyncMessage(message: OutgoingContentMessage): void;
sendSyncMessage(message: ContentMessage): void;
}

@ -1,5 +1,5 @@
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
@ -12,7 +12,7 @@ export class PendingMessageCache {
public addPendingMessage(
device: string,
message: OutgoingContentMessage
message: ContentMessage
): 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?

Loading…
Cancel
Save