Improve question review and image handling
This commit is contained in:
@@ -7,6 +7,7 @@ const DEFAULT_QUESTION_API_BASE_URL := "https://s3q.ranaze.com/api/questions"
|
||||
const DEFAULT_RATINGS_API_URL := "https://s3q.ranaze.com/api/ratings/me"
|
||||
const DEFAULT_QUESTION_REPORTS_API_URL := "https://s3q.ranaze.com/api/question-reports"
|
||||
const RETRY_DELAYS := [2, 5, 10, 20, 30]
|
||||
const IMAGE_QUESTION_SEARCH_LIMIT := 200
|
||||
const ATTEMPT_QUEUE_PATH := "user://pending_question_attempts.json"
|
||||
|
||||
signal questions_changed
|
||||
@@ -44,6 +45,8 @@ var attempt_queue: Array = []
|
||||
var active_attempt_index := -1
|
||||
var attempt_request_active := false
|
||||
var pending_excluded_question_ids: Array = []
|
||||
var pending_require_media := false
|
||||
var image_question_search_attempts := 0
|
||||
|
||||
func _ready() -> void:
|
||||
questions_api_url = EndpointConfig.resolve(
|
||||
@@ -93,13 +96,15 @@ func _ready() -> void:
|
||||
_process_attempt_queue()
|
||||
|
||||
|
||||
func load_questions_from_api(reset_retry: bool = true, excluded_question_ids: Array = []) -> void:
|
||||
func load_questions_from_api(reset_retry: bool = true, excluded_question_ids: Array = [], require_media: bool = false) -> void:
|
||||
if AuthState.access_token.is_empty():
|
||||
_set_load_error("Login required before loading questions.", false)
|
||||
return
|
||||
|
||||
if reset_retry:
|
||||
pending_excluded_question_ids = excluded_question_ids.duplicate()
|
||||
pending_require_media = require_media
|
||||
image_question_search_attempts = 0
|
||||
retry_attempt = 0
|
||||
next_retry_seconds = 0
|
||||
retry_timer.stop()
|
||||
@@ -120,6 +125,7 @@ func load_questions_from_api(reset_retry: bool = true, excluded_question_ids: Ar
|
||||
var payload := {
|
||||
"limit": 1,
|
||||
"supportsChoicePools": true,
|
||||
"requireMedia": pending_require_media,
|
||||
"excludeExternalIds": pending_excluded_question_ids
|
||||
}
|
||||
var err := request.request(questions_api_url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
||||
@@ -147,6 +153,17 @@ func _on_api_questions_loaded(result: int, response_code: int, _headers: PackedS
|
||||
if api_questions.is_empty():
|
||||
_set_load_error("Questions API returned no usable questions.")
|
||||
return
|
||||
if pending_require_media and not _contains_question_with_media(api_questions):
|
||||
for question in api_questions:
|
||||
var question_id := str(question.get("id", ""))
|
||||
if question_id != "" and not pending_excluded_question_ids.has(question_id):
|
||||
pending_excluded_question_ids.append(question_id)
|
||||
image_question_search_attempts += api_questions.size()
|
||||
if image_question_search_attempts >= IMAGE_QUESTION_SEARCH_LIMIT:
|
||||
_set_load_error("No question with an image was found.", false)
|
||||
return
|
||||
call_deferred("load_questions_from_api", false, pending_excluded_question_ids, true)
|
||||
return
|
||||
|
||||
questions = api_questions
|
||||
last_error = ""
|
||||
@@ -168,6 +185,18 @@ func load_next_random_question(excluded_question_ids: Array) -> void:
|
||||
load_questions_from_api(true, excluded_question_ids)
|
||||
|
||||
|
||||
func load_image_question_for_testing() -> void:
|
||||
load_questions_from_api(true, [], true)
|
||||
|
||||
|
||||
func _contains_question_with_media(question_list: Array) -> bool:
|
||||
for question in question_list:
|
||||
var media: Array = question.get("media", [])
|
||||
if not media.is_empty():
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func clear_questions() -> void:
|
||||
if request != null:
|
||||
request.cancel_request()
|
||||
@@ -195,6 +224,8 @@ func clear_questions() -> void:
|
||||
last_rating_change = {}
|
||||
pending_report_question_id = ""
|
||||
pending_excluded_question_ids.clear()
|
||||
pending_require_media = false
|
||||
image_question_search_attempts = 0
|
||||
questions_changed.emit()
|
||||
ratings_changed.emit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user