dao-governance-framework/forum-network/public/classes/post.js

49 lines
992 B
JavaScript
Raw Normal View History

2022-12-31 16:08:42 -06:00
import { CryptoUtil } from './crypto.js';
export class Citation {
constructor(postId, weight) {
this.postId = postId;
this.weight = weight;
}
toJSON() {
return {
postId: this.postId,
weight: this.weight,
};
}
static fromJSON({ postId, weight }) {
return new Citation(postId, weight);
}
}
2022-11-12 16:20:42 -06:00
2023-01-01 21:09:02 -06:00
export class PostContent {
constructor(content) {
2022-11-12 16:20:42 -06:00
this.id = CryptoUtil.randomUUID();
this.content = content;
this.citations = [];
}
addCitation(postId, weight) {
const citation = new Citation(postId, weight);
this.citations.push(citation);
return this;
}
toJSON() {
return {
id: this.id,
content: this.content,
citations: this.citations.map((citation) => citation.toJSON()),
};
}
static fromJSON({ id, content, citations }) {
2023-01-01 21:09:02 -06:00
const post = new PostContent(content);
post.id = id;
post.citations = citations.map((citation) => Citation.fromJSON(citation));
return post;
}
}