diff --git a/Client/origin-client/scenes/account/account_screen.gd b/Client/origin-client/scenes/account/account_screen.gd index 316f199..a27202f 100644 --- a/Client/origin-client/scenes/account/account_screen.gd +++ b/Client/origin-client/scenes/account/account_screen.gd @@ -44,8 +44,8 @@ func _on_profile_ok(p: Variant) -> void: func _load_notifications() -> void: loading_label.visible = true + loading_label.text = "Loading…" empty_label.visible = false - loading_label.text = "Loading…" for c in mailbox_list.get_children(): c.queue_free() @@ -72,78 +72,91 @@ func _on_notifications_ok(p: Variant) -> void: var row := NOTIF_ROW.instantiate() mailbox_list.add_child(row) row.setup(nd) - row.open_requested.connect(_open_notification) - row.reply_requested.connect(_reply_to_notification) - row.delete_requested.connect(_delete_notification) - row.mark_read_requested.connect(_mark_notification_read) + row.open_requested.connect(_on_open_notification) + row.reply_requested.connect(_on_reply_notification) + row.delete_requested.connect(_on_delete_notification) + row.mark_read_requested.connect(_on_mark_read_notification) -func _mark_notification_read(notification_id: String) -> void: +func _on_mark_read_notification(notification_id: String) -> void: if notification_id.is_empty(): return - Network.request( "chat.notifications.read", { "notificationIds": [notification_id] }, func(_t: String, _p: Variant): _load_notifications(), - func(_c: String, _m: String): _load_notifications() + func(_c: String, _m: String): pass ) -func _delete_notification(notification_id: String) -> void: +func _on_delete_notification(notification_id: String) -> void: if notification_id.is_empty(): return - Network.request( "chat.notifications.delete", { "notificationIds": [notification_id] }, func(_t: String, _p: Variant): _load_notifications(), - func(_c: String, _m: String): _load_notifications() + func(_c: String, _m: String): pass ) -func _open_notification(notification: Dictionary) -> void: - var id := str(notification.get("id", "")) - if not id.is_empty() and notification.get("readAt", null) == null: - _mark_notification_read(id) - +func _on_open_notification(notification: Dictionary) -> void: _show_notification_dialog(notification, false) -func _reply_to_notification(notification: Dictionary) -> void: +func _on_reply_notification(notification: Dictionary) -> void: _show_notification_dialog(notification, true) func _show_notification_dialog(notification: Dictionary, focus_reply: bool) -> void: + var notification_id := str(notification.get("id", "")) + if not notification_id.is_empty() and notification.get("readAt", null) == null: + _on_mark_read_notification(notification_id) + var dialog := AcceptDialog.new() - dialog.title = str(notification.get("title", "Mailbox Message")) + dialog.title = str(notification.get("title", "Mailbox")) dialog.ok_button_text = "Close" - dialog.min_size = Vector2(700, 500) + dialog.min_size = Vector2(680, 520) + add_child(dialog) var root := VBoxContainer.new() - root.custom_minimum_size = Vector2(660, 440) + root.size_flags_vertical = Control.SIZE_EXPAND_FILL + root.size_flags_horizontal = Control.SIZE_EXPAND_FILL root.add_theme_constant_override("separation", 8) dialog.add_child(root) var body := RichTextLabel.new() - body.fit_content = false - body.scroll_active = true - body.custom_minimum_size = Vector2(0, 220) body.size_flags_vertical = Control.SIZE_EXPAND_FILL - body.bbcode_enabled = true - body.text = _build_notification_text(notification) + body.bbcode_enabled = false + body.fit_content = false + body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + body.text = str(notification.get("body", "")) root.add_child(body) - var thread_status := Label.new() - thread_status.modulate = Color(0.7, 0.7, 0.75) - thread_status.text = "" - root.add_child(thread_status) + var thread_info := _extract_bug_report_payload(notification) + var bug_report_id := str(thread_info.get("bugReportId", "")) - var reply_box := TextEdit.new() - reply_box.custom_minimum_size = Vector2(0, 100) - reply_box.placeholder_text = "Write a reply to support..." - reply_box.visible = false - root.add_child(reply_box) + var divider := HSeparator.new() + root.add_child(divider) + + var response_title := Label.new() + response_title.text = "Thread" + response_title.modulate = Color(0.8, 0.8, 0.9) + root.add_child(response_title) + + var response_log := RichTextLabel.new() + response_log.size_flags_vertical = Control.SIZE_EXPAND_FILL + response_log.bbcode_enabled = false + response_log.fit_content = false + response_log.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + response_log.text = "Loading thread…" if not bug_report_id.is_empty() else "No support thread is attached to this message." + root.add_child(response_log) + + var reply_edit := TextEdit.new() + reply_edit.custom_minimum_size = Vector2(0, 100) + reply_edit.placeholder_text = "Reply to support…" + reply_edit.visible = not bug_report_id.is_empty() + root.add_child(reply_edit) var actions := HBoxContainer.new() actions.add_theme_constant_override("separation", 8) @@ -151,144 +164,108 @@ func _show_notification_dialog(notification: Dictionary, focus_reply: bool) -> v var send_btn := Button.new() send_btn.text = "Send Reply" - send_btn.visible = false + send_btn.visible = not bug_report_id.is_empty() actions.add_child(send_btn) var delete_btn := Button.new() - delete_btn.text = "Delete" + delete_btn.text = "Delete Message" delete_btn.modulate = Color(1.0, 0.5, 0.5) - delete_btn.pressed.connect(func() -> void: - var nid := str(notification.get("id", "")) - if not nid.is_empty(): - _delete_notification(nid) - dialog.queue_free()) actions.add_child(delete_btn) - add_child(dialog) - dialog.popup_centered() + if not bug_report_id.is_empty(): + _load_bug_report_thread(bug_report_id, response_log) - var parsed := _parse_payload(notification) - var bug_report_id := str(parsed.get("bugReportId", "")) - var can_reply := str(notification.get("notificationType", "")) == "admin_response" and not bug_report_id.is_empty() - - if can_reply: - reply_box.visible = true - send_btn.visible = true - thread_status.text = "Loading conversation…" - _load_bug_report_thread_into(body, thread_status, bug_report_id) - - send_btn.pressed.connect(func() -> void: - var content := reply_box.text.strip_edges() - if content.is_empty(): - thread_status.text = "Reply cannot be empty." - thread_status.modulate = Color(1.0, 0.5, 0.5) - return - send_btn.disabled = true - thread_status.text = "Sending reply…" - thread_status.modulate = Color(0.7, 0.7, 0.75) - Network.request( - "support.reply_bug_report", - { "bugReportId": bug_report_id, "content": content }, - func(_t: String, _p: Variant): - reply_box.text = "" - send_btn.disabled = false - thread_status.text = "Reply sent." - thread_status.modulate = Color(0.5, 0.9, 0.5) - _load_bug_report_thread_into(body, thread_status, bug_report_id), - func(code: String, msg: String): - send_btn.disabled = false - thread_status.text = "Reply failed (%s): %s" % [code, msg] - thread_status.modulate = Color(1.0, 0.5, 0.5) - ) + send_btn.pressed.connect(func() -> void: + var content := reply_edit.text.strip_edges() + if content.is_empty() or bug_report_id.is_empty(): + return + send_btn.disabled = true + Network.request( + "support.reply_bug_report", + { + "bugReportId": bug_report_id, + "content": content, + }, + func(_t: String, _p: Variant): + reply_edit.text = "" + send_btn.disabled = false + _load_bug_report_thread(bug_report_id, response_log), + func(code: String, msg: String): + send_btn.disabled = false + response_log.text += "\n\n[Reply failed: %s] %s" % [code, msg] ) - if focus_reply: - reply_box.grab_focus() - - -func _load_bug_report_thread_into(body: RichTextLabel, status_label: Label, bug_report_id: String) -> void: - Network.request( - "support.get_bug_report_thread", - { "bugReportId": bug_report_id }, - func(_t: String, p: Variant): - var thread := (p as Dictionary).get("thread", {}) as Dictionary - if thread.is_empty(): - status_label.text = "No conversation details available." - status_label.modulate = Color(1.0, 0.5, 0.5) - return - body.text = _build_thread_text(thread) - status_label.text = "" - , - func(code: String, msg: String): - status_label.text = "Failed to load thread (%s): %s" % [code, msg] - status_label.modulate = Color(1.0, 0.5, 0.5) ) + delete_btn.pressed.connect(func() -> void: + _on_delete_notification(notification_id) + dialog.queue_free() + ) -func _build_notification_text(notification: Dictionary) -> String: - var lines: Array[String] = [] - lines.append("[b]%s[/b]" % str(notification.get("title", "Mailbox Message"))) - lines.append(str(notification.get("body", ""))) - lines.append("") - lines.append("Type: %s" % str(notification.get("notificationType", "unknown"))) - lines.append("Created: %s" % _format_timestamp(str(notification.get("createdAt", "")))) - return "\n".join(lines) + dialog.popup_centered() + if focus_reply and reply_edit.visible: + reply_edit.grab_focus() -func _build_thread_text(thread: Dictionary) -> String: - var lines: Array[String] = [] - lines.append("[b]Support Thread[/b]") - lines.append("Subject: %s" % str(thread.get("title", ""))) - lines.append("Status: %s" % str(thread.get("status", "Open"))) - lines.append("Category: %s" % str(thread.get("category", "other"))) - lines.append("Created: %s" % _format_timestamp(str(thread.get("createdAt", "")))) - lines.append("") - lines.append("[b]Original Report[/b]") - lines.append(str(thread.get("description", ""))) - var steps := str(thread.get("stepsToReproduce", "")) - if not steps.is_empty(): - lines.append("") - lines.append("[b]Steps to Reproduce[/b]") - lines.append(steps) - - var responses : Array = thread.get("responses", []) as Array - if not responses.is_empty(): - lines.append("") - lines.append("[b]Conversation[/b]") - for r in responses: - var rd := r as Dictionary - lines.append("\n• [b]%s[/b] (%s)" % [ - str(rd.get("authorDisplayName", "Support")), - _format_timestamp(str(rd.get("createdAt", ""))) - ]) - lines.append(str(rd.get("content", ""))) - - return "\n".join(lines) - - -func _parse_payload(notification: Dictionary) -> Dictionary: - var payload_json := str(notification.get("payloadJson", "")) - if payload_json.is_empty(): +func _extract_bug_report_payload(notification: Dictionary) -> Dictionary: + var payload_raw := notification.get("payloadJson", null) + if payload_raw == null: return {} - var parsed := JSON.parse_string(payload_json) + + var payload_text := str(payload_raw) + if payload_text.is_empty(): + return {} + + var parsed := JSON.parse_string(payload_text) if typeof(parsed) == TYPE_DICTIONARY: return parsed as Dictionary return {} -func _format_timestamp(iso: String) -> String: - if iso.is_empty(): - return "—" - var t_idx := iso.find("T") - if t_idx < 0: - return iso - var day := iso.substr(0, t_idx) - var time_part := iso.substr(t_idx + 1) - var z_idx := time_part.find("Z") - if z_idx >= 0: - time_part = time_part.substr(0, z_idx) - if time_part.length() >= 5: - time_part = time_part.substr(0, 5) - return "%s %s" % [day, time_part] +func _load_bug_report_thread(bug_report_id: String, out_log: RichTextLabel) -> void: + Network.request( + "support.get_bug_report_thread", + { "bugReportId": bug_report_id }, + func(_t: String, p: Variant): + var thread := (p as Dictionary).get("thread", {}) as Dictionary + out_log.text = _format_thread_text(thread), + func(code: String, msg: String): + out_log.text = "Failed to load support thread.\n[%s] %s" % [code, msg] + ) + + +func _format_thread_text(thread: Dictionary) -> String: + if thread.is_empty(): + return "No thread data." + + var lines: Array[String] = [] + lines.append("Title: %s" % str(thread.get("title", ""))) + lines.append("Status: %s" % str(thread.get("status", ""))) + lines.append("Category: %s" % str(thread.get("category", ""))) + lines.append("") + lines.append("Original report:") + lines.append(str(thread.get("description", ""))) + + var steps := str(thread.get("stepsToReproduce", "")) + if not steps.is_empty(): + lines.append("") + lines.append("Steps to reproduce:") + lines.append(steps) + + lines.append("") + lines.append("Responses:") + + var responses: Array = thread.get("responses", []) as Array + if responses.is_empty(): + lines.append("(No responses yet)") + else: + for r in responses: + var rd := r as Dictionary + lines.append("- %s: %s" % [ + str(rd.get("authorDisplayName", "Unknown")), + str(rd.get("content", "")) + ]) + + return "\n".join(lines) # ── Navigation ────────────────────────────────────────────────────────────────