Skip to content

Commit

Permalink
add method for community notes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrir committed Dec 11, 2024
1 parent c31dd2a commit d26535a
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 198 deletions.
2 changes: 2 additions & 0 deletions backend/src/models/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CommentType extends Document {
imageUrl?: string;
hashTags?: string[];
mentionedUsers?: Types.ObjectId[];
communityNote?: string;
}

const CommentSchema = new Schema<CommentType>({
Expand All @@ -28,6 +29,7 @@ const CommentSchema = new Schema<CommentType>({
imageUrl: { type: String, default: undefined },
hashTags: { type: [String], default: undefined, index: true },
mentionedUsers: [{ type: Schema.Types.ObjectId, ref: 'User', default: [] }],
communityNote: { type: String, default: undefined },
});

export const Comment = model<CommentType>('Comment', CommentSchema);
2 changes: 2 additions & 0 deletions backend/src/models/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface PostType extends Document {
imageUrl?: string;
hashTags?: string[];
mentionedUsers?: Types.ObjectId[];
communityNote?: string;
}

const PostSchema = new Schema<PostType>({
Expand All @@ -24,6 +25,7 @@ const PostSchema = new Schema<PostType>({
imageUrl: { type: String, default: undefined },
hashTags: { type: [String], default: undefined, index: true },
mentionedUsers: [{ type: Schema.Types.ObjectId, ref: 'User', default: [] }],
communityNote: { type: String, default: undefined },
});

export const Post = model<PostType>('Post', PostSchema);
24 changes: 4 additions & 20 deletions backend/src/resolvers/post/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const postQueries: IResolvers = {
getPosts: async (
_: any,
{ page = 1, filter = 'LATEST', limit = 10 }: { page: number; filter: string; limit?: number },
{ user, isRetarded }: { user?: UserType; isRetarded?: boolean }
{ user }: { user?: UserType; isRetarded?: boolean }
) => {
const ITEMS_PER_PAGE = limit;
const skip = (page - 1) * ITEMS_PER_PAGE;
Expand Down Expand Up @@ -218,6 +218,7 @@ export const postQueries: IResolvers = {
parentID: (originalPost as CommentType).parentID,
parentType: (originalPost as CommentType).parentType,
controversyRatio: controversyRatio,
communityNote: originalPost.communityNote,
};
})
);
Expand Down Expand Up @@ -255,24 +256,6 @@ export const postQueries: IResolvers = {

combinedResults = combinedResults.slice(0, ITEMS_PER_PAGE);

if (isRetarded) {
combinedResults = [
{
__typename: 'Post',
id: new Types.ObjectId('6756e9357a50c3bf2f45267d'),
body: 'Dassbotn',
originalBody: null,
author: new Types.ObjectId('6756f1dd7a50c3bf2f453046'),
amtLikes: 69,
amtComments: 0,
amtReposts: 0,
imageUrl: '/uploads/dassbotten.gif',
createdAt: '1733749045885',
},
...combinedResults,
];
}

return combinedResults;
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -348,6 +331,7 @@ export const postQueries: IResolvers = {
amtReposts: 1,
createdAt: 1,
imageUrl: 1,
communityNote: 1,
},
},
]);
Expand Down Expand Up @@ -386,4 +370,4 @@ export const postQueries: IResolvers = {
}
},
},
};
};
3 changes: 3 additions & 0 deletions backend/src/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Post {
imageUrl: String
hashTags: [String!]!
mentionedUsers: [User!]!
communityNote: String
}

type Comment {
Expand All @@ -71,6 +72,7 @@ type Comment {
imageUrl: String
hashTags: [String!]!
mentionedUsers: [User!]!
communityNote: String
}

type TrendingHashtag {
Expand Down Expand Up @@ -116,6 +118,7 @@ type Repost {
mentionedUsers: [User!]!
parentID: ID
parentType: String
communityNote: String
}

type Mutation {
Expand Down
Loading

0 comments on commit d26535a

Please sign in to comment.