don't add empty comments

This commit is contained in:
Toni Förster 2024-04-02 15:08:36 +02:00
parent ae16680fc2
commit c77c5a6d21
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7

View File

@ -727,15 +727,23 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
let commentorUrl = details["commentorUrl"]?.string let commentorUrl = details["commentorUrl"]?.string
let channelId = commentorUrl?.components(separatedBy: "/")[2] ?? "" 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( return Comment(
id: details["commentId"]?.string ?? UUID().uuidString, id: commentId,
author: author, author: author,
authorAvatarURL: details["thumbnail"]?.string ?? "", authorAvatarURL: details["thumbnail"]?.string ?? "",
time: details["commentedTime"]?.string ?? "", time: details["commentedTime"]?.string ?? "",
pinned: details["pinned"]?.bool ?? false, pinned: details["pinned"]?.bool ?? false,
hearted: details["hearted"]?.bool ?? false, hearted: details["hearted"]?.bool ?? false,
likeCount: details["likeCount"]?.int ?? 0, likeCount: details["likeCount"]?.int ?? 0,
text: extractCommentText(from: details["commentText"]?.stringValue), text: commentText,
repliesPage: details["repliesPage"]?.string, repliesPage: details["repliesPage"]?.string,
channel: Channel(app: .piped, id: channelId, name: author) channel: Channel(app: .piped, id: channelId, name: author)
) )