Skip to content

Commit

Permalink
feat: notify users who have favorited a post
Browse files Browse the repository at this point in the history
closes #199
  • Loading branch information
drodil committed Feb 25, 2025
1 parent fdbd240 commit 38bb945
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions plugins/qeta-backend/src/database/DatabaseQetaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,12 @@ export class DatabaseQetaStore implements QetaStore {
.delete());
}

async getUsersWhoFavoritedPost(postId: number): Promise<string[]> {
const query = this.db('user_favorite').where('postId', '=', postId);
const users = await query.select('user');
return users.map(u => u.user);
}

async deleteAnswerVote(user_ref: string, answerId: number): Promise<boolean> {
return !!(await this.db('answer_votes')
.where('author', '=', user_ref)
Expand Down
10 changes: 6 additions & 4 deletions plugins/qeta-backend/src/database/QetaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,18 @@ export interface QetaStore {
/**
* Mark question favorite for user
* @param user_ref user name of the user voting question
* @param questionId question id
* @param postId post id
*/
favoritePost(user_ref: string, questionId: number): Promise<boolean>;
favoritePost(user_ref: string, postId: number): Promise<boolean>;

/**
* Mark question unfavorite for user
* @param user_ref user name of the user voting question
* @param questionId question id
* @param postId post id
*/
unfavoritePost(user_ref: string, questionId: number): Promise<boolean>;
unfavoritePost(user_ref: string, postId: number): Promise<boolean>;

getUsersWhoFavoritedPost(postId: number): Promise<string[]>;

/**
* Returns all used tags for posts
Expand Down
2 changes: 2 additions & 0 deletions plugins/qeta-backend/src/service/routes/answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const answersRoutes = (router: Router, options: RouteOptions) => {
database.getUsersForTags(post.tags),
database.getUsersForEntities(post.entities),
database.getFollowingUsers(username),
database.getUsersWhoFavoritedPost(post.id),
]);
const sent = await notificationMgr.onNewAnswer(
username,
Expand Down Expand Up @@ -329,6 +330,7 @@ export const answersRoutes = (router: Router, options: RouteOptions) => {
database.getUsersForTags(post.tags),
database.getUsersForEntities(post.entities),
database.getFollowingUsers(username),
database.getUsersWhoFavoritedPost(post.id),
]);
const sent = await notificationMgr.onAnswerComment(
username,
Expand Down
2 changes: 2 additions & 0 deletions plugins/qeta-backend/src/service/routes/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export const postsRoutes = (router: Router, options: RouteOptions) => {
database.getUsersForTags(post.tags),
database.getUsersForEntities(post.entities),
database.getFollowingUsers(username),
database.getUsersWhoFavoritedPost(post.id),
]);
const sent = await notificationMgr.onNewPostComment(
username,
Expand Down Expand Up @@ -451,6 +452,7 @@ export const postsRoutes = (router: Router, options: RouteOptions) => {
database.getUsersForTags(tags),
database.getUsersForEntities(entities),
database.getFollowingUsers(username),
database.getUsersWhoFavoritedPost(post.id),
]);
const sent = await notificationMgr.onNewPost(
username,
Expand Down

0 comments on commit 38bb945

Please sign in to comment.