Skip to content

Commit

Permalink
Merge pull request #4696 from coralproject/develop
Browse files Browse the repository at this point in the history
v9.5.3
  • Loading branch information
tessalt authored Nov 14, 2024
2 parents dad90cd + 317fe8b commit b8ba9d3
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "9.5.2",
"version": "9.5.3",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand Down
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common",
"version": "9.5.2",
"version": "9.5.3",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "common",
"version": "9.5.2",
"version": "9.5.3",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion locales/fr-FR/stream.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ stream-footer-links-top-of-article = Revenir au début du contenu
.title = Aller en haut de l'article
stream-footer-links-top-of-comments = Revenir au début des commentaires
.title = Aller en haut des commentaires
stream-footer-links-profile = Profile et réponses
stream-footer-links-profile = Profil et réponses
.title = Aller au profil et aux réponses
stream-footer-links-discussions = Plus de discussions
.title = Lire plus de discussions
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/talk",
"version": "9.5.2",
"version": "9.5.3",
"author": "The Coral Project",
"homepage": "https://coralproject.net/",
"sideEffects": [
Expand Down
15 changes: 14 additions & 1 deletion server/src/core/server/models/user/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GQLUSER_ROLE } from "coral-server/graph/schema/__generated__/types";
import { isSiteModerationScoped } from "coral-common/common/lib/permissions";

import { MODERATOR_ROLES, STAFF_ROLES } from "./constants";
import { LocalProfile, Profile, SSOProfile, User } from "./user";
import { IgnoredUser, LocalProfile, Profile, SSOProfile, User } from "./user";

export function roleIsStaff(role: GQLUSER_ROLE) {
if (STAFF_ROLES.includes(role)) {
Expand Down Expand Up @@ -189,3 +189,16 @@ export function hasSSOProfile(user: Pick<User, "profiles">): boolean {
const profile = getUserProfile(user, "sso") as SSOProfile | null;
return profile ? true : false;
}

/**
* authorIsIgnored will return true if the author is ignored by the viewer
* @param authorID id of the author of the comment
* @param viewer the User who attempting to access the comment
*/

export function authorIsIgnored(authorID: string, viewer: User): boolean {
return (
viewer.ignoredUsers &&
viewer.ignoredUsers.some((user: IgnoredUser) => user.id === authorID)
);
}
13 changes: 7 additions & 6 deletions server/src/core/server/models/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ import {
createEmptyCommentStatusCounts,
updateRelatedCommentCounts,
} from "../comment";
import { getLocalProfile, getSSOProfile, hasLocalProfile } from "./helpers";
import {
authorIsIgnored,
getLocalProfile,
getSSOProfile,
hasLocalProfile,
} from "./helpers";

export interface LocalProfile {
type: "local";
Expand Down Expand Up @@ -3154,11 +3159,7 @@ export async function ignoreUser(
throw new UserNotFoundError(id);
}

// TODO: extract function
if (
user.ignoredUsers &&
user.ignoredUsers.some((u) => u.id === ignoreUserID)
) {
if (authorIsIgnored(ignoreUserID, user)) {
// TODO: improve error
throw new Error("user already ignored");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { mapErrorsToNull } from "coral-server/helpers/dataloader";
import { hasPublishedStatus } from "coral-server/models/comment";
import { PUBLISHED_STATUSES } from "coral-server/models/comment/constants";
import { getStoryTitle, getURLWithCommentID } from "coral-server/models/story";
import { IgnoredUser, User } from "coral-server/models/user";
import { User } from "coral-server/models/user";
import { authorIsIgnored } from "coral-server/models/user/helpers";

import { NotificationCategory } from "./category";

Expand Down Expand Up @@ -70,11 +71,7 @@ export const reply: NotificationCategory<Payloads> = {

// Check to see if this user is ignoring the user who replied to their
// comment.
if (
parentAuthor.ignoredUsers.some(
(ignoredUser: IgnoredUser) => ignoredUser.id === author.id
)
) {
if (authorIsIgnored(author.id, parentAuthor)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
retrieveUser,
User,
} from "coral-server/models/user";
import { authorIsIgnored } from "coral-server/models/user/helpers";
import { I18n } from "coral-server/services/i18n";

import {
Expand Down Expand Up @@ -66,7 +67,7 @@ const shouldSendReplyNotification = (
return false;
}
// don't notify when ignored users reply
return !targetUser.ignoredUsers.some((user) => user.id === replyAuthorID);
return !authorIsIgnored(replyAuthorID, targetUser);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions server/src/core/server/services/users/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
warnUser,
} from "coral-server/models/user";
import {
authorIsIgnored,
getLocalProfile,
hasLocalProfile,
hasStaffRole,
Expand Down Expand Up @@ -2299,8 +2300,7 @@ export async function ignore(
throw new UserCannotBeIgnoredError(userID);
}

// TODO: extract function
if (user.ignoredUsers && user.ignoredUsers.some((u) => u.id === userID)) {
if (authorIsIgnored(userID, user)) {
// TODO: improve error
throw new Error("user already ignored");
}
Expand Down

0 comments on commit b8ba9d3

Please sign in to comment.