diff --git a/lib/tapatalker.rb b/lib/tapatalker.rb index 6e3d437..9001d2d 100644 --- a/lib/tapatalker.rb +++ b/lib/tapatalker.rb @@ -101,6 +101,7 @@ helpers do 'reply_number' => discourse_topic['posts_count'].to_i, # reply_count ? 'new_post' => !!discourse_topic['unseen'], 'view_number' => discourse_topic['views'].to_i, + # 'short_content' => binary_xmlrpc( "" ) # api level 4, not provided by discourse in some calls } @@ -124,11 +125,16 @@ helpers do end end + + # 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['last_reply_time'] = result["post_time"] result end - # Try to keep this instance around for as long as possible... # TODO: To keep it around, push into Rack::Session, or cookies? Some sort of # long-lived store. Can go away with process restarts, of course. @@ -313,22 +319,25 @@ helpers do def xmlrpc_get_topic( forum_id, start_num = 0, last_num = 0, mode = "DATE" ) - category = if forum_id == "0" && %w|ANN TOP|.include?(mode) + if forum_id == "0" # && %w|ANN TOP|.include?(mode) # In these cases, we're not interested in a particular forum # TODO! This is for announcements (mode = "ANN")! FIXME! - nil - else - # FIXME: Wasteful! - # Normal-ish mode - # TODO: Need to respect pagination, restrict to just one category - forum_info = discourse.categories({}) - category_list = forum_info.fetch( "category_list" ) - categories = category_list.fetch( "categories" ) - cat = categories.find {|hsh| hsh['id'].to_s == forum_id } - cat['can_create_topic'] = category_list['can_create_topic'] if cat # monkey-patch this in - cat + # TODO: also for latest, like xmlrpc_get_latest_topic! FIXME! + return respond_xmlrpc( 'result' => false ) end + # TODO: Need to respect pagination, restrict to just one category + forum_info = discourse.category(:category_id => forum_id) + + pp forum_info + + categories = forum_info.fetch( "categories" ) + users = forum_info["users"] + + categories.each {|hsh| hsh["can_create_topic"] = forum_info["topic_list"]["can_create_topic"] } + + category = categories.find {|hsh| hsh["id"].to_s == forum_id } + # Null category to handle failure-to-find cases above category ||= { 'topic_count' => 0, @@ -341,44 +350,27 @@ helpers do result = { 'total_topic_num' => category['topic_count'].to_i, 'forum_id' => category['id'].to_s, - 'forum_name' => category['name'].to_s, - 'can_subscribe' => false, # TODO - 'is_subscribed' => false, # TODO - 'require_prefix' => false, + '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' => "", + 'prefix_display_name' => binary_xmlrpc( "" ), 'can_post' => !!category['can_create_topic'], # FIXME: may not be correct! 'can_upload' => false, - 'require_prefix' => false, + # 'require_prefix' => false, # api level 4 } - result['topics'] = category['topics'].collect {|hsh| - next if hsh['archived'] - - tmp = { "forum_id" => category["id"].to_s, - "topic_id" => hsh["id"].to_s, - "topic_title" => hsh["title"].to_s, - "prefix" => "", - "topic_author_id" => "0", # FIXME: This isn't included by discourse?! - "topic_author_name" => "(Unknown)", # FIXME: this either! - "is_subscribed" => false, - "can_subscribe" => false, - "is_closed" => !!hsh["closed"], - "last_reply_time" => make_xmlrpc_datetime( hsh["last_posted_at"] ), # FIXME: Doesn't seem to like being a DateTime? - "reply_number" => category["posts_count"].to_i, - "new_post" => !!category["unseen"], - "view_number" => 0, # FIXME: Isn't included in above - "short_content" => "", - } - - ## Srs bsns - # if request.headers["Mobiquoid"] == "11" - # tmp["participated_uids"] = [] - # end - - tmp - }.compact + topic_list = forum_info.fetch( "topic_list" ) + + result['topics'] = topic_list.fetch( "topics" ).collect {|hsh| + build_tapatalk_topic( hsh, :users => users, :categories => categories ) + } + + pp result respond_xmlrpc( result ) end