mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: discussion views (fix #69)
This commit is contained in:
1 parent
16fcd80a00
commit
2b8b9a776b
5 files changed
+29
-11
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.32.2",
|
||||
"version": "2.32.3",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -187,6 +187,12 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
||||
if (drdoc.reply) uids.push(...drdoc.reply.map((drrdoc) => drrdoc.owner));
|
||||
}
|
||||
const udict = await user.getList(domainId, uids);
|
||||
if (!dsdoc.view) {
|
||||
await Promise.all([
|
||||
discussion.inc(domainId, did, 'views', 1),
|
||||
discussion.setStatus(domainId, did, this.user._id, { view: true }),
|
||||
]);
|
||||
}
|
||||
const path = [
|
||||
['Hydro', 'homepage'],
|
||||
['discussion_main', 'discussion_main'],
|
||||
|
||||
@@ -9,6 +9,7 @@ import TaskModel from './task';
|
||||
import { DiscussionNodeNotFoundError, DocumentNotFoundError } from '../error';
|
||||
import { DiscussionReplyDoc, DiscussionTailReplyDoc, Document } from '../interface';
|
||||
import { buildProjection } from '../utils';
|
||||
import { NumberKeys } from '../typeutils';
|
||||
import * as bus from '../service/bus';
|
||||
|
||||
export interface DiscussionDoc extends Document { }
|
||||
@@ -112,6 +113,12 @@ export function edit(
|
||||
return document.set(domainId, document.TYPE_DISCUSSION, did, payload);
|
||||
}
|
||||
|
||||
export function inc(
|
||||
domainId: string, did: ObjectID, key: NumberKeys<DiscussionDoc>, value: number,
|
||||
): Promise<DiscussionDoc | null> {
|
||||
return document.inc(domainId, document.TYPE_DISCUSSION, did, key, value);
|
||||
}
|
||||
|
||||
export function del(domainId: string, did: ObjectID): Promise<never> {
|
||||
return Promise.all([
|
||||
document.deleteOne(domainId, document.TYPE_DISCUSSION, did),
|
||||
@@ -221,6 +228,10 @@ export function getStatus(domainId: string, did: ObjectID, uid: number) {
|
||||
return document.getStatus(domainId, document.TYPE_DISCUSSION, did, uid);
|
||||
}
|
||||
|
||||
export function setStatus(domainId: string, did: ObjectID, uid: number, $set) {
|
||||
return document.setStatus(domainId, document.TYPE_DISCUSSION, did, uid, $set);
|
||||
}
|
||||
|
||||
export function addNode(domainId: string, _id: string, category: string, args: any = {}) {
|
||||
return document.add(
|
||||
domainId, category, 1, document.TYPE_DISCUSSION_NODE,
|
||||
@@ -327,6 +338,7 @@ global.Hydro.model.discussion = {
|
||||
|
||||
add,
|
||||
get,
|
||||
inc,
|
||||
edit,
|
||||
del,
|
||||
count,
|
||||
@@ -344,6 +356,7 @@ global.Hydro.model.discussion = {
|
||||
react,
|
||||
setStar,
|
||||
getStatus,
|
||||
setStatus,
|
||||
addNode,
|
||||
getNode,
|
||||
getNodes,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.16.1",
|
||||
"version": "4.16.2",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
{{ vnode['title'] }}
|
||||
</a>
|
||||
</li>
|
||||
<li><h2>{{ ddoc.title }}</h2></li>
|
||||
<li>
|
||||
{{ user.render_inline(udict[ddoc.owner]) }}
|
||||
@
|
||||
@@ -30,13 +31,11 @@
|
||||
</div>
|
||||
<ul class="section__footer supplementary dot list">
|
||||
{% if handler.user.hasPerm(perm.PERM_EDIT_DISCUSSION) or (handler.user.own(ddoc) and handler.user.hasPerm(perm.PERM_EDIT_DISCUSSION_SELF)) %}
|
||||
<li>
|
||||
<a href="{{ url('discussion_edit', did=ddoc.docId) }}"><span class="icon icon-edit"></span> {{ _('Edit') }}</a>
|
||||
</li>
|
||||
<li><a href="{{ url('discussion_edit', did=ddoc.docId) }}">
|
||||
<span class="icon icon-edit"></span> {{ _('Edit') }}
|
||||
</a></li>
|
||||
{% endif %}
|
||||
<li>
|
||||
{{ _('{0} views').format(ddoc.views) }}
|
||||
</li>
|
||||
<li>{{ _('{0} views').format(ddoc.views) }}</li>
|
||||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
||||
<li><form class="form--inline" method="post">
|
||||
<input type="hidden" name="operation" value="{% if not dsdoc['star'] %}star{% else %}unstar{% endif %}">
|
||||
@@ -47,9 +46,9 @@
|
||||
</button>
|
||||
</form></li>
|
||||
{% endif %}
|
||||
<li>
|
||||
<a href="{{ url('wiki_help', anchor='contact') }}"><span class="icon icon-warning"></span> {{ _('Report') }}</a>
|
||||
</li>
|
||||
<li><a href="{{ url('wiki_help', anchor='contact') }}">
|
||||
<span class="icon icon-warning"></span> {{ _('Report') }}
|
||||
</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
|
||||
Reference in new issue
Block a user