diff --git a/Client/origin-client/scenes/chat/chat_overlay.gd b/Client/origin-client/scenes/chat/chat_overlay.gd index fcaf64a..cf30f9e 100644 --- a/Client/origin-client/scenes/chat/chat_overlay.gd +++ b/Client/origin-client/scenes/chat/chat_overlay.gd @@ -114,7 +114,7 @@ func _connect_chat_signals() -> void: Chat.message_received.connect(_on_message_received) Chat.social_updated.connect(_on_social_updated) Chat.presence_updated.connect(_on_presence_updated) - Chat.notifications_updated.connect(_refresh_badge) + Chat.notifications_updated.connect(_on_notifications_updated) Chat.party_updated.connect(_on_party_updated) Chat.party_invite_received.connect(_on_party_invite_received) @@ -237,6 +237,29 @@ func _refresh_friends() -> void: for c in _friends_list.get_children(): c.queue_free() + # Notification preview section (unread only). + var unread_notifications := Chat.notifications.filter(func(n: Dictionary) -> bool: + return n.get("readAt") == null) + if not unread_notifications.is_empty(): + _friends_list.add_child(_make_section_label("NOTIFICATIONS — %d" % unread_notifications.size())) + for n: Dictionary in unread_notifications: + _friends_list.add_child(_make_notification_row(n)) + + var mark_all_btn := Button.new() + mark_all_btn.text = "Mark all notifications read" + mark_all_btn.flat = true + mark_all_btn.alignment = HORIZONTAL_ALIGNMENT_LEFT + mark_all_btn.custom_minimum_size = Vector2(0, 30) + mark_all_btn.add_theme_color_override("font_color", ACCENT_COLOR) + mark_all_btn.pressed.connect(func() -> void: + var ids: Array = unread_notifications.map(func(n: Dictionary) -> String: + return str(n.get("id", ""))) + Chat.mark_notifications_read(ids)) + _friends_list.add_child(mark_all_btn) + + var notif_sep := HSeparator.new() + _friends_list.add_child(notif_sep) + # Pending requests section. if is_instance_valid(_requests_section): _requests_section.visible = not Chat.pending_requests.is_empty() @@ -296,6 +319,55 @@ func _make_friend_row(f: Dictionary) -> Control: return btn +func _make_notification_row(n: Dictionary) -> Control: + var row := VBoxContainer.new() + row.custom_minimum_size = Vector2(0, 42) + row.add_theme_constant_override("separation", 2) + + var title := Label.new() + title.text = n.get("title", "Notification") + title.add_theme_font_size_override("font_size", 12) + title.add_theme_color_override("font_color", Color(0.92, 0.92, 0.98)) + row.add_child(title) + + var body := Label.new() + body.text = n.get("body", "") + body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + body.add_theme_font_size_override("font_size", 11) + body.add_theme_color_override("font_color", MUTED_COLOR) + row.add_child(body) + + var footer := HBoxContainer.new() + footer.add_theme_constant_override("separation", 8) + row.add_child(footer) + + var ts := Label.new() + ts.text = _format_time(str(n.get("createdAt", ""))) + ts.add_theme_font_size_override("font_size", 10) + ts.add_theme_color_override("font_color", MUTED_COLOR) + ts.size_flags_horizontal = Control.SIZE_EXPAND_FILL + footer.add_child(ts) + + var mark_btn := Button.new() + mark_btn.text = "Mark read" + mark_btn.flat = true + mark_btn.add_theme_font_size_override("font_size", 10) + mark_btn.add_theme_color_override("font_color", ACCENT_COLOR) + mark_btn.pressed.connect(func() -> void: + var id := str(n.get("id", "")) + if not id.is_empty(): + Chat.mark_notifications_read([id])) + footer.add_child(mark_btn) + + var wrap := MarginContainer.new() + wrap.add_theme_constant_override("margin_left", 10) + wrap.add_theme_constant_override("margin_right", 10) + wrap.add_theme_constant_override("margin_top", 4) + wrap.add_theme_constant_override("margin_bottom", 4) + wrap.add_child(row) + return wrap + + func _make_request_row(req: Dictionary) -> Control: var dn : String = req.get("otherDisplayName", "Unknown") var rid : String = req.get("requestId", "") @@ -811,6 +883,12 @@ func _on_presence_updated() -> void: Tab.PRESENCE: _refresh_presence() +func _on_notifications_updated() -> void: + _refresh_badge() + if _panel.visible and _current_tab == Tab.FRIENDS: + _refresh_friends() + + func _on_own_presence_changed(index: int) -> void: const STATUS_MAP := ["Online", "Away", "Offline"] Chat.set_presence(STATUS_MAP[index])