Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into en
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Jan 8, 2024
2 parents 253a39b + 8f07366 commit 47ce2c4
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ module.exports = {
'no-underscore-dangle': [2, { 'allow': [
'_id', '__get__', '__set__', '__RewireAPI__', '__Rewire__', '__ResetDependency__', '__GetDependency__',
] }],
// Max assertions is 20 and warning rather than error.
'jest/max-expects': [1, { 'max': 20 }],
// Max assertions is 10 and warning rather than error.
'jest/max-expects': [1, { 'max': 10 }],
// We are not using TypeScript
'jest/no-untyped-mock-factory': 0,
},
Expand Down
121 changes: 0 additions & 121 deletions controllers/__tests__/comment.test.js

This file was deleted.

56 changes: 20 additions & 36 deletions controllers/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,36 +722,9 @@ async function giveForUser({ login, page = 1, type = 'photo', active = true, del
}

const fields = { _id: 0, lastChanged: 1, cid: 1, obj: 1, stamp: 1, txt: 1, 'del.origin': 1 };
const options = { sort: { stamp: -1 }, skip: page * commentsUserPerPage, limit: commentsUserPerPage };
const options = { lean: true, sort: { stamp: -1 }, skip: page * commentsUserPerPage, limit: commentsUserPerPage };

if (!iAm.registered) {
comments = await commentModel.find(query, fields, options).lean().exec();
} else {
fields.hasChild = 1;
comments = await commentModel.aggregate([
{
'$match': query,
},
{
'$lookup': {
'from': commentModel.collection.collectionName,
'localField': 'cid',
'foreignField': 'parent',
'as': 'children',
},
},
{
'$addFields': {
'hasChild': {
$gt: [{ $size: '$children' }, 0],
},
},
},
{
'$project': fields,
},
]).sort(options.sort).skip(options.skip).limit(options.limit).exec();
}
comments = await commentModel.find(query, fields, options).exec();
}

if (_.isEmpty(comments)) {
Expand Down Expand Up @@ -784,6 +757,18 @@ async function giveForUser({ login, page = 1, type = 'photo', active = true, del

if (type === 'photo' && iAm.registered) {
await this.call('photo.fillPhotosProtection', { photos: objs, setMyFlag: true });

for (const obj of objs) {
objFormattedHashCid[obj.cid] = objFormattedHashId[obj._id] = obj;
obj._id = undefined;
obj.user = undefined;
obj.mime = undefined;
}
} else {
for (const obj of objs) {
objFormattedHashCid[obj.cid] = objFormattedHashId[obj._id] = obj;
obj._id = undefined;
}
}

for (const obj of objs) {
Expand All @@ -795,9 +780,6 @@ async function giveForUser({ login, page = 1, type = 'photo', active = true, del

// For each comment check object exists and assign to comment its cid
for (const comment of comments) {
// Mark those awaiting response.
comment.waitsAnswer = comment.hasChild !== undefined && !comment.hasChild;

const obj = objFormattedHashId[comment.obj];

if (obj !== undefined) {
Expand Down Expand Up @@ -944,7 +926,7 @@ async function create(data) {
throw obj.nocomments ? new NoticeError(constantsError.COMMENT_NOT_ALLOWED) : new AuthorizationError();
}

if (data.parent && (!parent || parent.del || parent.level >= 9 || data.level !== parent.level + 1)) {
if (data.parent && (!parent || parent.del || parent.level >= 9 || data.level !== (parent.level || 0) + 1)) {
throw new NoticeError(constantsError.COMMENT_WRONG_PARENT);
}

Expand All @@ -970,11 +952,9 @@ async function create(data) {
}
}

comment.level = data.level ?? 0;

if (data.parent) {
comment.parent = data.parent;
comment.level = data.level ?? parent.level + 1;
comment.level = data.level;
}

if (fragAdded) {
Expand Down Expand Up @@ -1018,6 +998,10 @@ async function create(data) {
comment.obj = objCid;
comment.can = {};

if (comment.level === undefined) {
comment.level = 0;
}

session.emitUser({ usObj: iAm, excludeSocket: socket });
subscrController.commentAdded(obj._id, iAm.user, stamp);

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "PastVu",
"version": "2.0.42",
"version": "2.0.43",
"description": "Retrospective topography of media content",
"homepage": "https://github.com/pastvu/pastvu",
"keywords": [
Expand Down
9 changes: 0 additions & 9 deletions public/style/common.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import '_vars.less';
@import 'fonts/fontU.less';
@import 'bs/bootstrap.less';
@import 'bs/badges.less';

@-webkit-keyframes fadeIn {
0% { opacity: 0; }
Expand Down Expand Up @@ -481,14 +480,6 @@ body {
}
}

// Badges
.badge-latest {
font-size: 11px;
font-weight: normal;
color: #f2f2f2;
background-color: rgba(85, 85, 85, 80%);
}

// Tooltip
.tltp {
position: absolute;
Expand Down
9 changes: 1 addition & 8 deletions views/module/user/comments.pug
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
.dotDelimeter ·
.commentChanged(title="Show history of changes", data-bind="text: ($data.del ? 'Removed at ' : 'Changed at ') + moment($data.lastChanged).calendar().toLowerCase(), click: function () {$parent.showHistory($data.obj.cid, $data.cid)}")
// /ko
//ko if: $data.waitsAnswer
.dotDelimeter ·
.badge.badge-latest Awaiting answer
// /ko
a.commentText(data-bind="attr: {href: $data.link}, html: $data.txt")
| </script>

Expand All @@ -62,10 +58,6 @@
.dotDelimeter ·
.commentChanged(title="Show history of changes", data-bind="text: ($data.del ? 'Removed at ' : 'Changed at ') + moment($data.lastChanged).calendar().toLowerCase(), click: function () {$parent.showHistory($data.obj.cid, $data.cid)}")
// /ko
//ko if: $data.waitsAnswer
.dotDelimeter ·
.badge.badge-latest Awaiting answer
// /ko
a.commentText(style="margin-left:29px", data-bind="attr: {href: $data.link}, html: $data.txt")
| </script>

Expand All @@ -79,3 +71,4 @@
li.edge(data-bind="css: {disabled: !pageHasNext()}"): a(data-bind="attr: {href: pageUrl() + '/' + (page() + 1) + pageQuery()}", title="Next page") &raquo;
li.edge(data-bind="css: {disabled: page() === pageLast()}"): a(data-bind="attr: {href: pageUrl() + '/' + pageLast() + pageQuery()}", title="Last page") &raquo;&raquo;
| </script>

0 comments on commit 47ce2c4

Please sign in to comment.