Get thread view working properly in the official tapatalk client
You can now browse by category and read any thread. Pagination is a bit strange so I've not dealt with it yet - discourse goes by page number, whereas tapatalk asks for ranges of posts - so that needs fixing In The Future. We're probably in a state to begin looking at push notifications now
This commit is contained in:
@@ -101,6 +101,7 @@ helpers do
|
|||||||
'reply_number' => discourse_topic['posts_count'].to_i, # reply_count ?
|
'reply_number' => discourse_topic['posts_count'].to_i, # reply_count ?
|
||||||
'new_post' => !!discourse_topic['unseen'],
|
'new_post' => !!discourse_topic['unseen'],
|
||||||
'view_number' => discourse_topic['views'].to_i,
|
'view_number' => discourse_topic['views'].to_i,
|
||||||
|
|
||||||
# 'short_content' => binary_xmlrpc( "" ) # api level 4, not provided by discourse in some calls
|
# 'short_content' => binary_xmlrpc( "" ) # api level 4, not provided by discourse in some calls
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -124,11 +125,16 @@ helpers do
|
|||||||
end
|
end
|
||||||
|
|
||||||
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
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Try to keep this instance around for as long as possible...
|
# 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
|
# 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.
|
# 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" )
|
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
|
# In these cases, we're not interested in a particular forum
|
||||||
# TODO! This is for announcements (mode = "ANN")! FIXME!
|
# TODO! This is for announcements (mode = "ANN")! FIXME!
|
||||||
nil
|
# TODO: also for latest, like xmlrpc_get_latest_topic! FIXME!
|
||||||
else
|
return respond_xmlrpc( 'result' => false )
|
||||||
# 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
|
|
||||||
end
|
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
|
# Null category to handle failure-to-find cases above
|
||||||
category ||= {
|
category ||= {
|
||||||
'topic_count' => 0,
|
'topic_count' => 0,
|
||||||
@@ -341,44 +350,27 @@ helpers do
|
|||||||
result = {
|
result = {
|
||||||
'total_topic_num' => category['topic_count'].to_i,
|
'total_topic_num' => category['topic_count'].to_i,
|
||||||
'forum_id' => category['id'].to_s,
|
'forum_id' => category['id'].to_s,
|
||||||
'forum_name' => category['name'].to_s,
|
'forum_name' => binary_xmlrpc( category['name'].to_s ),
|
||||||
'can_subscribe' => false, # TODO
|
# 'unread_sticky_count' => 0, # TODO - api level 4
|
||||||
'is_subscribed' => false, # TODO
|
# 'unread_announce_count' => 0,
|
||||||
'require_prefix' => false,
|
# 'can_subscribe' => false, # TODO - api level 4
|
||||||
|
# 'is_subscribed' => false, # TODO - api level 4
|
||||||
|
# 'require_prefix' => false, # TODO - api level 4
|
||||||
'prefixes' => [],
|
'prefixes' => [],
|
||||||
'prefix_id' => "",
|
'prefix_id' => "",
|
||||||
'prefix_display_name' => "",
|
'prefix_display_name' => binary_xmlrpc( "" ),
|
||||||
'can_post' => !!category['can_create_topic'], # FIXME: may not be correct!
|
'can_post' => !!category['can_create_topic'], # FIXME: may not be correct!
|
||||||
'can_upload' => false,
|
'can_upload' => false,
|
||||||
'require_prefix' => false,
|
# 'require_prefix' => false, # api level 4
|
||||||
}
|
}
|
||||||
|
|
||||||
result['topics'] = category['topics'].collect {|hsh|
|
topic_list = forum_info.fetch( "topic_list" )
|
||||||
next if hsh['archived']
|
|
||||||
|
result['topics'] = topic_list.fetch( "topics" ).collect {|hsh|
|
||||||
tmp = { "forum_id" => category["id"].to_s,
|
build_tapatalk_topic( hsh, :users => users, :categories => categories )
|
||||||
"topic_id" => hsh["id"].to_s,
|
}
|
||||||
"topic_title" => hsh["title"].to_s,
|
|
||||||
"prefix" => "",
|
pp result
|
||||||
"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
|
|
||||||
|
|
||||||
respond_xmlrpc( result )
|
respond_xmlrpc( result )
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user