File indexing completed on 2025-02-23 04:35:13

0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 #include "comment.h"
0005 
0006 using namespace QInvidious;
0007 using namespace Qt::StringLiterals;
0008 
0009 Comment Comment::fromJson(const QJsonObject &obj, Comment &comment)
0010 {
0011     const bool isPeerTube = obj.contains("id"_L1);
0012     const bool isPiped = obj.contains("commentId"_L1) && !obj.contains("authorThumbnails"_L1);
0013     if (isPeerTube) {
0014         comment.m_author = obj["account"_L1].toObject()["displayName"_L1].toString();
0015         comment.m_content = obj["text"_L1].toString();
0016     } else if (isPiped) {
0017         comment.m_author = obj["author"_L1].toString();
0018         comment.m_content = obj["commentText"_L1].toString();
0019         comment.m_authorAvatar = obj["thumbnail"_L1].toString();
0020     } else {
0021         comment.m_author = obj["author"_L1].toString();
0022         comment.m_content = obj["contentHtml"_L1].toString();
0023         const QJsonValue firstAvatar = obj["authorThumbnails"_L1].toArray().first();
0024         comment.m_authorAvatar = firstAvatar.toObject()["url"_L1].toString();
0025     }
0026     return comment;
0027 }
0028 
0029 QString Comment::author() const
0030 {
0031     return m_author;
0032 }
0033 
0034 QString Comment::authorAvatar() const
0035 {
0036     return m_authorAvatar;
0037 }
0038 
0039 QString Comment::content() const
0040 {
0041     return m_content;
0042 }