mcfearsome (owner)

Revisions

gist: 115680 Download_button fork
public
Public Clone URL: git://gist.github.com/115680.git
Embed All Files: show embed
snippet.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class NewNotifications
  extend ActionView::Helpers::TagHelper
  extend ActionView::Helpers::UrlHelper
 
  def self.call(env)
    session = env['rack.session']
    if env["PATH_INFO"] =~ /^\/metal\/new_notifications/ and !session[:user].nil?
      user = User.find_by_token(session[:user])
      notifications = TimelineEvent.new.forUser(user)
      unless notifications.nil?
        r = notifications.map do |n|
          begin
            item = "<li>#{self.send(n.event_type.to_sym, n)}</li>"
          rescue
            next
          end
          item
        end
        r = "<ul>#{r}</ul>"
      else
        r = ""
      end
      [200, {"Content-Type" => "text/html"}, [r]]
    else
      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
    end
  end
 
  def self.message_notification(timeline_event)
    "#{link_to(timeline_event.actor.display_name, "/gamer/#{timeline_event.actor.token}")} sent you a #{link_to('message',"/messages/#{timeline_event.subject.id}")}! <span class='date'>#{timeline_event.created_at.to_s("%m/%d/%y")}</span>"
  end
end