プロジェクト

全般

プロフィール

提案 #1600 » 0001-add-support-for-mastodon-bookmark.patch

Akira Ouchi, 2024-12-15 23:53

差分を表示:

plugin/mastodon/mastodon.rb
110 110
            world.sse.user,
111 111
            world.sse.mention,
112 112
            world.sse.direct,
113
            world.rest.bookmarks,
113 114
            world.sse.public,
114 115
            world.sse.public(only_media: true),
115 116
            world.sse.public_local,
plugin/mastodon/model/rest_authorized_type.rb
35 35
      set_endpoint_timelines('direct')
36 36
    end
37 37

  
38
    def bookmarks
39
      @datasource_slug = "mastodon-#{world.account.acct}-bookmarks".to_sym
40
      @title = Plugin[:mastodon]._('Mastodon/%{domain}/%{acct}/ブックマーク') % {domain: world.server.domain, acct: world.account.acct}
41
      @perma_link = Diva::URI.new('https://%{domain}/api/v1/bookmarks' % {domain: server.domain})
42
      @response_entities = :status
43
      self
44
    end
45

  
38 46
    def list(list_id:, title:)
39 47
      # params[:list] = list_id
40 48
      @datasource_slug = "mastodon-#{world.account.acct}-list-#{list_id}".to_sym
plugin/mastodon/model/status.rb
31 31
    field.has :application, Application
32 32
    field.string :language
33 33
    field.bool :pinned
34
    field.bool :bookmarked
34 35

  
35 36
    field.string :domain, required: true # APIには無い追加フィールド
36 37

  
......
51 52
    alias :perma_link :url
52 53
    alias :muted? :muted
53 54
    alias :pinned? :pinned
55
    alias :bookmarked? :bookmarked
54 56
    alias :retweet_ancestor :reblog
55 57
    alias :sensitive? :sensitive # NSFW系プラグイン用
56 58

  
plugin/mastodon/model/world.rb
241 241
      }
242 242
    end
243 243

  
244
    def bookmark(status)
245
      Plugin::Mastodon::API.get_local_status_id(self, status).next{ |status_id|
246
        Plugin::Mastodon::API.call(:post, domain, "/api/v1/statuses/#{status_id}/bookmark", access_token)
247
      }.next{
248
        status.bookmarked = true
249
      }
250
    end
251

  
252
    def unbookmark(status)
253
      Plugin::Mastodon::API.get_local_status_id(self, status).next{ |status_id|
254
        Plugin::Mastodon::API.call(:post, domain, "/api/v1/statuses/#{status_id}/unbookmark", access_token)
255
      }.next{
256
        status.bookmarked = false
257
      }
258
    end
259

  
244 260
    def report_for_spam(statuses, comment)
245 261
      Deferred.when(
246 262
        Plugin::Mastodon::API.get_local_account_id(self, statuses.first.account),
plugin/mastodon/spell.rb
61 61
    }
62 62
  end
63 63

  
64
  command(:mastodon_pin_message, name: _('ブックマークする'), visible: true, role: :timeline,
65
          condition: lambda { |opt|
66
            opt.messages.any? { |m| bookmark_message?(opt.world, m) }
67
          }) do |opt|
68
    opt.messages.select{ |m|
69
      bookmark_message?(opt.world, m)
70
    }.each { |status|
71
      opt.world.bookmark(status)
72
    }
73
  end
74

  
75
  command(:mastodon_unpin_message, name: _('ブックマークを解除する'), visible: true, role: :timeline,
76
          condition: lambda { |opt|
77
            opt.messages.any? { |m| unbookmark_message?(opt.world, m) }
78
          }) do |opt|
79
    opt.messages.select{ |m|
80
      unbookmark_message?(opt.world, m)
81
    }.each { |status|
82
      opt.world.unbookmark(status)
83
    }
84
  end
85

  
64 86
  command(:mastodon_edit_list_membership, name: _('リストへの追加・削除'), visible: true, role: :timeline,
65 87
          condition: lambda { |opt|
66 88
            mastodon?(opt.world)
......
470 492
    world.unpin(status)
471 493
  end
472 494

  
495
  defspell(:bookmark_message, :mastodon, :mastodon_status,
496
           condition: -> (world, status) { !status.bookmarked? }
497
          ) do |world, status|
498
    world.bookmark(status)
499
  end
500

  
501
  defspell(:unbookmark_message, :mastodon, :mastodon_status,
502
           condition: -> (world, status) { status.bookmarked? }
503
          ) do |world, status|
504
    world.unbookmark(status)
505
  end
506

  
473 507
  defspell(:mastodon, :mastodon) do |mastodon|
474 508
    true
475 509
  end
plugin/mastodon_rest/mastodon_rest.rb
5 5
    [ new_world.rest.user,
6 6
      new_world.rest.mention,
7 7
      new_world.rest.direct,
8
      new_world.rest.bookmarks,
8 9
      new_world.rest.public,
9 10
      new_world.rest.public_local,
10 11
      new_world.rest.public(only_media: true),
(1-1/2)