@@ -2,7 +2,7 @@ import { Option } from '@polkadot/types/codec'
2
2
import { Post , Space , SpacePermissionSet , SpacePermissions } from '@subsocial/types/substrate/interfaces'
3
3
import { notEmptyObj } from '@subsocial/utils'
4
4
import { FlatSpacePermissionKey , FlatSpacePermissionMap , FlatSpacePermissions , FlatSpacePermissionsKey } from '@subsocial/types/substrate/rpc'
5
- import { CanBeUpdated , CanHaveContent , CanHaveHandle , CanHaveParentId , CanHaveSpaceId , CommentExtension , CommentStruct , CommonContent , EntityData , EntityId , FlatPostExtension , FlatSuperCommon , HasId , HasOwner , PostStruct , ProfileStruct , PublicProfileStruct , SharedPostExtension , SharedPostStruct , SpaceOrPostStruct , SpaceStruct , SuperCommonStruct , FlatSpaceOrPost , SocialAccountWithId } from '@subsocial/types/dto'
5
+ import { CanHaveContent , CanHaveParentId , CanHaveSpaceId , CommentExtension , CommentStruct , CommonContent , EntityData , EntityId , FlatPostExtension , FlatSuperCommon , HasId , HasOwner , PostStruct , SharedPostExtension , SharedPostStruct , SpaceOrPostStruct , SpaceStruct , SuperCommonStruct , FlatSpaceOrPost } from '@subsocial/types/dto'
6
6
7
7
type EntityDataWithField < S extends { } > = EntityData < HasId & S , CommonContent > | ( HasId & S )
8
8
@@ -29,22 +29,6 @@ export const getUniqueContentIds = (entities: EntityDataWithField<CanHaveContent
29
29
export const getUniqueSpaceIds = ( entities : EntityDataWithField < CanHaveSpaceId > [ ] ) =>
30
30
getUniqueIds ( entities , 'spaceId' )
31
31
32
- function getUpdatedFields ( { updated } : SuperCommonStruct ) : CanBeUpdated {
33
- const maybeUpdated = updated . unwrapOr ( undefined )
34
- let res : CanBeUpdated = {
35
- isUpdated : updated . isSome ,
36
- }
37
- if ( maybeUpdated ) {
38
- res = {
39
- ...res ,
40
- updatedByAccount : maybeUpdated . account . toHuman ( ) ,
41
- updatedAtBlock : maybeUpdated . block . toNumber ( ) ,
42
- updatedAtTime : maybeUpdated . time . toNumber ( )
43
- }
44
- }
45
- return res
46
- }
47
-
48
32
function getContentFields ( { content } : SuperCommonStruct ) : CanHaveContent {
49
33
let res : CanHaveContent = { }
50
34
if ( content . isIpfs ) {
@@ -64,7 +48,7 @@ export function flattenCommonFields (struct: SuperCommonStruct): FlatSuperCommon
64
48
createdAtBlock : created . block . toNumber ( ) ,
65
49
createdAtTime : created . time . toNumber ( ) ,
66
50
67
- ... getUpdatedFields ( struct ) ,
51
+ isUpdated : struct . updated . toHuman ( ) ,
68
52
...getContentFields ( struct ) ,
69
53
}
70
54
}
@@ -97,10 +81,7 @@ export const flattenPermisions = (permissions?: SpacePermissions) => {
97
81
return flatPermissions
98
82
}
99
83
100
- export function flattenSpaceStruct ( struct : Space ) : SpaceStruct {
101
- const postsCount = struct . postsCount . toNumber ( )
102
- const hiddenPostsCount = struct . hiddenPostsCount . toNumber ( )
103
- const visiblePostsCount = postsCount - hiddenPostsCount
84
+ export function flattenSpaceStruct ( struct : Space , ) : SpaceStruct {
104
85
const flatPermissions = flattenPermisions ( struct . permissions . unwrapOr ( undefined ) )
105
86
106
87
let parentField : CanHaveParentId = { }
@@ -110,27 +91,13 @@ export function flattenSpaceStruct (struct: Space): SpaceStruct {
110
91
}
111
92
}
112
93
113
- let handleField : CanHaveHandle = { }
114
- if ( struct . handle . isSome ) {
115
- handleField = {
116
- handle : struct . handle . toHuman ( ) ?. toString ( )
117
- }
118
- }
119
-
120
94
121
95
return {
122
96
...flattenSpaceOrPostStruct ( struct ) ,
123
97
...parentField ,
124
- ...handleField ,
125
-
126
98
...flatPermissions ,
127
99
canFollowerCreatePosts : ! ! flatPermissions . followerPermissions ?. CreatePosts , //TODO: check CreatePosts permissions in follower set
128
100
canEveryoneCreatePosts : ! ! flatPermissions . everyonePermissions ?. CreatePosts , //TODO: check CreatePosts permissions in everyone set
129
- postsCount,
130
- hiddenPostsCount,
131
- visiblePostsCount,
132
- followersCount : struct . followersCount . toNumber ( ) ,
133
- score : struct . score . toNumber ( )
134
101
}
135
102
}
136
103
@@ -139,12 +106,13 @@ export function flattenSpaceStructs (structs: Space[]): SpaceStruct[] {
139
106
}
140
107
141
108
function flattenPostExtension ( struct : Post ) : FlatPostExtension {
142
- const { isSharedPost, isComment } = struct . extension
109
+ const { isSharedPost, isComment, isRegularPost } = struct . extension
143
110
let normExt : FlatPostExtension = { }
144
111
145
112
if ( isSharedPost ) {
113
+ const originalPostId = struct . extension . asSharedPost
146
114
const sharedPost : SharedPostExtension = {
147
- sharedPostId : struct . extension . asSharedPost . toString ( )
115
+ originalPostId : originalPostId . toString ( )
148
116
}
149
117
normExt = sharedPost
150
118
} else if ( isComment ) {
@@ -162,9 +130,6 @@ function flattenPostExtension (struct: Post): FlatPostExtension {
162
130
}
163
131
164
132
export function flattenPostStruct ( struct : Post ) : PostStruct {
165
- const repliesCount = struct . repliesCount . toNumber ( )
166
- const hiddenRepliesCount = struct . hiddenRepliesCount . toNumber ( )
167
- const visibleRepliesCount = repliesCount - hiddenRepliesCount
168
133
const { isRegularPost, isSharedPost, isComment } = struct . extension
169
134
const extensionFields = flattenPostExtension ( struct )
170
135
@@ -180,14 +145,8 @@ export function flattenPostStruct (struct: Post): PostStruct {
180
145
...spaceField ,
181
146
...extensionFields ,
182
147
183
- repliesCount,
184
- hiddenRepliesCount,
185
- visibleRepliesCount,
186
-
187
- sharesCount : struct . sharesCount . toNumber ( ) ,
188
148
upvotesCount : struct . upvotesCount . toNumber ( ) ,
189
149
downvotesCount : struct . downvotesCount . toNumber ( ) ,
190
- score : struct . score . toNumber ( ) ,
191
150
192
151
isRegularPost,
193
152
isSharedPost,
@@ -210,33 +169,3 @@ export function asCommentStruct (post: PostStruct): CommentStruct {
210
169
211
170
return post as CommentStruct
212
171
}
213
-
214
- export function asPublicProfileStruct ( profile : ProfileStruct ) : PublicProfileStruct {
215
- if ( ! profile . hasProfile ) throw new Error ( 'Account has no profile' )
216
-
217
- return profile as PublicProfileStruct
218
- }
219
-
220
- export function flattenProfileStruct ( struct : SocialAccountWithId ) : ProfileStruct {
221
- const profile = struct . profile ?. unwrapOr ( undefined )
222
- const hasProfile = struct . profile ?. isSome
223
- const maybeProfile : Partial < FlatSuperCommon > = profile
224
- ? flattenCommonFields ( profile )
225
- : { }
226
-
227
- return {
228
- id : struct . id . toString ( ) ,
229
-
230
- followersCount : struct . followersCount . toNumber ( ) ,
231
- followingAccountsCount : struct . followingAccountsCount . toNumber ( ) ,
232
- followingSpacesCount : struct . followingSpacesCount . toNumber ( ) ,
233
- reputation : struct . reputation . toNumber ( ) ,
234
-
235
- hasProfile,
236
- ...maybeProfile
237
- }
238
- }
239
-
240
- export function flattenProfileStructs ( accounts : SocialAccountWithId [ ] ) : ProfileStruct [ ] {
241
- return accounts . map ( flattenProfileStruct )
242
- }
0 commit comments