mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { v4 as uuid } from 'uuid';
|
|
import type { OutgoingUserProfile } from '../../../types/message';
|
|
|
|
export type MessageParams = {
|
|
createAtNetworkTimestamp: number;
|
|
identifier?: string;
|
|
};
|
|
|
|
export type WithOutgoingUserProfile = { userProfile: OutgoingUserProfile | null };
|
|
|
|
export abstract class Message {
|
|
/**
|
|
* This is the network timestamp when this message was created (and so, potentially signed).
|
|
* This must be used as the envelope timestamp, as other devices are going to use it to verify messages.
|
|
* There is also the stored_at/effectiveTimestamp which we get back once we sent a message to the recipient's swarm, but that's not included here.
|
|
*/
|
|
public readonly createAtNetworkTimestamp: number;
|
|
public readonly identifier: string;
|
|
|
|
constructor({ createAtNetworkTimestamp, identifier }: MessageParams) {
|
|
this.createAtNetworkTimestamp = createAtNetworkTimestamp;
|
|
if (identifier && identifier.length === 0) {
|
|
throw new Error('Cannot set empty identifier');
|
|
}
|
|
|
|
if (!createAtNetworkTimestamp || createAtNetworkTimestamp <= 0) {
|
|
throw new Error('Cannot set undefined createAtNetworkTimestamp or <=0');
|
|
}
|
|
this.identifier = identifier || uuid();
|
|
}
|
|
}
|