|
@@ -14,8 +14,8 @@ import BaseTransport from './base';
|
|
|
import { ThreadId, PostId } from '@joystream/types/forum';
|
|
|
import { Proposal, ProposalId, VoteKind, DiscussionThread, DiscussionPost } from '@joystream/types/proposals';
|
|
|
import { MemberId } from '@joystream/types/members';
|
|
|
-import { u32 } from '@polkadot/types/';
|
|
|
-import { BalanceOf, EventRecord } from '@polkadot/types/interfaces';
|
|
|
+import { u32, u64 } from '@polkadot/types/';
|
|
|
+import { BalanceOf } from '@polkadot/types/interfaces';
|
|
|
|
|
|
import { includeKeys, bytesToString } from '../functions/misc';
|
|
|
import _ from 'lodash';
|
|
@@ -26,8 +26,6 @@ import MembersTransport from './members';
|
|
|
import ChainTransport from './chain';
|
|
|
import CouncilTransport from './council';
|
|
|
|
|
|
-import { Vec } from '@polkadot/types/codec';
|
|
|
-
|
|
|
export default class ProposalsTransport extends BaseTransport {
|
|
|
private membersT: MembersTransport;
|
|
|
private chainT: ChainTransport;
|
|
@@ -181,25 +179,6 @@ export default class ProposalsTransport extends BaseTransport {
|
|
|
return this.proposalsEngine.proposals(id, callback);
|
|
|
}
|
|
|
|
|
|
- // Find postId having only the object and storage key
|
|
|
- // FIXME: TODO: This is necessary because of the "hacky" workaround described in ./base.ts
|
|
|
- // (in order to avoid fetching all posts ever created)
|
|
|
- async findPostId (post: DiscussionPost, storageKey: string): Promise<PostId | null> {
|
|
|
- const blockHash = await this.api.rpc.chain.getBlockHash(post.created_at);
|
|
|
- const events = await this.api.query.system.events.at(blockHash) as Vec<EventRecord>;
|
|
|
- const postIds: PostId[] = events
|
|
|
- .filter(({ event }) => event.section === 'proposalsDiscussion' && event.method === 'PostCreated')
|
|
|
- .map(({ event }) => event.data[0] as PostId);
|
|
|
-
|
|
|
- // Just in case there were multiple posts created in this block...
|
|
|
- for (const postId of postIds) {
|
|
|
- const foundPostKey = this.proposalsDiscussion.postThreadIdByPostId.key(post.thread_id, postId);
|
|
|
- if (foundPostKey === storageKey) return postId;
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
async discussion (id: number|ProposalId): Promise<ParsedDiscussion | null> {
|
|
|
const threadId = (await this.proposalsCodex.threadIdByProposalId(id)) as ThreadId;
|
|
|
if (!threadId.toNumber()) {
|
|
@@ -207,15 +186,16 @@ export default class ProposalsTransport extends BaseTransport {
|
|
|
}
|
|
|
const thread = (await this.proposalsDiscussion.threadById(threadId)) as DiscussionThread;
|
|
|
const postEntries = await this.doubleMapEntries(
|
|
|
- this.proposalsDiscussion.postThreadIdByPostId,
|
|
|
+ 'proposalsDiscussion.postThreadIdByPostId',
|
|
|
threadId,
|
|
|
- (v) => new DiscussionPost(v)
|
|
|
+ (v) => new DiscussionPost(v),
|
|
|
+ async () => ((await this.proposalsDiscussion.postCount()) as u64).toNumber()
|
|
|
);
|
|
|
|
|
|
const parsedPosts: ParsedPost[] = [];
|
|
|
- for (const { storageKey, value: post } of postEntries) {
|
|
|
+ for (const { secondKey: postId, value: post } of postEntries) {
|
|
|
parsedPosts.push({
|
|
|
- postId: await this.findPostId(post, storageKey),
|
|
|
+ postId: new PostId(postId),
|
|
|
threadId: post.thread_id,
|
|
|
text: bytesToString(post.text),
|
|
|
createdAt: await this.chainT.blockTimestamp(post.created_at.toNumber()),
|