| 1 |
|
| 2 |
|
| 3 |
Plugin.create(:mastodon_custom_post) do |
| 4 |
@visibilities = %w[direct private unlisted public].freeze |
| 5 |
|
| 6 |
command( |
| 7 |
:mastodon_custom_post, |
| 8 |
name: _('カスタム投稿'), |
| 9 |
condition: ->(opt) do |
| 10 |
mastodon?(opt.world) && opt.widget.editable? |
| 11 |
end, |
| 12 |
visible: true, |
| 13 |
icon: Skin[:post], |
| 14 |
role: :postbox |
| 15 |
) do |opt| |
| 16 |
i_postbox = opt.widget |
| 17 |
postbox, = Plugin.filtering(:gui_get_gtk_widget, i_postbox) |
| 18 |
body = postbox.widget_post.buffer.text |
| 19 |
reply_to = postbox.mastodon_get_reply_to |
| 20 |
|
| 21 |
dialog(_('カスタム投稿')) { |
| 22 |
ョンを並べる |
| 23 |
multitext _('CW警告文'), :spoiler_text |
| 24 |
self[:body] = body |
| 25 |
multitext _('本文'), :body |
| 26 |
self[:sensitive] = opt.world.account.source.sensitive |
| 27 |
boolean _('閲覧注意'), :sensitive |
| 28 |
|
| 29 |
self[:visibility] = Plugin::Mastodon::Util.visibility2select( |
| 30 |
visibility_default(opt.world.account.source.privacy, reply_to) |
| 31 |
) |
| 32 |
select _('公開範囲'), :visibility do |
| 33 |
option :'1public', _('公開') |
| 34 |
option :'2unlisted', _('未収載') |
| 35 |
option :'3private', _('非公開') |
| 36 |
option :'4direct', _('ダイレクト') |
| 37 |
end |
| 38 |
|
| 39 |
settings _('添付メディア') do |
| 40 |
勝手に持ってくる |
| 41 |
dirs = 10.times.map { |i| |
| 42 |
UserConfig[:"galary_dir#{i + 1}"] |
| 43 |
}.compact.reject(&:empty?) |
| 44 |
|
| 45 |
fileselect '', :media1, shortcuts: dirs, use_preview: true |
| 46 |
fileselect '', :media2, shortcuts: dirs, use_preview: true |
| 47 |
fileselect '', :media3, shortcuts: dirs, use_preview: true |
| 48 |
fileselect '', :media4, shortcuts: dirs, use_preview: true |
| 49 |
end |
| 50 |
|
| 51 |
settings _('投票を受付ける') do |
| 52 |
input '1', :poll_options1 |
| 53 |
input '2', :poll_options2 |
| 54 |
input '3', :poll_options3 |
| 55 |
input '4', :poll_options4 |
| 56 |
select _('投票受付期間'), :poll_expires_in do |
| 57 |
option :min5, _('5分') |
| 58 |
option :hour, _('1時間') |
| 59 |
option :day, _('1日') |
| 60 |
option :week, _('1週間') |
| 61 |
option :month, _('1ヶ月') |
| 62 |
end |
| 63 |
boolean _('複数選択可にする'), :poll_multiple |
| 64 |
boolean _('終了するまで結果を表示しない'), :poll_hide_totals |
| 65 |
end |
| 66 |
}.next do |result| |
| 67 |
投稿 |
| 68 |
像をアップロード |
| 69 |
media_ids = [] |
| 70 |
media_urls = [] |
| 71 |
(1..4).each do |i| |
| 72 |
if result[:"media#{i}"] |
| 73 |
path = Pathname(result[:"media#{i}"]) |
| 74 |
hash = +Plugin::Mastodon::API.call(:post, opt.world.domain, '/api/v1/media', opt.world.access_token, file: path) 枚同時アップロードできる |
| 75 |
media_ids << hash[:id].to_i |
| 76 |
media_urls << hash[:text_url] |
| 77 |
end |
| 78 |
end |
| 79 |
できたらcompose spellを起動 |
| 80 |
opts = { |
| 81 |
body: result[:body] |
| 82 |
} |
| 83 |
unless media_ids.empty? |
| 84 |
opts[:media_ids] = media_ids |
| 85 |
end |
| 86 |
unless result[:spoiler_text].empty? |
| 87 |
opts[:spoiler_text] = result[:spoiler_text] |
| 88 |
end |
| 89 |
opts[:sensitive] = result[:sensitive] |
| 90 |
opts[:visibility] = Plugin::Mastodon::Util.select2visibility(result[:visibility]) |
| 91 |
|
| 92 |
if (1..4).any? { |i| result[:"poll_options#{i}"] } |
| 93 |
opts[:poll] = {} |
| 94 |
opts[:poll][:expires_in] = case result[:poll_expires_in] |
| 95 |
when :min5 |
| 96 |
5 * 60 + 1 のための+1 |
| 97 |
when :hour |
| 98 |
60 * 60 |
| 99 |
when :day |
| 100 |
24 * 60 * 60 |
| 101 |
when :week |
| 102 |
7 * 24 * 60 * 60 |
| 103 |
when :month |
| 104 |
(Date.today.next_month - Date.today).to_i * 24 * 60 * 60 - 1 のための-1 |
| 105 |
end |
| 106 |
opts[:poll][:multiple] = !!result[:poll_multiple] |
| 107 |
opts[:poll][:hide_totals] = !!result[:poll_hide_totals] |
| 108 |
opts[:poll][:options] = (1..4).map { |i| result[:"poll_options#{i}"] }.compact |
| 109 |
end |
| 110 |
|
| 111 |
compose(opt.world, reply_to, **opts) |
| 112 |
|
| 113 |
if Gtk::PostBox.list[0] == postbox |
| 114 |
postbox.widget_post.buffer.text = '' |
| 115 |
else |
| 116 |
postbox.destroy |
| 117 |
end |
| 118 |
end |
| 119 |
end |
| 120 |
|
| 121 |
def visibility_default(default, reply_to) |
| 122 |
if reply_to.is_a?(Plugin::Mastodon::Status) |
| 123 |
@visibilities[ |
| 124 |
[ |
| 125 |
@visibilities.index(default), |
| 126 |
@visibilities.index(reply_to.visibility), |
| 127 |
@visibilities.size - 1 |
| 128 |
].compact.min |
| 129 |
] |
| 130 |
else |
| 131 |
default |
| 132 |
end |
| 133 |
end |
| 134 |
end |