Skip to content

Commit

Permalink
Replace atest comment badge with highlight instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Nov 30, 2023
1 parent 0178126 commit e361d7d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
24 changes: 8 additions & 16 deletions controllers/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,13 @@ function commentsTreeBuildAnonym(comments, usersHash) {
}

// Set latest comment flag.
let latestCommentStamp = 0;

if (latestCid) {
const latestComment = hash[latestCid];

latestComment.latest = true;
latestCommentStamp = latestComment.stamp;
}

return { tree, latestCommentStamp };
return { tree, latestCid };
}

async function commentsTreeBuildAuth({ iAm, type, commentModel, obj, canReply, showDel }) {
Expand Down Expand Up @@ -260,13 +257,10 @@ async function commentsTreeBuildAuth({ iAm, type, commentModel, obj, canReply, s
}

// Set latest comment flag.
let latestCommentStamp = 0;

if (latestCid) {
const latestComment = commentsHash[latestCid];

latestComment.latest = true;
latestCommentStamp = latestComment.stamp;
}

const { usersById, usersByLogin } = await getUsersHashForComments(usersSet);
Expand Down Expand Up @@ -312,7 +306,7 @@ async function commentsTreeBuildAuth({ iAm, type, commentModel, obj, canReply, s
}
}

return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCommentStamp };
return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCid };
}

async function commentsTreeBuildCanModerate({ iAm, type, commentModel, obj, showDel }) {
Expand Down Expand Up @@ -413,12 +407,10 @@ async function commentsTreeBuildCanModerate({ iAm, type, commentModel, obj, show

// Set latest comment flag.
const latestComment = commentsMap.get(latestCid);
let latestCommentStamp = 0;

if (latestComment) {
latestComment.latest = true;
commentsMap.set(latestCid, latestComment);
latestCommentStamp = latestComment.stamp;
}

const { usersById, usersByLogin } = await getUsersHashForComments(usersSet);
Expand All @@ -427,7 +419,7 @@ async function commentsTreeBuildCanModerate({ iAm, type, commentModel, obj, show
comment.user = usersById[comment.user].login;
}

return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCommentStamp };
return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCid };
}

async function commentsTreeBuildDel(comment, childs, checkMyId) {
Expand Down Expand Up @@ -559,14 +551,14 @@ async function getCommentsObjAnonym({ cid, type = 'photo' }) {
let tree;
let usersById;
let usersByLogin;
let latestCommentStamp = 0;
let latestCid = 0;

if (usersSet.size) {
({ usersById, usersByLogin } = await getUsersHashForComments(usersSet));
({ tree, latestCommentStamp } = commentsTreeBuildAnonym(comments, usersById));
({ tree, latestCid } = commentsTreeBuildAnonym(comments, usersById));
}

return { comments: tree || [], countTotal: comments.length, users: usersByLogin, latestCommentStamp };
return { comments: tree || [], countTotal: comments.length, users: usersByLogin, latestCid };
}

async function getCommentsObjAuth({ cid, type = 'photo', showDel = false }) {
Expand All @@ -590,14 +582,14 @@ async function getCommentsObjAuth({ cid, type = 'photo', showDel = false }) {
const canModerate = permissions.canModerate(type, obj, iAm);
const canReply = permissions.canReply(type, obj, iAm);

const { tree, users, countTotal, countNew, countDel, latestCommentStamp } = await (canModerate ?
const { tree, users, countTotal, countNew, countDel, latestCid } = await (canModerate ?
// Если это модератор данной фотографии или администратор новости
commentsTreeBuildCanModerate({ iAm, type, commentModel, obj, showDel }) :
// Если это зарегистрированный пользователь
commentsTreeBuildAuth({ iAm, type, commentModel, obj, canReply, showDel })
);

return { comments: tree, users, countTotal, countNew, countDel, canModerate, canReply, latestCommentStamp };
return { comments: tree, users, countTotal, countNew, countDel, canModerate, canReply, latestCid };
}

// Select comments for object
Expand Down
12 changes: 9 additions & 3 deletions public/js/module/comment/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define([
this.count = ko.observable(this.options.count || 0);
this.countNew = ko.observable(this.options.countNew || 0);
this.countDel = ko.observable(0);
this.latestCommentStamp = ko.observable(0);
this.latestCommentCid = ko.observable(0);
this.subscr = ko.observable(this.options.subscr || false);
this.nocomments = ko.observable(this.options.nocomments);
this.canReply = ko.observable(this.options.canReply);
Expand Down Expand Up @@ -394,7 +394,7 @@ define([
this.countDel(data.countDel || 0);
this.canModerate(canModerate);
this.canReply(canReply);
this.latestCommentStamp(data.latestCommentStamp);
this.latestCommentCid(data.latestCid);

if (Utils.isType('function', cbBeforeRender)) {
cbBeforeRender.call(ctx, data);
Expand Down Expand Up @@ -500,6 +500,8 @@ define([
}
} else if (ccid === 'latest') {
$element = $('.latest', this.$cmts);
ccid = this.latestCommentCid();
highlight = true;
} else {
$element = $('#c' + ccid, this.$cmts);
highlight = true;
Expand Down Expand Up @@ -546,7 +548,11 @@ define([
$('.c.hl', this.$cmts).removeClass('hl');
},
getLatestCommentStamp: function () {
return formatDateRelative(new Date(this.latestCommentStamp()));
if (this.commentsHash[this.latestCommentCid()]) {
return formatDateRelative(new Date(this.commentsHash[this.latestCommentCid()].stamp));
}

return '';
},
// Создаёт поле ввода комментария. Ответ или редактирование
inputCreate: function (relatedComment, $cedit) {
Expand Down
4 changes: 0 additions & 4 deletions views/module/comment/cdotanonym.pug
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@
.dotDelimeter ·
.changed(title="Показать историю изменений") {{='Изменен '+it.fDateIn(new Date(c.lastChanged))}}
| {{?}}
| {{?c.latest}}
.dotDelimeter ·
.badge.badge-latest Последний комментарий
| {{?}}
.ctext {{=c.txt}}
4 changes: 0 additions & 4 deletions views/module/comment/cdotauth.pug
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
.dotDelimeter ·
.changed(title="Показать историю изменений") {{='Изменен '+it.fDateIn(new Date(c.lastChanged))}}
| {{?}}
| {{?c.latest}}
.dotDelimeter ·
.badge.badge-latest Последний комментарий
| {{?}}
.ctext {{=c.txt}}
.cacts
| {{?it.reply}}
Expand Down

0 comments on commit e361d7d

Please sign in to comment.