プロジェクト

全般

プロフィール

バグ #916 » api_shortcuts.rb.diff

Izumi Tsutsui, 2017-12-24 22:52

差分を表示:

core/plugin/twitter/mikutwitter/api_shortcuts.rb
52 52
  defcursorpager :followers_id, 'followers/ids', :paged_ids, :ids, id: :user_id
53 53

  
54 54
  def followings(args = {})
55
    idlist2userlist(friends_id(RELATIONAL_DEFAULT.merge(args))) end
55
    idlist2userlist(friends_id(RELATIONAL_DEFAULT.merge(args)), cache: args[:cache]) end
56 56

  
57 57
  def followers(args = {})
58
    idlist2userlist(followers_id(RELATIONAL_DEFAULT.merge(args))) end
58
    idlist2userlist(followers_id(RELATIONAL_DEFAULT.merge(args)), cache: args[:cache]) end
59 59

  
60 60
  def direct_messages(args = {})
61 61
    (self/:direct_messages).direct_messages({:count => 200}.merge(args)) end
......
260 260
        cursor_pager(api, parser, key, args.merge(cursor: res[:next_cursor])).next{ |nex|
261 261
          res[key] + nex } end } end
262 262

  
263
  def idlist2userlist(deferred)
264
    deferred.next{ |ids|
265
      promise = Deferred.new(true)
266
      Thread.new{
267
        begin
268
          promise.call(Plugin::Twitter::User.findbyid(ids))
269
        rescue Exception => e
270
          promise.fail(e) end }
271
      promise.next{ |users|
272
        if(users.size != ids.size)
273
          Deferred.when(*(ids - users.map{ |u| u[:id] }).each_slice(100).map{ |segment|
274
                          user_lookup(id: segment.join(',')).trap{ |e| warn e; [] } }).next{ |res|
275
            res.inject(users){ |a, b| a + b } }
263
  def idlist2userlist(deferred, cache: :keep)
264
    deferred.next do |ids|
265
      detected = {}           # {id => User}
266
      lookups = Set.new       # [id]
267
      ids.each do |id|
268
        user = Plugin::Twitter::User.findbyid(id, Diva::DataSource::USE_LOCAL_ONLY)
269
        if user.is_a? User
270
          detected[id] = user
276 271
        else
277
          users end } } end
272
          lookups << id
273
        end
274
      end
275
      defer = lookups.each_slice(100).map{|lookup_chunk|
276
        user_lookup(id: lookup_chunk.join(','), cache: cache).next{|users|
277
          users.each do |user|
278
            detected[user.id] = user
279
          end
280
        }
281
      }
282
      Delayer::Deferred.when(*defer).next do
283
        ids.map{|id| detected[id] }
284
      end
285
    end
286
  end
278 287

  
279 288
  # upload.twitter.comに画像等をアップロードし、
280 289
  # アップロードしたファイルのmedia_idを返す。
(1-1/2)