This commit is contained in:
Xeltica 2020-07-24 13:58:36 +09:00
parent 575e7e2fab
commit d24e835c5b
5 changed files with 70 additions and 35 deletions

View File

@ -29,6 +29,6 @@ export const render = views(__dirname + '/views', {
}
if (note.localOnly) icon += '☣';
return icon;
},
}
}
});

View File

@ -23,9 +23,14 @@ async function timeline(ctx: Context, host: string, endpoint: string, timelineNa
const user = await i(host, token);
const notes = await api<Note[]>(host, endpoint, { i: token });
const myself = await i(host, token);
await ctx.render('timeline', {
title: timelineName + ' - Simpkey',
user, notes, timelineName
user,
notes,
timelineName,
canRenote: (note: Note) => note.userId === myself.id || note.visibility === 'public' || note.visibility === 'home',
canReact: (note: Note) => note.userId !== myself.id,
});
}
@ -97,8 +102,13 @@ router.get('/notifications', async ctx => {
return;
}
const myself = await i(host, token);
const notifications = await api<any>(host, 'i/notifications', { i: token });
await ctx.render('notifications', { notifications });
await ctx.render('notifications', {
notifications,
canRenote: (note: Note) => note.userId === myself.id || note.visibility === 'public' || note.visibility === 'home',
canReact: (note: Note) => note.userId !== myself.id,
});
});
@ -111,8 +121,12 @@ router.get('/renote/:noteId', async ctx => {
}
try {
const myself = await i(host, token);
const note = await notesShow(host, ctx.params.noteId);
await ctx.render('renote', { note });
await ctx.render('renote', {
note,
canRenote: note.userId === myself.id || note.visibility === 'public' || note.visibility === 'home'
});
} catch(e) {
await die(ctx, e.message);
}
@ -145,16 +159,20 @@ router.get('/react/:noteId', async ctx => {
try {
const note = await notesShow(host, ctx.params.noteId);
const myself = await i(host, token);
await ctx.render('react', { note, reactions: myself.clientData?.reactions });
await ctx.render('react', {
note,
reactions: myself.clientData?.reactions,
canReact: note.userId !== myself.id && !note.myReaction
});
} catch(e) {
await die(ctx, e.message);
}
});
router.get('/@:acct', async ctx => {
const i = ctx.cookies.get('i');
const token = ctx.cookies.get('i');
const host = ctx.cookies.get('host');
if (!i || !host) {
if (!token || !host) {
await die(ctx, 'ログインしてください');
return;
}
@ -162,10 +180,16 @@ router.get('/@:acct', async ctx => {
const acct = ctx.params.acct.split('@');
const username = acct[0];
const remoteHost = acct[1];
const myself = await i(host, token);
const user = await usersShowByName(host, username, remoteHost);
const notes = await api<Note[]>(host, 'users/notes', { i, userId: user.id });
await ctx.render('user', { user, notes });
const notes = await api<Note[]>(host, 'users/notes', { i: token, userId: user.id });
await ctx.render('user', {
user,
notes,
canRenote: (note: Note) => note.userId === myself.id || note.visibility === 'public' || note.visibility === 'home',
canReact: (note: Note) => note.userId !== myself.id,
});
});
router.post('/', async ctx => {

View File

@ -54,17 +54,20 @@ mixin note(note)
footer
|[
a(href="/reply/" + note.id) リプライ !{note.repliesCount}
|] [
a(href="/renote/" + note.id) リノート !{note.renoteCount}
|]
if !note.myReaction
| [
a(href="/react/" + note.id) リアクション
| ]
else
form(action="action/unreact", method="post" style="display: inline")
input(type="hidden", name="noteId", value=note.id)
button(type="submit") リアクション解除
|]
if canRenote && canRenote(note)
|[
a(href="/renote/" + note.id) リノート !{note.renoteCount}
|]
if canReact && canReact(note)
if !note.myReaction
| [
a(href="/react/" + note.id) リアクション
| ]
else
form(action="action/unreact", method="post" style="display: inline")
input(type="hidden", name="noteId", value=note.id)
button(type="submit") リアクション解除
mixin post-form(url, placeholder, buttonText)
form(action=url, method="post")

View File

@ -1,16 +1,20 @@
extends _base
block content
h2 このノートにリアクションを押しますか?
+sub-note(note)
form(action="/action/react", method="post")
each val in reactions
if canReact
h2 このノートにリアクションを押しますか?
+sub-note(note)
form(action="/action/react", method="post")
each val in reactions
div: label
input(type="radio", name="reaction" value=val)
!= val
div: label
input(type="radio", name="reaction" value=val)
!= val
div: label
input(type="radio", name="reaction", value="custom")
input(type="text", name="customReaction")
input(type="hidden", name="noteId", value=note.id)
input(type="radio", name="reaction", value="custom")
input(type="text", name="customReaction")
input(type="hidden", name="noteId", value=note.id)
button(type="submit") リアクションを押す
button(type="submit") リアクションを押す
else
h2 このノートにはリアクションできません
+sub-note(note)

View File

@ -1,7 +1,11 @@
extends _base
block content
h2 このノートをリノートしますか?
+sub-note(note)
+post-form('/action/create-note', "コメント(省略可能)", "リノート")
input(type="hidden", name="renoteId", value=note.id)
if canRenote
h2 このノートをリノートしますか?
+sub-note(note)
+post-form('/action/create-note', "コメント(省略可能)", "リノート")
input(type="hidden", name="renoteId", value=note.id)
else
h2 このノートはリノートできません
+sub-note(note)