OpChan/src/types/waku.ts

90 lines
1.8 KiB
TypeScript
Raw Normal View History

/**
* Message types for Waku communication
*/
export enum MessageType {
CELL = 'cell',
POST = 'post',
COMMENT = 'comment',
VOTE = 'vote',
MODERATE = 'moderate',
}
/**
* Base interface for all message types
*/
export interface BaseMessage {
2025-08-29 16:16:20 +05:30
id: string;
type: MessageType;
2025-08-29 15:29:20 +05:30
timestamp: number | Date;
author: string;
signature?: string; // Message signature for verification
browserPubKey?: string; // Public key that signed the message
}
/**
* Represents a cell message
*/
export interface CellMessage extends BaseMessage {
type: MessageType.CELL;
name: string;
description: string;
icon?: string;
}
/**
* Represents a post message
*/
export interface PostMessage extends BaseMessage {
type: MessageType.POST;
cellId: string;
title: string;
content: string;
}
/**
* Represents a comment message
*/
export interface CommentMessage extends BaseMessage {
type: MessageType.COMMENT;
postId: string;
content: string;
}
/**
* Represents a vote message
*/
export interface VoteMessage extends BaseMessage {
type: MessageType.VOTE;
targetId: string; // ID of the post or comment being voted on
2025-04-16 14:45:27 +05:30
value: 1 | -1;
}
/**
* Represents a moderate message
*/
export interface ModerateMessage extends BaseMessage {
type: MessageType.MODERATE;
cellId: string;
targetType: 'post' | 'comment' | 'user';
targetId: string; // postId, commentId, or user address (for user moderation)
reason?: string;
}
/**
* Cache objects for storing messages
*/
export interface CellCache {
[cellId: string]: CellMessage;
}
export interface PostCache {
[postId: string]: PostMessage;
}
export interface CommentCache {
[commentId: string]: CommentMessage;
}
export interface VoteCache {
[key: string]: VoteMessage; // key = targetId + authorAddress
}