Skip to content

Commit d9be36e

Browse files
authored
Merge pull request #643 from kabalin/latestcomment
Replace latest comment badge with highlight instead
2 parents 0178126 + e361d7d commit d9be36e

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

controllers/comment.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,13 @@ function commentsTreeBuildAnonym(comments, usersHash) {
107107
}
108108

109109
// Set latest comment flag.
110-
let latestCommentStamp = 0;
111-
112110
if (latestCid) {
113111
const latestComment = hash[latestCid];
114112

115113
latestComment.latest = true;
116-
latestCommentStamp = latestComment.stamp;
117114
}
118115

119-
return { tree, latestCommentStamp };
116+
return { tree, latestCid };
120117
}
121118

122119
async function commentsTreeBuildAuth({ iAm, type, commentModel, obj, canReply, showDel }) {
@@ -260,13 +257,10 @@ async function commentsTreeBuildAuth({ iAm, type, commentModel, obj, canReply, s
260257
}
261258

262259
// Set latest comment flag.
263-
let latestCommentStamp = 0;
264-
265260
if (latestCid) {
266261
const latestComment = commentsHash[latestCid];
267262

268263
latestComment.latest = true;
269-
latestCommentStamp = latestComment.stamp;
270264
}
271265

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

315-
return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCommentStamp };
309+
return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCid };
316310
}
317311

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

414408
// Set latest comment flag.
415409
const latestComment = commentsMap.get(latestCid);
416-
let latestCommentStamp = 0;
417410

418411
if (latestComment) {
419412
latestComment.latest = true;
420413
commentsMap.set(latestCid, latestComment);
421-
latestCommentStamp = latestComment.stamp;
422414
}
423415

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

430-
return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCommentStamp };
422+
return { tree: commentsTree, users: usersByLogin, countTotal, countNew, countDel, latestCid };
431423
}
432424

433425
async function commentsTreeBuildDel(comment, childs, checkMyId) {
@@ -559,14 +551,14 @@ async function getCommentsObjAnonym({ cid, type = 'photo' }) {
559551
let tree;
560552
let usersById;
561553
let usersByLogin;
562-
let latestCommentStamp = 0;
554+
let latestCid = 0;
563555

564556
if (usersSet.size) {
565557
({ usersById, usersByLogin } = await getUsersHashForComments(usersSet));
566-
({ tree, latestCommentStamp } = commentsTreeBuildAnonym(comments, usersById));
558+
({ tree, latestCid } = commentsTreeBuildAnonym(comments, usersById));
567559
}
568560

569-
return { comments: tree || [], countTotal: comments.length, users: usersByLogin, latestCommentStamp };
561+
return { comments: tree || [], countTotal: comments.length, users: usersByLogin, latestCid };
570562
}
571563

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

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

600-
return { comments: tree, users, countTotal, countNew, countDel, canModerate, canReply, latestCommentStamp };
592+
return { comments: tree, users, countTotal, countNew, countDel, canModerate, canReply, latestCid };
601593
}
602594

603595
// Select comments for object

public/js/module/comment/comments.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ define([
6666
this.count = ko.observable(this.options.count || 0);
6767
this.countNew = ko.observable(this.options.countNew || 0);
6868
this.countDel = ko.observable(0);
69-
this.latestCommentStamp = ko.observable(0);
69+
this.latestCommentCid = ko.observable(0);
7070
this.subscr = ko.observable(this.options.subscr || false);
7171
this.nocomments = ko.observable(this.options.nocomments);
7272
this.canReply = ko.observable(this.options.canReply);
@@ -394,7 +394,7 @@ define([
394394
this.countDel(data.countDel || 0);
395395
this.canModerate(canModerate);
396396
this.canReply(canReply);
397-
this.latestCommentStamp(data.latestCommentStamp);
397+
this.latestCommentCid(data.latestCid);
398398

399399
if (Utils.isType('function', cbBeforeRender)) {
400400
cbBeforeRender.call(ctx, data);
@@ -500,6 +500,8 @@ define([
500500
}
501501
} else if (ccid === 'latest') {
502502
$element = $('.latest', this.$cmts);
503+
ccid = this.latestCommentCid();
504+
highlight = true;
503505
} else {
504506
$element = $('#c' + ccid, this.$cmts);
505507
highlight = true;
@@ -546,7 +548,11 @@ define([
546548
$('.c.hl', this.$cmts).removeClass('hl');
547549
},
548550
getLatestCommentStamp: function () {
549-
return formatDateRelative(new Date(this.latestCommentStamp()));
551+
if (this.commentsHash[this.latestCommentCid()]) {
552+
return formatDateRelative(new Date(this.commentsHash[this.latestCommentCid()].stamp));
553+
}
554+
555+
return '';
550556
},
551557
// Создаёт поле ввода комментария. Ответ или редактирование
552558
inputCreate: function (relatedComment, $cedit) {

views/module/comment/cdotanonym.pug

-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@
2222
.dotDelimeter ·
2323
.changed(title="Показать историю изменений") {{='Изменен '+it.fDateIn(new Date(c.lastChanged))}}
2424
| {{?}}
25-
| {{?c.latest}}
26-
.dotDelimeter ·
27-
.badge.badge-latest Последний комментарий
28-
| {{?}}
2925
.ctext {{=c.txt}}

views/module/comment/cdotauth.pug

-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
.dotDelimeter ·
2626
.changed(title="Показать историю изменений") {{='Изменен '+it.fDateIn(new Date(c.lastChanged))}}
2727
| {{?}}
28-
| {{?c.latest}}
29-
.dotDelimeter ·
30-
.badge.badge-latest Последний комментарий
31-
| {{?}}
3228
.ctext {{=c.txt}}
3329
.cacts
3430
| {{?it.reply}}

0 commit comments

Comments
 (0)