Permalink
Browse files

Merge branch 'master' of git@github.com:nahi/ffp

  • Loading branch information...
2 parents b2165b5 + c37c338 commit 52b125e7d8d3033a8a82367c76a87ead21ff401f NAKAMURA committed Jan 27, 2009
View
@@ -8,3 +8,8 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
+
+task 'tags' do
+ chdir 'app'
+ sh 'rtags --vi **/*.rb'
+end
@@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
# filter_parameter_logging :password
+ session_options[:session_expires] = Time.mktime(2030, 12, 31)
def self.ff_client
@@ff ||= FriendFeed::APIClient.new
@@ -1,7 +1,7 @@
class EntryController < ApplicationController
before_filter :login_required
- NUM_DEFAULT = '15'
+ NUM_DEFAULT = '20'
verify :only => :list,
:method => :get,
@@ -74,7 +74,7 @@ def add
if body
ff_client.post(@auth.name, @auth.remote_key, body, link, nil, nil, nil, room)
end
- redirect_to :action => 'list'
+ redirect_to :action => 'list', :room => room
end
verify :only => :delete,
@@ -107,10 +107,8 @@ def undelete
def do_delete(id, comment = nil, undelete = false)
if comment and !comment.empty?
- logger.info([id, comment, undelete].inspect)
ff_client.delete_comment(@auth.name, @auth.remote_key, id, comment, undelete)
else
- logger.info([id, comment, undelete].inspect)
ff_client.delete(@auth.name, @auth.remote_key, id, undelete)
end
end
@@ -129,4 +127,32 @@ def add_comment
end
redirect_to :action => 'list'
end
+
+ verify :only => :like,
+ :method => :get,
+ :params => [:id],
+ :add_flash => {:error => 'verify failed'},
+ :redirect_to => {:action => 'list'}
+
+ def like
+ eid = params[:id]
+ if eid
+ ff_client.like(@auth.name, @auth.remote_key, eid)
+ end
+ redirect_to :action => 'list'
+ end
+
+ verify :only => :unlike,
+ :method => :get,
+ :params => [:id],
+ :add_flash => {:error => 'verify failed'},
+ :redirect_to => {:action => 'list'}
+
+ def unlike
+ eid = params[:id]
+ if eid
+ ff_client.unlike(@auth.name, @auth.remote_key, eid)
+ end
+ redirect_to :action => 'list'
+ end
end
@@ -50,7 +50,7 @@ def via(via)
end
def image_size(width, height)
- "#{h(width)}x#{h(height)}"
+ "#{width}x#{height}"
end
def date(time, compact = true)
@@ -92,7 +92,7 @@ def link_url(url)
end
def q(str)
- %Q["#{str}"]
+ h('"') + str + h('"')
end
def v(hash, *keywords)
@@ -44,13 +44,15 @@ def common_content(entry)
title = v(entry, 'title')
link = v(entry, 'link')
if link and with_link?(v(entry, 'service'))
- content = link_to(h(q(title)), link)
+ content = link_to(q(h(title)), link)
else
- content = h(q(title))
+ content = q(pickup_link(h(title)))
end
medias = v(entry, 'media')
if medias and !medias.empty?
- content += "<br/>\n" + content_with_media(title, medias)
+ # entries from Hatena contains 'enclosure' but no title and link for now.
+ with_media = content_with_media(title, medias)
+ content += "<br/>\n" + with_media unless with_media.empty?
end
content
end
@@ -66,20 +68,24 @@ def content_with_media(title, medias)
media_title = v(media, 'title')
media_link = v(media, 'link')
tbs = v(media, 'thumbnails')
- if tbs and !tbs.empty?
- safe_content = tbs.collect { |tb|
- tb_url = v(tb, 'url')
- tb_width = v(tb, 'width')
- tb_height = v(tb, 'height')
- if tb_url
- image_tag(tb_url,
- :alt => h(media_title), :size => image_size(tb_width, tb_height))
- end
- }.join(' ')
- else
+ safe_content = nil
+ if tbs and tbs.first
+ tb = tbs.first
+ tb_url = v(tb, 'url')
+ tb_width = v(tb, 'width')
+ tb_height = v(tb, 'height')
+ if tb_url
+ safe_content = image_tag(tb_url,
+ :alt => h(media_title), :size => image_size(tb_width, tb_height))
+ end
+ elsif media_title
safe_content = h(media_title)
end
- link_to(safe_content, media_link)
+ if safe_content
+ link_to(safe_content, media_link)
+ elsif media_link
+ link_to(media_link)
+ end
}.join(' ')
end
@@ -105,14 +111,16 @@ def brightkite_content(common, entry)
end
end
- # TODO: uglish
def twitter_content(common, entry)
- common = common.sub(/\A&quot;(.*)&quot;\z/) { $1 }
- common = common.gsub(/((?:http|https):\/\/\S+)/) { link_to(h($1), $1) }
- common = common.gsub(/@([a-zA-Z0-9_]+)/) {
+ common.gsub(/@([a-zA-Z0-9_]+)/) {
link_to('@' + $1, "http://twitter.com/#{$1}")
}
- '&quot;' + common + '&quot;'
+ end
+
+ def pickup_link(content)
+ if content
+ content.gsub(/((?:http|https):\/\/\S+)/) { link_to(h($1), $1) }
+ end
end
def via(entry)
@@ -148,10 +156,10 @@ def delete_icon
end
def comment(comment)
- h(v(comment, 'body'))
+ pickup_link(h(v(comment, 'body')))
end
- def post_comment_form
+ def post_entry_form
str = ''
room = (@room != '*') ? @room : nil
if room
@@ -162,6 +170,10 @@ def post_comment_form
str
end
+ def post_comment_form
+ text_field_tag('body') + submit_tag('post')
+ end
+
def logout_link
link_to(h('[logout]'), :controller => 'login', :action => 'clear')
end
@@ -207,7 +219,7 @@ def delete_link(entry)
eid = v(entry, 'id')
name = v(entry, 'user', 'nickname')
if name == @auth.name
- link_to(delete_icon, {:action => 'delete', :id => u(eid)}, :confirm => 'Are you sure?')
+ link_to(h('[delete]'), {:action => 'delete', :id => u(eid)}, :confirm => 'Are you sure?')
end
end
@@ -220,7 +232,20 @@ def delete_comment_link(entry, comment)
cid = v(comment, 'id')
name = v(comment, 'user', 'nickname')
if name == @auth.name
- link_to(delete_icon, {:action => 'delete', :id => u(eid), :comment => u(cid)}, :confirm => 'Are you sure?')
+ link_to(h('[delete]'), {:action => 'delete', :id => u(eid), :comment => u(cid)}, :confirm => 'Are you sure?')
+ end
+ end
+
+ def like_link(entry)
+ eid = v(entry, 'id')
+ name = v(entry, 'user', 'nickname')
+ if name != @auth.name
+ likes = v(entry, 'likes')
+ if likes and likes.find { |like| v(like, 'user', 'nickname') == @auth.name }
+ link_to(h('[un-like]'), :action => 'unlike', :id => u(eid))
+ else
+ link_to(h('[like]'), :action => 'like', :id => u(eid))
+ end
end
end
@@ -245,7 +270,7 @@ def fold(entries)
seq = 0
prev = nil
entries.each do |entry|
- pair = [v(entry, 'user', 'nickname'), v(entry, 'service', 'id')]
+ pair = [v(entry, 'user', 'nickname'), v(entry, 'service', 'id'), v(entry, 'room')]
if pair == prev
seq += 1
else
@@ -261,4 +286,14 @@ def fold(entries)
end
result
end
+
+ def fold_comments(comments)
+ if @compact and comments.size > 3
+ result = comments.values_at(0, -2, -1)
+ result[1, 0] = Fold.new(comments.size - 3)
+ result
+ else
+ comments
+ end
+ end
end
@@ -17,7 +17,7 @@
<% end %>
<% if @post %>
<% form_tag(:action => 'add') do %>
- <p><%= post_comment_form %> <%= logout_link %></p>
+ <p><%= post_entry_form %> <%= logout_link %></p>
<% end %>
<% end %>
<%= page_links %>
@@ -26,9 +26,7 @@
(@entry_fold ? fold(@entries) : @entries).each do |entry|
if entry.respond_to?(:fold_entries)
%>
- <ul>
- <li><%= link_to(h("#{entry.fold_entries} entrie(s) from same service"), list_opt(:action => 'list', :start => @start, :num => @num, :fold => 'no')) %></li>
- </ul>
+ <li><%= link_to(h("#{entry.fold_entries} entry(es) from same service"), list_opt(:action => 'list', :start => @start, :num => @num, :fold => 'no')) %></li>
<%
next
end
@@ -42,14 +40,19 @@
<%= via(entry) %>
<%= likes(entry) %>
<%= delete_link(entry) %>
+ <%= like_link(entry) %>
<% comments = v(entry, 'comments') %>
<% if comments and !comments.empty? %>
<ul>
- <% if @compact and comments.size > 4 %>
- <li><%= link_to("#{comments.size - 3} more comment(s)", :action => 'show', :id => u(v(entry, 'id'))) %></li>
- <% comments = comments[-3, 3] %>
- <% end %>
- <% comments.each do |c| %>
+ <%
+ fold_comments(comments).each do |c|
+ if c.respond_to?(:fold_entries)
+ %>
+ <li><%= link_to("#{c.fold_entries} more comment(s)", :action => 'show', :id => u(v(entry, 'id'))) %></li>
+ <%
+ next
+ end
+ %>
<li>
<%= date(v(c, 'date'), @compact) %></a>
<%= comment(c) %>
@@ -65,9 +68,7 @@
<% end %>
<% if @post_comment %>
<% form_tag(:action => 'add_comment', :id => u(@eid)) do %>
- <p>
- <%= text_field_tag('body') %> <%= submit_tag('post') %>
- </p>
+ <p><%= post_comment_form %></p>
<% end %>
<% end %>
</li>
@@ -21,11 +21,11 @@
<hr/>
<p>Bear in mind...</p>
<ul>
- <li>Do not enter your FriendFeed PASSWORD here. You can check <%= link_to('your remote key', 'https://friendfeed.com/account/api') %> by yourself.</li>
+ <li>Do NOT enter your FriendFeed PASSWORD here. You can check <%= link_to('your remote key', 'https://friendfeed.com/account/api') %> by yourself.</li>
<li>NO WARRANTY; This service is provided on an "AS IS" basis without warranty of any kind.</li>
<li>The pairs of nickname and remote key are stored in DB of this server for accessing FriendFeed API.</li>
<li>Your feed is NOT stored in the DB.</li>
- <li>Let me know if you have any trouble on this service at <%= link_url('http://friendfeed.com/ffpd') %>.</li>
+ <li>Let me know about any trouble on this service at <%= link_url('http://friendfeed.com/ffpd') %>.</li>
</ul>
<hr/>
<p>NAKAMURA, Hiroshi a.k.a. NaHi - <%= link_url('http://friendfeed.com/nahi') %></p>
View
@@ -36,6 +36,7 @@
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
# map.root :controller => "welcome"
+ map.root :controller => 'entry'
# See how all your routes lay out with "rake routes"
View
@@ -130,6 +130,22 @@ def delete_comment(name, remote_key, entry, comment, undelete = false)
end
end
+ def like(name, remote_key, entry)
+ uri = uri("like")
+ query = {'entry' => entry}
+ client_sync(uri, name, remote_key) do |client|
+ client.post(uri, query)
+ end
+ end
+
+ def unlike(name, remote_key, entry)
+ uri = uri("like/delete")
+ query = {'entry' => entry}
+ client_sync(uri, name, remote_key) do |client|
+ client.post(uri, query)
+ end
+ end
+
private
def uri(part)
@@ -158,6 +174,5 @@ def get_feed(client, uri, query = {})
remote_key = ARGV.shift or raise
client = FriendFeed::APIClient.new
require 'pp'
- #pp client.get_home_entries(name, remote_key)
- pp client.get_rooms(name, remote_key)
+ pp client.get_home_entries(name, remote_key)
end
Oops, something went wrong.

0 comments on commit 52b125e

Please sign in to comment.