Commit a4b6d2d5 authored by Dan Leinir Turthra Jensen's avatar Dan Leinir Turthra Jensen 🌈
Browse files

Add support for sub-comments to the Reviews backend

Summary:
Using a similar style to the comments delegate in KNewStuffQuick, this
adds the functionality for having subcomments in the Reviews model.
The end result is that we no longer have incorrect numbers showing in
Discover, as it now shows all the items returned by the server.

* Adds a role for the depth of reviews (used for comments on reviews)
* Adds sub-comments (and set their depth) in the KNS backend's reviews
* Adapts the ReviewDelegate to have indentation marks (styled like KNSQuick)

BUG: 391191
FIXED-IN: 5.17.0

Test Plan:
Without the patch, incorrect numbers of reviews are shown (as no children are shown). With this patch, children are shown (using the same indentation style as used by KNewStuffQuick):
{F7812653}

Reviewers: #discover_software_store, #plasma, apol, ngraham

Reviewed By: #discover_software_store, ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25886
parent 89088f76
......@@ -23,8 +23,7 @@ import QtQuick.Controls 2.1
import org.kde.discover 2.0
import org.kde.kirigami 2.0 as Kirigami
ColumnLayout
{
RowLayout {
id: item
visible: model.shouldShow
property bool compact: false
......@@ -38,52 +37,73 @@ ColumnLayout
: i18n("<em>%1 out of %2 people found this review useful</em>", favorable, total)
}
RowLayout {
Layout.fillWidth: true
Repeater {
model: depth
delegate: Rectangle {
Layout.fillHeight: true
Layout.minimumWidth: Kirigami.Units.largeSpacing
Layout.maximumWidth: Kirigami.Units.largeSpacing
color: Qt.tint(Kirigami.Theme.textColor, Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.8))
Rectangle {
anchors {
top: parent.top
bottom: parent.bottom
left: parent.left
}
width: 1
color: Kirigami.Theme.backgroundColor
}
}
}
ColumnLayout
{
RowLayout {
Layout.fillWidth: true
Label {
id: content
Layout.fillWidth: true
elide: Text.ElideRight
readonly property string author: reviewer ? reviewer : i18n("unknown reviewer")
text: summary ? i18n("<b>%1</b> by %2", summary, author) : i18n("Comment by %1", author)
}
Rating {
id: rating
rating: model.rating
starSize: content.font.pointSize
}
}
Label {
id: content
Layout.fillWidth: true
elide: Text.ElideRight
readonly property string author: reviewer ? reviewer : i18n("unknown reviewer")
text: summary ? i18n("<b>%1</b> by %2", summary, author) : i18n("Comment by %1", author)
text: display
maximumLineCount: item.compact ? 3 : undefined
wrapMode: Text.Wrap
}
Rating {
id: rating
rating: model.rating
starSize: content.font.pointSize
Label {
visible: !item.compact
text: item.usefulnessToString(usefulnessFavorable, usefulnessTotal)
}
}
Label {
Layout.fillWidth: true
text: display
maximumLineCount: item.compact ? 3 : undefined
wrapMode: Text.Wrap
}
Label {
visible: !item.compact
text: usefulnessToString(usefulnessFavorable, usefulnessTotal)
}
Label {
visible: !item.compact
Layout.alignment: Qt.AlignRight
text: {
switch(usefulChoice) {
case ReviewsModel.Yes:
i18n("<em>Useful? <a href='true'><b>Yes</b></a>/<a href='false'>No</a></em>")
break;
case ReviewsModel.No:
i18n("<em>Useful? <a href='true'>Yes</a>/<a href='false'><b>No</b></a></em>")
break;
default:
i18n("<em>Useful? <a href='true'>Yes</a>/<a href='false'>No</a></em>")
break;
Label {
visible: !item.compact
Layout.alignment: Qt.AlignRight
text: {
switch(usefulChoice) {
case ReviewsModel.Yes:
i18n("<em>Useful? <a href='true'><b>Yes</b></a>/<a href='false'>No</a></em>")
break;
case ReviewsModel.No:
i18n("<em>Useful? <a href='true'>Yes</a>/<a href='false'><b>No</b></a></em>")
break;
default:
i18n("<em>Useful? <a href='true'>Yes</a>/<a href='false'>No</a></em>")
break;
}
}
onLinkActivated: item.markUseful(link=='true')
}
Kirigami.Separator {
visible: item.separator
Layout.fillWidth: true
}
onLinkActivated: item.markUseful(link=='true')
}
Kirigami.Separator {
visible: item.separator
Layout.fillWidth: true
}
}
......@@ -46,6 +46,7 @@ QHash< int, QByteArray > ReviewsModel::roleNames() const
roles.insert(UsefulChoice, "usefulChoice");
roles.insert(Rating, "rating");
roles.insert(Summary, "summary");
roles.insert(Depth, "depth");
return roles;
}
......@@ -72,6 +73,8 @@ QVariant ReviewsModel::data(const QModelIndex& index, int role) const
return m_reviews.at(index.row())->rating();
case Summary:
return m_reviews.at(index.row())->summary();
case Depth:
return m_reviews.at(index.row())->getMetadata(QStringLiteral("NumberOfParents")).toInt();
}
return QVariant();
}
......
......@@ -45,7 +45,8 @@ class DISCOVERCOMMON_EXPORT ReviewsModel : public QAbstractListModel
UsefulnessFavorable,
UsefulChoice,
Rating,
Summary
Summary,
Depth
};
enum UserChoice {
None,
......
......@@ -78,21 +78,29 @@ void KNSReviews::fetchReviews(AbstractResource* app, int page)
m_fetching++;
}
void KNSReviews::commentsReceived(Attica::BaseJob* j)
{
m_fetching--;
Attica::ListJob<Attica::Comment>* job = static_cast<Attica::ListJob<Attica::Comment>*>(j);
Attica::Comment::List comments = job->itemList();
static QVector<ReviewPtr> createReviewList(AbstractResource* app, Attica::Comment::List comments, int depth = 0) {
QVector<ReviewPtr> reviews;
AbstractResource* app = job->property("app").value<AbstractResource*>();
foreach(const Attica::Comment& comment, comments) {
//TODO: language lookup?
ReviewPtr r(new Review(app->name(), app->packageName(), QStringLiteral("en"), comment.subject(), comment.text(), comment.user(),
comment.date(), true, comment.id().toInt(), comment.score()/10, 0, 0, QString()
));
r->addMetadata(QStringLiteral("NumberOfParents"), depth);
reviews += r;
if (comment.childCount() > 0) {
reviews += createReviewList(app, comment.children(), depth + 1);
}
}
return reviews;
}
void KNSReviews::commentsReceived(Attica::BaseJob* j)
{
m_fetching--;
Attica::ListJob<Attica::Comment>* job = static_cast<Attica::ListJob<Attica::Comment>*>(j);
AbstractResource* app = job->property("app").value<AbstractResource*>();
QVector<ReviewPtr> reviews = createReviewList(app, job->itemList());
emit reviewsReady(app, reviews, !reviews.isEmpty());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment