Skip to content

Commit b8ba9d3

Browse files
authored
Merge pull request #4696 from coralproject/develop
v9.5.3
2 parents dad90cd + 317fe8b commit b8ba9d3

File tree

10 files changed

+33
-21
lines changed

10 files changed

+33
-21
lines changed

client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coralproject/talk",
3-
"version": "9.5.2",
3+
"version": "9.5.3",
44
"author": "The Coral Project",
55
"homepage": "https://coralproject.net/",
66
"sideEffects": [

common/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "common",
3-
"version": "9.5.2",
3+
"version": "9.5.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "common",
3-
"version": "9.5.2",
3+
"version": "9.5.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

locales/fr-FR/stream.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ stream-footer-links-top-of-article = Revenir au début du contenu
800800
.title = Aller en haut de l'article
801801
stream-footer-links-top-of-comments = Revenir au début des commentaires
802802
.title = Aller en haut des commentaires
803-
stream-footer-links-profile = Profile et réponses
803+
stream-footer-links-profile = Profil et réponses
804804
.title = Aller au profil et aux réponses
805805
stream-footer-links-discussions = Plus de discussions
806806
.title = Lire plus de discussions

server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coralproject/talk",
3-
"version": "9.5.2",
3+
"version": "9.5.3",
44
"author": "The Coral Project",
55
"homepage": "https://coralproject.net/",
66
"sideEffects": [

server/src/core/server/models/user/helpers.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GQLUSER_ROLE } from "coral-server/graph/schema/__generated__/types";
66
import { isSiteModerationScoped } from "coral-common/common/lib/permissions";
77

88
import { MODERATOR_ROLES, STAFF_ROLES } from "./constants";
9-
import { LocalProfile, Profile, SSOProfile, User } from "./user";
9+
import { IgnoredUser, LocalProfile, Profile, SSOProfile, User } from "./user";
1010

1111
export function roleIsStaff(role: GQLUSER_ROLE) {
1212
if (STAFF_ROLES.includes(role)) {
@@ -189,3 +189,16 @@ export function hasSSOProfile(user: Pick<User, "profiles">): boolean {
189189
const profile = getUserProfile(user, "sso") as SSOProfile | null;
190190
return profile ? true : false;
191191
}
192+
193+
/**
194+
* authorIsIgnored will return true if the author is ignored by the viewer
195+
* @param authorID id of the author of the comment
196+
* @param viewer the User who attempting to access the comment
197+
*/
198+
199+
export function authorIsIgnored(authorID: string, viewer: User): boolean {
200+
return (
201+
viewer.ignoredUsers &&
202+
viewer.ignoredUsers.some((user: IgnoredUser) => user.id === authorID)
203+
);
204+
}

server/src/core/server/models/user/user.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ import {
5454
createEmptyCommentStatusCounts,
5555
updateRelatedCommentCounts,
5656
} from "../comment";
57-
import { getLocalProfile, getSSOProfile, hasLocalProfile } from "./helpers";
57+
import {
58+
authorIsIgnored,
59+
getLocalProfile,
60+
getSSOProfile,
61+
hasLocalProfile,
62+
} from "./helpers";
5863

5964
export interface LocalProfile {
6065
type: "local";
@@ -3154,11 +3159,7 @@ export async function ignoreUser(
31543159
throw new UserNotFoundError(id);
31553160
}
31563161

3157-
// TODO: extract function
3158-
if (
3159-
user.ignoredUsers &&
3160-
user.ignoredUsers.some((u) => u.id === ignoreUserID)
3161-
) {
3162+
if (authorIsIgnored(ignoreUserID, user)) {
31623163
// TODO: improve error
31633164
throw new Error("user already ignored");
31643165
}

server/src/core/server/services/notifications/email/categories/reply.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { mapErrorsToNull } from "coral-server/helpers/dataloader";
77
import { hasPublishedStatus } from "coral-server/models/comment";
88
import { PUBLISHED_STATUSES } from "coral-server/models/comment/constants";
99
import { getStoryTitle, getURLWithCommentID } from "coral-server/models/story";
10-
import { IgnoredUser, User } from "coral-server/models/user";
10+
import { User } from "coral-server/models/user";
11+
import { authorIsIgnored } from "coral-server/models/user/helpers";
1112

1213
import { NotificationCategory } from "./category";
1314

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

7172
// Check to see if this user is ignoring the user who replied to their
7273
// comment.
73-
if (
74-
parentAuthor.ignoredUsers.some(
75-
(ignoredUser: IgnoredUser) => ignoredUser.id === author.id
76-
)
77-
) {
74+
if (authorIsIgnored(author.id, parentAuthor)) {
7875
return null;
7976
}
8077

server/src/core/server/services/notifications/internal/context.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
retrieveUser,
1515
User,
1616
} from "coral-server/models/user";
17+
import { authorIsIgnored } from "coral-server/models/user/helpers";
1718
import { I18n } from "coral-server/services/i18n";
1819

1920
import {
@@ -66,7 +67,7 @@ const shouldSendReplyNotification = (
6667
return false;
6768
}
6869
// don't notify when ignored users reply
69-
return !targetUser.ignoredUsers.some((user) => user.id === replyAuthorID);
70+
return !authorIsIgnored(replyAuthorID, targetUser);
7071
}
7172

7273
return false;

server/src/core/server/services/users/users.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import {
106106
warnUser,
107107
} from "coral-server/models/user";
108108
import {
109+
authorIsIgnored,
109110
getLocalProfile,
110111
hasLocalProfile,
111112
hasStaffRole,
@@ -2299,8 +2300,7 @@ export async function ignore(
22992300
throw new UserCannotBeIgnoredError(userID);
23002301
}
23012302

2302-
// TODO: extract function
2303-
if (user.ignoredUsers && user.ignoredUsers.some((u) => u.id === userID)) {
2303+
if (authorIsIgnored(userID, user)) {
23042304
// TODO: improve error
23052305
throw new Error("user already ignored");
23062306
}

0 commit comments

Comments
 (0)