chore: cleanup lib/forum

This commit is contained in:
Danish Arora 2025-08-28 17:11:47 +05:30
parent 88012154d3
commit 62d6800f0b
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
8 changed files with 116 additions and 120 deletions

View File

@ -1,8 +1,7 @@
import { RelevanceCalculator } from './relevance';
import { Post, Comment, Cell, User } from '@/types';
import { RelevanceCalculator } from '../relevance';
import { Post, Comment, User, UserVerificationStatus } from '@/types/forum';
import { VoteMessage, MessageType } from '@/lib/waku/types';
import { expect, describe, beforeEach, it } from 'vitest';
import { UserVerificationStatus } from './types';
describe('RelevanceCalculator', () => {
let calculator: RelevanceCalculator;

View File

@ -7,7 +7,7 @@ import {
VoteMessage,
ModerateMessage,
} from '@/lib/waku/types';
import { Cell, Comment, Post, User } from '@/types';
import { Cell, Comment, Post, User } from '@/types/forum';
import { transformCell, transformComment, transformPost } from './transformers';
import { MessageService } from '@/lib/identity/services/MessageService';
import { AuthService } from '@/lib/identity/services/AuthService';

View File

@ -1,6 +1,5 @@
import { Post, Comment, Cell, User } from '@/types';
import { Post, Comment, Cell, User, RelevanceScoreDetails, UserVerificationStatus } from '@/types/forum';
import { VoteMessage } from '@/lib/waku/types';
import { RelevanceScoreDetails, UserVerificationStatus } from './types';
export class RelevanceCalculator {
private static readonly BASE_SCORES = {

View File

@ -1,4 +1,4 @@
import { Post, Comment, Cell } from '@/types';
import { Post, Comment, Cell } from '@/types/forum';
export type SortOption = 'relevance' | 'time';

View File

@ -1,27 +0,0 @@
export interface RelevanceScoreDetails {
baseScore: number;
engagementScore: number;
authorVerificationBonus: number;
verifiedUpvoteBonus: number;
verifiedCommenterBonus: number;
timeDecayMultiplier: number;
moderationPenalty: number;
finalScore: number;
isVerified: boolean;
upvotes: number;
comments: number;
verifiedUpvotes: number;
verifiedCommenters: number;
daysOld: number;
isModerated: boolean;
}
export interface UserVerificationStatus {
[address: string]: {
isVerified: boolean;
hasENS: boolean;
hasOrdinal: boolean;
ensName?: string;
verificationStatus?: 'unverified' | 'verified-none' | 'verified-basic' | 'verified-owner' | 'verifying';
};
}

110
src/types/forum.ts Normal file
View File

@ -0,0 +1,110 @@
import { CellMessage, CommentMessage, PostMessage, VoteMessage, ModerateMessage } from "@/lib/waku/types";
export type OpchanMessage = CellMessage | PostMessage | CommentMessage | VoteMessage | ModerateMessage;
export interface User {
address: string;
walletType: 'bitcoin' | 'ethereum';
// Bitcoin-specific
ordinalOwnership?: boolean | { id: string; details: string };
// Ethereum-specific
ensName?: string;
ensAvatar?: string;
ensOwnership?: boolean;
verificationStatus: 'unverified' | 'verified-none' | 'verified-basic' | 'verified-owner' | 'verifying';
signature?: string;
lastChecked?: number;
browserPubKey?: string; // Browser-generated public key for key delegation
delegationSignature?: string; // Signature from Bitcoin/Ethereum wallet for delegation
delegationExpiry?: number; // When the delegation expires
}
export interface Cell {
id: string;
name: string;
description: string;
icon?: string;
signature?: string; // Message signature
browserPubKey?: string; // Public key that signed the message
relevanceScore?: number; // Calculated relevance score
activeMemberCount?: number; // Number of active members in the cell
relevanceDetails?: RelevanceScoreDetails; // Detailed breakdown of relevance score calculation
}
export interface Post {
id: string;
cellId: string;
authorAddress: string;
title: string;
content: string;
timestamp: number;
upvotes: VoteMessage[];
downvotes: VoteMessage[];
signature?: string; // Message signature
browserPubKey?: string; // Public key that signed the message
moderated?: boolean;
moderatedBy?: string;
moderationReason?: string;
moderationTimestamp?: number;
relevanceScore?: number; // Calculated relevance score
verifiedUpvotes?: number; // Count of upvotes from verified users
verifiedCommenters?: string[]; // List of verified users who commented
relevanceDetails?: RelevanceScoreDetails; // Detailed breakdown of relevance score calculation
}
export interface Comment {
id: string;
postId: string;
authorAddress: string;
content: string;
timestamp: number;
upvotes: VoteMessage[];
downvotes: VoteMessage[];
signature?: string; // Message signature
browserPubKey?: string; // Public key that signed the message
moderated?: boolean;
moderatedBy?: string;
moderationReason?: string;
moderationTimestamp?: number;
relevanceScore?: number; // Calculated relevance score
relevanceDetails?: RelevanceScoreDetails; // Detailed breakdown of relevance score calculation
}
// Extended message types for verification
export interface SignedMessage {
signature?: string; // Signature of the message
browserPubKey?: string; // Public key that signed the message
}
export interface RelevanceScoreDetails {
baseScore: number;
engagementScore: number;
authorVerificationBonus: number;
verifiedUpvoteBonus: number;
verifiedCommenterBonus: number;
timeDecayMultiplier: number;
moderationPenalty: number;
finalScore: number;
isVerified: boolean;
upvotes: number;
comments: number;
verifiedUpvotes: number;
verifiedCommenters: number;
daysOld: number;
isModerated: boolean;
}
export interface UserVerificationStatus {
[address: string]: {
isVerified: boolean;
hasENS: boolean;
hasOrdinal: boolean;
ensName?: string;
verificationStatus?: 'unverified' | 'verified-none' | 'verified-basic' | 'verified-owner' | 'verifying';
};
}

View File

@ -1,4 +0,0 @@
import 'react';
// Ensures file is treated as a module
export {};

View File

@ -1,82 +1 @@
import { CellMessage, CommentMessage, PostMessage, VoteMessage, ModerateMessage } from "@/lib/waku/types";
import { RelevanceScoreDetails } from "@/lib/forum/relevance";
export type OpchanMessage = CellMessage | PostMessage | CommentMessage | VoteMessage | ModerateMessage;
export interface User {
address: string;
walletType: 'bitcoin' | 'ethereum';
// Bitcoin-specific
ordinalOwnership?: boolean | { id: string; details: string };
// Ethereum-specific
ensName?: string;
ensAvatar?: string;
ensOwnership?: boolean;
verificationStatus: 'unverified' | 'verified-none' | 'verified-basic' | 'verified-owner' | 'verifying';
signature?: string;
lastChecked?: number;
browserPubKey?: string; // Browser-generated public key for key delegation
delegationSignature?: string; // Signature from Bitcoin/Ethereum wallet for delegation
delegationExpiry?: number; // When the delegation expires
}
export interface Cell {
id: string;
name: string;
description: string;
icon?: string;
signature?: string; // Message signature
browserPubKey?: string; // Public key that signed the message
relevanceScore?: number; // Calculated relevance score
activeMemberCount?: number; // Number of active members in the cell
relevanceDetails?: RelevanceScoreDetails; // Detailed breakdown of relevance score calculation
}
export interface Post {
id: string;
cellId: string;
authorAddress: string;
title: string;
content: string;
timestamp: number;
upvotes: VoteMessage[];
downvotes: VoteMessage[];
signature?: string; // Message signature
browserPubKey?: string; // Public key that signed the message
moderated?: boolean;
moderatedBy?: string;
moderationReason?: string;
moderationTimestamp?: number;
relevanceScore?: number; // Calculated relevance score
verifiedUpvotes?: number; // Count of upvotes from verified users
verifiedCommenters?: string[]; // List of verified users who commented
relevanceDetails?: RelevanceScoreDetails; // Detailed breakdown of relevance score calculation
}
export interface Comment {
id: string;
postId: string;
authorAddress: string;
content: string;
timestamp: number;
upvotes: VoteMessage[];
downvotes: VoteMessage[];
signature?: string; // Message signature
browserPubKey?: string; // Public key that signed the message
moderated?: boolean;
moderatedBy?: string;
moderationReason?: string;
moderationTimestamp?: number;
relevanceScore?: number; // Calculated relevance score
relevanceDetails?: RelevanceScoreDetails; // Detailed breakdown of relevance score calculation
}
// Extended message types for verification
export interface SignedMessage {
signature?: string; // Signature of the message
browserPubKey?: string; // Public key that signed the message
}
export * as forum from './forum';