Class: T2Server::Interaction::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/t2-server/interaction.rb

Instance Method Summary collapse

Constructor Details

#initialize(run) ⇒ Feed

Returns a new instance of Feed.



49
50
51
52
# File 'lib/t2-server/interaction.rb', line 49

def initialize(run)
  @run = run
  @cache = {:requests => {}, :replies => {}}
end

Instance Method Details

#new_requestsObject

Get all new notification requests since they were last checked.

Here we really only want new unanswered notifications, but polling returns all requests new to us, even those that have been replied to elsewhere. Filter out answered requests here.



59
60
61
# File 'lib/t2-server/interaction.rb', line 59

def new_requests
  poll(:requests).select { |i| !i.has_reply? }
end

#notifications(type = :all) ⇒ Object

Get all notifications, or all of a particular type.



64
65
66
67
68
69
70
71
72
73
# File 'lib/t2-server/interaction.rb', line 64

def notifications(type = :all)
  poll

  case type
  when :requests, :replies
    @cache[type].values
  else
    @cache[:requests].values + @cache[:replies].values
  end
end