| 1 |
module Plugin::Mastodon |
| 2 |
|
| 3 |
class PollOption < Diva::Model |
| 4 |
register :mastodon_poll_option, name: Plugin[:mastodon]._('Mastodon投票候補') |
| 5 |
|
| 6 |
field.string :title, required: true |
| 7 |
field.int :votes_count |
| 8 |
|
| 9 |
def path |
| 10 |
"/#{title}" |
| 11 |
end |
| 12 |
|
| 13 |
def inspect |
| 14 |
"mastodon-poll-option(#{title}, #{votes_count})" |
| 15 |
end |
| 16 |
end |
| 17 |
|
| 18 |
|
| 19 |
class Poll < Diva::Model |
| 20 |
register :mastodon_poll, name: Plugin[:mastodon]._('Mastodon投票') |
| 21 |
|
| 22 |
field.string :id, required: true |
| 23 |
field.time :expires_at |
| 24 |
field.bool :expired, required: true |
| 25 |
field.bool :multiple, required: true |
| 26 |
field.int :votes_count, required: true |
| 27 |
field.has :options, [PollOption], required: true |
| 28 |
field.bool :voted |
| 29 |
|
| 30 |
def initialize(hash) |
| 31 |
if hash[:expires_at].is_a?(String) |
| 32 |
hash[:expires_at] = Time.parse(hash[:expires_at]).localtime |
| 33 |
end |
| 34 |
|
| 35 |
super hash |
| 36 |
end |
| 37 |
|
| 38 |
def path |
| 39 |
"/#{id}" |
| 40 |
end |
| 41 |
|
| 42 |
def inspect |
| 43 |
"mastodon-poll(#{id})" |
| 44 |
end |
| 45 |
end |
| 46 |
end |