Get forum fiend working again

main
Nick Thomas 2013-09-29 02:10:41 +01:00
parent 5197e63e0d
commit 9b80bcdcfa
1 changed files with 83 additions and 19 deletions

View File

@ -73,7 +73,7 @@ set :tapatalk_api_key, CONFIG.fetch( 'tapatalk_api_key', nil )
before do
# Pass through all cookies to the discourse instance
discourse( request.cookies )
# TODO: Override on auth failures, cookie timeouts, etc. to set this to false
mobiquo_login_header!( request.cookies.has_key?("_t") )
end
@ -131,7 +131,12 @@ helpers do
def make_xmlrpc_datetime( string )
t = Chronic.parse( string )
::Tapatalk::Time.new( t.year, t.month, t.day, t.hour, t.min, t.sec, t.utc_offset )
if request.env['HTTP_MOBIQUOID'] == "2" || request['HTTP_MOBIQUO_ID'] == "2" # apple
::Tapatalk::Time.new( t.year, t.month, t.day, t.hour, t.min, t.sec, t.utc_offset )
else
t
end
end
def binary_xmlrpc( string )
@ -175,9 +180,19 @@ helpers do
'reply_number' => discourse_topic['posts_count'].to_i, # reply_count ?
'new_post' => !!discourse_topic['unseen'],
'view_number' => discourse_topic['views'].to_i,
'new_post' => false, # TODO
'short_content' => binary_xmlrpc( "" ), # api level 4, not provided by discourse in some calls, TODO
'attachment' => "0",
'can_delete' => false,
'can_move' => false,
'can_close' => false,
'can_stick' => false,
'is_sticky' => false,
'can_approve' => false,
'is_approved' => true,
'can_rename' => false,
# 'short_content' => binary_xmlrpc( "" ) # api level 4, not provided by discourse in some calls, TODO
}
@ -207,7 +222,7 @@ helpers do
# FIXME: how do these differ from post_author_name/id ? most recent / original?
result['topic_author_name'] = result['post_author_name']
result['topic_author_id'] = result['post_author_id'].to_s
result['timestamp'] = result['last_reply_time'].to_i.to_s
result
end
@ -369,12 +384,12 @@ helpers do
respond_xmlrpc(
'result' => true,
'user_id' => user["id"], # api level 4
'username' => binary_xmlrpc( user["username"] ), # api level 4
'user_id' => user["id"].to_s, # api level 4
'username' => binary_xmlrpc( user["username"].to_s ), # api level 4
# 'usergroup_id' => [], # api level 4
# 'email' => binary_xmlrpc( "" ) # api level 4 # not sent by discourse
# 'icon_url' => make_avatar_url( user["avatar_template"] ), # api level 4
# 'post_count' => , # api level 4 # discourse gives back stats with action_type and count members
'post_count' => 0, # api level 4 # discourse gives back stats with action_type and count members
'can_pm' => false, # TODO!
'can_send_pm' => false, # TODO! # can_send_private_message_to_user is always false...?
'can_moderate' => false, # TODO! user["moderator"]
@ -431,17 +446,15 @@ helpers do
'new_post' => true, # TODO
"is_protected" => false, # Not required, apparently
'description' => binary_xmlrpc( hsh['description'].to_s ),
"child" => [],
# "child" => [],
# These are returned by some others
'new_post' => false,
'url' => '',
'logo_url' => '',
'unread_count' => 0, # TODO
}
# FIXME: may not be right?
# if return_description
#
@ -449,6 +462,8 @@ helpers do
tmp
}
result.select! {|cat| cat['parent_id'] == forum_id } if forum_id
respond_xmlrpc( result )
end
@ -501,11 +516,12 @@ helpers do
def xmlrpc_get_topic( forum_id, start_num = 0, last_num = 0, mode = "DATE" )
if forum_id == "0" # && %w|ANN TOP|.include?(mode)
if forum_id == "0"
# In these cases, we're not interested in a particular forum
# TODO! This is for announcements (mode = "ANN")! FIXME!
# TODO: also for latest, like xmlrpc_get_latest_topic! FIXME!
return respond_xmlrpc( 'result' => false )
return xmlrpc_get_latest_topic( start_num, last_num )
end
# TODO: Need to respect pagination, restrict to just one category
@ -527,20 +543,40 @@ helpers do
'topics' => []
}
# Return an empty list for weirdy ones
if mode == "ANN" || mode == "TOP"
return respond_xmlrpc(
'total_topic_num' => 0,
'unread_sticky_count' => 0,
'unread_announce_count' => 0,
'forum_id' => forum_id,
'forum_name' => binary_xmlrpc( category['name'].to_s ),
'can_post' => false,
'can_upload' => false,
'max_attachment' => 0,
'max_png_size' => 0,
'max_jpg_size' => 0,
'topics' => []
)
end
result = {
'forum_id' => category['id'].to_s,
'forum_name' => binary_xmlrpc( category['name'].to_s ),
# 'unread_sticky_count' => 0, # TODO - api level 4
# 'unread_announce_count' => 0,
# 'can_subscribe' => false, # TODO - api level 4
# 'is_subscribed' => false, # TODO - api level 4
# 'require_prefix' => false, # TODO - api level 4
'prefixes' => [],
'prefix_id' => "",
'prefix_display_name' => binary_xmlrpc( "" ),
'can_post' => !!category['can_create_topic'], # FIXME: may not be correct!
'can_upload' => false,
'require_prefix' => false, # api level 4
'max_attachment' => 0,
'max_png_size' => 0,
'max_jpg_size' => 0,
'unread_sticky_count' => 0, # FIXME
'unread_announce_count' => 0,
# 'can_subscribe' => false,
# 'is_subscribed' => false,
# 'require_prefix' => false, # api level 4
}
topic_list = forum_info.fetch( "topic_list" )
@ -548,9 +584,29 @@ helpers do
result['topics'] = topic_list.fetch( "topics" ).collect {|hsh|
build_tapatalk_topic( hsh, :users => users, :categories => categories )
}
=begin
good_keys = %w{
forum_id topic_id topic_title prefix topic_author_id topic_author_name
is_subscribed can_subscribe is_closed icon_url last_reply_time reply_number
new_post view_number short_content participated_uids
}
# Some of these aren't documented for get_topic
result['topics'].each do |topic|
topic.keys.each do |key|
if !good_keys.include?( key )
# puts "#{key} set to #{topic[key]}, deleting"
topic.delete( key )
end
end
end
=end
result['total_topic_num'] = result['topics'].count
# pp result
respond_xmlrpc( result )
end
@ -719,3 +775,11 @@ end
post "/mobiquo/mobiquo.php" do
dispatch
end
get "/" do
halt 200, "Tapatalk endpoint"
end
get "/mobiquo/mobiquo.php" do
halt 200, "Tapatalk endpoint"
end