Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/libbugzilla/clients/commentclient.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2019 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "commentclient.h" | ||||
22 | | ||||
23 | #include <QVariantHash> | ||||
24 | | ||||
25 | namespace Bugzilla { | ||||
26 | | ||||
27 | QList<Comment::Ptr> CommentClient::getFromBug(KJob *kjob) | ||||
28 | { | ||||
29 | APIJob *job = qobject_cast<APIJob *>(kjob); | ||||
30 | | ||||
31 | QJsonObject bugs = job->object().value(QStringLiteral("bugs")).toObject(); | ||||
32 | Q_ASSERT(bugs.keys().size() == 1); | ||||
33 | | ||||
34 | #warning at 0 is a bit wonky | ||||
35 | QJsonObject bug = bugs.value(bugs.keys().at(0)).toObject(); | ||||
36 | QJsonArray comments = bug.value(QStringLiteral("comments")).toArray(); | ||||
37 | | ||||
38 | QList<Comment::Ptr> list; | ||||
39 | for (auto it = comments.constBegin(); it != comments.constEnd(); ++it) { | ||||
40 | list.append(new Comment((*it).toObject().toVariantHash())); | ||||
41 | } | ||||
42 | | ||||
43 | return list; | ||||
44 | } | ||||
45 | | ||||
46 | KJob *CommentClient::getFromBug(int bugId) | ||||
47 | { | ||||
48 | return m_connection.get(QStringLiteral("/bug/%1/comment").arg(QString::number(bugId))); | ||||
49 | } | ||||
50 | | ||||
51 | #warning fimxe somehow bug should do this, feels super weird to have to ask antoher client to ask for comments. could just be the bug model. but then the bug model knows more? | ||||
52 | #warning the problem with apireply is that it can raise in a qt slot that has undefined behavior | ||||
53 | APIReply<QList<Comment::Ptr>> *CommentClient::getFromBug2(int bugId) | ||||
54 | { | ||||
55 | APIJob *job = m_connection.get(QStringLiteral("/bug/%1/comment").arg(QString::number(bugId))); | ||||
56 | | ||||
57 | auto reply = new APIReply<QList<Comment::Ptr>>(job); | ||||
58 | reply->constructResult([](KJob *kjob) -> QList<Comment::Ptr> { | ||||
59 | APIJob *job = qobject_cast<APIJob *>(kjob); | ||||
60 | | ||||
61 | #warning code dupe form getFromBug looks like | ||||
62 | QJsonObject bugs = job->object().value(QStringLiteral("bugs")).toObject(); | ||||
63 | Q_ASSERT(bugs.keys().size() == 1); | ||||
64 | | ||||
65 | QJsonObject bug = bugs.value(bugs.keys().at(0)).toObject(); | ||||
66 | QJsonArray comments = bug.value(QStringLiteral("comments")).toArray(); | ||||
67 | | ||||
68 | QList<Comment::Ptr> list; | ||||
69 | for (auto it = comments.constBegin(); it != comments.constEnd(); ++it) { | ||||
70 | list.append(new Comment((*it).toObject().toVariantHash())); | ||||
71 | } | ||||
72 | | ||||
73 | return list; | ||||
74 | }); | ||||
75 | | ||||
76 | return reply; | ||||
77 | } | ||||
78 | | ||||
79 | } // namespace Bugzilla |