From c77c5a6d21723c58ab58e29e36bb4dd7c73ed8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20F=C3=B6rster?= Date: Tue, 2 Apr 2024 15:08:36 +0200 Subject: [PATCH] don't add empty comments --- Model/Applications/PipedAPI.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 1a1567e3..f456d343 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -727,15 +727,23 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { let commentorUrl = details["commentorUrl"]?.string let channelId = commentorUrl?.components(separatedBy: "/")[2] ?? "" + let commentText = extractCommentText(from: details["commentText"]?.stringValue) + let commentId = details["commentId"]?.string ?? UUID().uuidString + + // Sanity checks: return nil if required data is missing + if commentText.isEmpty || commentId.isEmpty || author.isEmpty { + return nil + } + return Comment( - id: details["commentId"]?.string ?? UUID().uuidString, + id: commentId, author: author, authorAvatarURL: details["thumbnail"]?.string ?? "", time: details["commentedTime"]?.string ?? "", pinned: details["pinned"]?.bool ?? false, hearted: details["hearted"]?.bool ?? false, likeCount: details["likeCount"]?.int ?? 0, - text: extractCommentText(from: details["commentText"]?.stringValue), + text: commentText, repliesPage: details["repliesPage"]?.string, channel: Channel(app: .piped, id: channelId, name: author) )