提案 #1600 » 0001-add-support-for-mastodon-bookmark.patch
plugin/mastodon/mastodon.rb | ||
---|---|---|
world.sse.user,
|
||
world.sse.mention,
|
||
world.sse.direct,
|
||
world.rest.bookmarks,
|
||
world.sse.public,
|
||
world.sse.public(only_media: true),
|
||
world.sse.public_local,
|
plugin/mastodon/model/rest_authorized_type.rb | ||
---|---|---|
set_endpoint_timelines('direct')
|
||
end
|
||
def bookmarks
|
||
@datasource_slug = "mastodon-#{world.account.acct}-bookmarks".to_sym
|
||
@title = Plugin[:mastodon]._('Mastodon/%{domain}/%{acct}/ブックマーク') % {domain: world.server.domain, acct: world.account.acct}
|
||
@perma_link = Diva::URI.new('https://%{domain}/api/v1/bookmarks' % {domain: server.domain})
|
||
@response_entities = :status
|
||
self
|
||
end
|
||
def list(list_id:, title:)
|
||
# params[:list] = list_id
|
||
@datasource_slug = "mastodon-#{world.account.acct}-list-#{list_id}".to_sym
|
plugin/mastodon/model/status.rb | ||
---|---|---|
field.has :application, Application
|
||
field.string :language
|
||
field.bool :pinned
|
||
field.bool :bookmarked
|
||
field.string :domain, required: true # APIには無い追加フィールド
|
||
... | ... | |
alias :perma_link :url
|
||
alias :muted? :muted
|
||
alias :pinned? :pinned
|
||
alias :bookmarked? :bookmarked
|
||
alias :retweet_ancestor :reblog
|
||
alias :sensitive? :sensitive # NSFW系プラグイン用
|
||
plugin/mastodon/model/world.rb | ||
---|---|---|
}
|
||
end
|
||
def bookmark(status)
|
||
Plugin::Mastodon::API.get_local_status_id(self, status).next{ |status_id|
|
||
Plugin::Mastodon::API.call(:post, domain, "/api/v1/statuses/#{status_id}/bookmark", access_token)
|
||
}.next{
|
||
status.bookmarked = true
|
||
}
|
||
end
|
||
def unbookmark(status)
|
||
Plugin::Mastodon::API.get_local_status_id(self, status).next{ |status_id|
|
||
Plugin::Mastodon::API.call(:post, domain, "/api/v1/statuses/#{status_id}/unbookmark", access_token)
|
||
}.next{
|
||
status.bookmarked = false
|
||
}
|
||
end
|
||
def report_for_spam(statuses, comment)
|
||
Deferred.when(
|
||
Plugin::Mastodon::API.get_local_account_id(self, statuses.first.account),
|
plugin/mastodon/spell.rb | ||
---|---|---|
}
|
||
end
|
||
command(:mastodon_pin_message, name: _('ブックマークする'), visible: true, role: :timeline,
|
||
condition: lambda { |opt|
|
||
opt.messages.any? { |m| bookmark_message?(opt.world, m) }
|
||
}) do |opt|
|
||
opt.messages.select{ |m|
|
||
bookmark_message?(opt.world, m)
|
||
}.each { |status|
|
||
opt.world.bookmark(status)
|
||
}
|
||
end
|
||
command(:mastodon_unpin_message, name: _('ブックマークを解除する'), visible: true, role: :timeline,
|
||
condition: lambda { |opt|
|
||
opt.messages.any? { |m| unbookmark_message?(opt.world, m) }
|
||
}) do |opt|
|
||
opt.messages.select{ |m|
|
||
unbookmark_message?(opt.world, m)
|
||
}.each { |status|
|
||
opt.world.unbookmark(status)
|
||
}
|
||
end
|
||
command(:mastodon_edit_list_membership, name: _('リストへの追加・削除'), visible: true, role: :timeline,
|
||
condition: lambda { |opt|
|
||
mastodon?(opt.world)
|
||
... | ... | |
world.unpin(status)
|
||
end
|
||
defspell(:bookmark_message, :mastodon, :mastodon_status,
|
||
condition: -> (world, status) { !status.bookmarked? }
|
||
) do |world, status|
|
||
world.bookmark(status)
|
||
end
|
||
defspell(:unbookmark_message, :mastodon, :mastodon_status,
|
||
condition: -> (world, status) { status.bookmarked? }
|
||
) do |world, status|
|
||
world.unbookmark(status)
|
||
end
|
||
defspell(:mastodon, :mastodon) do |mastodon|
|
||
true
|
||
end
|
plugin/mastodon_rest/mastodon_rest.rb | ||
---|---|---|
[ new_world.rest.user,
|
||
new_world.rest.mention,
|
||
new_world.rest.direct,
|
||
new_world.rest.bookmarks,
|
||
new_world.rest.public,
|
||
new_world.rest.public_local,
|
||
new_world.rest.public(only_media: true),
|