mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-28 14:16:44 -06:00
This commit is contained in:
parent
dbafa13d94
commit
caf9457653
6 changed files with 167 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "misskey",
|
||||
"author": "syuilo <i@syuilo.com>",
|
||||
"version": "0.0.1434",
|
||||
"version": "0.0.1460",
|
||||
"license": "MIT",
|
||||
"description": "A miniblog-based SNS",
|
||||
"bugs": "https://github.com/syuilo/misskey/issues",
|
||||
|
|
|
@ -409,6 +409,10 @@ const endpoints: Endpoint[] = [
|
|||
},
|
||||
kind: 'vote-write'
|
||||
},
|
||||
{
|
||||
name: 'posts/polls/recommendation',
|
||||
withCredential: true
|
||||
},
|
||||
|
||||
{
|
||||
name: 'messaging/history',
|
||||
|
|
57
src/api/endpoints/posts/polls/recommendation.ts
Normal file
57
src/api/endpoints/posts/polls/recommendation.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import Vote from '../../../models/poll-vote';
|
||||
import Post from '../../../models/post';
|
||||
import serialize from '../../../serializers/post';
|
||||
|
||||
/**
|
||||
* Get recommended polls
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get votes
|
||||
const votes = await Vote.find({
|
||||
user_id: user._id
|
||||
}, {
|
||||
fields: {
|
||||
_id: false,
|
||||
post_id: true
|
||||
}
|
||||
});
|
||||
|
||||
const nin = votes && votes.length != 0 ? votes.map(v => v.post_id) : [];
|
||||
|
||||
const posts = await Post
|
||||
.find({
|
||||
_id: {
|
||||
$nin: nin
|
||||
},
|
||||
poll: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
sort: {
|
||||
_id: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(posts.map(async post =>
|
||||
await serialize(post, user, { detail: true }))));
|
||||
});
|
103
src/web/app/desktop/tags/home-widgets/recommended-polls.tag
Normal file
103
src/web/app/desktop/tags/home-widgets/recommended-polls.tag
Normal file
|
@ -0,0 +1,103 @@
|
|||
<mk-recommended-polls-home-widget>
|
||||
<p class="title"><i class="fa fa-pie-chart"></i>投票</p>
|
||||
<button onclick={ refresh } title="他を見る"><i class="fa fa-refresh"></i></button>
|
||||
<div class="poll" if={ !loading && poll != null }>
|
||||
<p class="text">{ poll.text }</p>
|
||||
<mk-poll post={ poll }></mk-poll>
|
||||
</div>
|
||||
<p class="empty" if={ !loading && poll == null }>ありません!</p>
|
||||
<p class="loading" if={ loading }><i class="fa fa-spinner fa-pulse fa-fw"></i>読み込んでいます<mk-ellipsis></mk-ellipsis></p>
|
||||
<style>
|
||||
:scope
|
||||
display block
|
||||
background #fff
|
||||
|
||||
> .title
|
||||
margin 0
|
||||
padding 0 16px
|
||||
line-height 42px
|
||||
font-size 0.9em
|
||||
font-weight bold
|
||||
color #888
|
||||
border-bottom solid 1px #eee
|
||||
|
||||
> i
|
||||
margin-right 4px
|
||||
|
||||
> button
|
||||
position absolute
|
||||
z-index 2
|
||||
top 0
|
||||
right 0
|
||||
padding 0
|
||||
width 42px
|
||||
font-size 0.9em
|
||||
line-height 42px
|
||||
color #ccc
|
||||
|
||||
&:hover
|
||||
color #aaa
|
||||
|
||||
&:active
|
||||
color #999
|
||||
|
||||
> .poll
|
||||
padding 16px
|
||||
font-size 12px
|
||||
color #555
|
||||
|
||||
> p
|
||||
margin 0 0 8px 0
|
||||
|
||||
> .empty
|
||||
margin 0
|
||||
padding 16px
|
||||
text-align center
|
||||
color #aaa
|
||||
|
||||
> .loading
|
||||
margin 0
|
||||
padding 16px
|
||||
text-align center
|
||||
color #aaa
|
||||
|
||||
> i
|
||||
margin-right 4px
|
||||
|
||||
</style>
|
||||
<script>
|
||||
this.mixin('api');
|
||||
|
||||
this.poll = null;
|
||||
this.loading = true;
|
||||
|
||||
this.offset = 0;
|
||||
|
||||
this.on('mount', () => {
|
||||
this.fetch();
|
||||
});
|
||||
|
||||
this.fetch = () => {
|
||||
this.update({
|
||||
loading: true,
|
||||
poll: null
|
||||
});
|
||||
this.api('posts/polls/recommendation', {
|
||||
limit: 1,
|
||||
offset: this.offset
|
||||
}).then(posts => {
|
||||
const poll = posts ? posts[0] : null;
|
||||
if (poll == null) this.offset = 0;
|
||||
this.update({
|
||||
loading: false,
|
||||
poll: poll
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.refresh = () => {
|
||||
this.offset++;
|
||||
this.fetch();
|
||||
};
|
||||
</script>
|
||||
</mk-recommended-polls-home-widget>
|
|
@ -76,6 +76,7 @@
|
|||
'broadcast',
|
||||
'notifications',
|
||||
'user-recommendation',
|
||||
'recommended-polls',
|
||||
'donation',
|
||||
'nav',
|
||||
'tips'
|
||||
|
|
|
@ -42,6 +42,7 @@ require('./home-widgets/rss-reader.tag');
|
|||
require('./home-widgets/photo-stream.tag');
|
||||
require('./home-widgets/broadcast.tag');
|
||||
require('./home-widgets/version.tag');
|
||||
require('./home-widgets/recommended-polls.tag');
|
||||
require('./timeline.tag');
|
||||
require('./messaging/window.tag');
|
||||
require('./messaging/room-window.tag');
|
||||
|
|
Loading…
Reference in a new issue