Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Computershik73 committed Feb 10, 2024
2 parents 2666517 + 3171f8b commit f105274
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 36 deletions.
66 changes: 45 additions & 21 deletions qml/pages/WallPostPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ Page {

Repeater {
model: vksdk.commentsModel
delegate: Item {
delegate: ListItem {
width: parent.width
height: childrenRect.height

//height: childrenRect.height
contentHeight: commentContent.height
property real avatarSize : Theme.iconSizeMedium
Image {
id: commentAvatar
anchors.top: parent.top
anchors.left: parent.left

width: 50 //Theme.iconSizeSmall
height: 50 //Theme.iconSizeSmall
width: avatarSize
height: avatarSize
source: avatarSource

layer.enabled: true
Expand All @@ -110,38 +111,61 @@ Page {
}
Rectangle {
id: commentAvatarMask
width: 50
height: 50
radius: 50
width: avatarSize
height: avatarSize
radius: avatarSize
visible: false
}
Column {
id: commentContent
anchors {
left: commentAvatar.right
right: parent.right
leftMargin: Theme.paddingMedium
}
Label {
id: commentUserName
//anchors.top: parent.top
//anchors.left: commentAvatar.right
color: Theme.highlightColor
Row {
width: parent.width
//anchors.leftMargin: Theme.paddingMedium
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.WordWrap
text: title
spacing: Theme.paddingSmall
Label {
id: commentUserName
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.WordWrap
text: title
}
Image {
id: commnetLikeIcon
width: Theme.fontSizeTiny
height: Theme.fontSizeTiny
source: "image://theme/icon-s-like?" +
(userLiked ? Theme.secondaryHighlightColor : Theme.secondaryColor)
}

Label {
id: commentLikeCounter
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeTiny
text: likeCount
}
}

Label {
//anchors.top: parent.top
//anchors.left: commentAvatar.right
width: parent.width
//anchors.leftMargin: Theme.paddingMedium
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.WordWrap
text: commentText
}

}
menu: ContextMenu {

MenuItem {
text: qsTr("Like")
onClicked: {
vksdk.likes.addComment(wallpost.toId, commentId)
commentLikeCounter.text = parseInt(commentLikeCounter.text) +1
commnetLikeIcon.source = "image://theme/icon-s-like?" + Theme.secondaryHighlightColor
}
}
}
Component.onCompleted: console.log(avatarSource, commentText)
}
Expand Down
5 changes: 3 additions & 2 deletions translations/harbour-kat-az.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="50"/>
<location filename="../qml/pages/WallPostPage.qml" line="162"/>
<source>Like</source>
<translation>Bəyəndim</translation>
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="153"/>
<location filename="../qml/pages/WallPostPage.qml" line="154"/>
<location filename="../qml/pages/WallPostPage.qml" line="179"/>
<location filename="../qml/pages/WallPostPage.qml" line="180"/>
<source>Your comment</source>
<translation>Sizin şərhiviz</translation>
</message>
Expand Down
5 changes: 3 additions & 2 deletions translations/harbour-kat-it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="50"/>
<location filename="../qml/pages/WallPostPage.qml" line="162"/>
<source>Like</source>
<translation>Mi piace</translation>
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="153"/>
<location filename="../qml/pages/WallPostPage.qml" line="154"/>
<location filename="../qml/pages/WallPostPage.qml" line="179"/>
<location filename="../qml/pages/WallPostPage.qml" line="180"/>
<source>Your comment</source>
<translation type="unfinished"></translation>
</message>
Expand Down
5 changes: 3 additions & 2 deletions translations/harbour-kat-nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="50"/>
<location filename="../qml/pages/WallPostPage.qml" line="162"/>
<source>Like</source>
<translation>Like</translation>
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="153"/>
<location filename="../qml/pages/WallPostPage.qml" line="154"/>
<location filename="../qml/pages/WallPostPage.qml" line="179"/>
<location filename="../qml/pages/WallPostPage.qml" line="180"/>
<source>Your comment</source>
<translation>Jouw commentaar</translation>
</message>
Expand Down
5 changes: 3 additions & 2 deletions translations/harbour-kat-ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="50"/>
<location filename="../qml/pages/WallPostPage.qml" line="162"/>
<source>Like</source>
<translation>Мне нравится</translation>
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="153"/>
<location filename="../qml/pages/WallPostPage.qml" line="154"/>
<location filename="../qml/pages/WallPostPage.qml" line="179"/>
<location filename="../qml/pages/WallPostPage.qml" line="180"/>
<source>Your comment</source>
<translation>Ваш комментарий</translation>
</message>
Expand Down
5 changes: 3 additions & 2 deletions translations/harbour-kat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="50"/>
<location filename="../qml/pages/WallPostPage.qml" line="162"/>
<source>Like</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/WallPostPage.qml" line="153"/>
<location filename="../qml/pages/WallPostPage.qml" line="154"/>
<location filename="../qml/pages/WallPostPage.qml" line="179"/>
<location filename="../qml/pages/WallPostPage.qml" line="180"/>
<source>Your comment</source>
<translation type="unfinished"></translation>
</message>
Expand Down
19 changes: 14 additions & 5 deletions vksdk/src/models/commentsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@ int CommentsModel::rowCount(const QModelIndex &parent) const {

QVariant CommentsModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) return QVariant();

Comment * comment = _comments.at(index.row());
switch (role) {
case IdRole:
return QVariant(comment->id());
case AvatarRole:
return QVariant(_getAvatarSource(_comments.at(index.row())->fromId()));
return QVariant(_getAvatarSource(comment->fromId()));
case TitleRole:
return QVariant(_getTitle(_comments.at(index.row())->fromId()));
return QVariant(_getTitle(comment->fromId()));
case TextRole:
return QVariant(_comments.at(index.row())->text());
return QVariant(comment->text());
case DateRole:
return QVariant(_comments.at(index.row())->date());
return QVariant(comment->date());
case LikeCountRole:
return QVariant(comment->likesCount());
case UserLikedRole:
return QVariant(comment->userLiked());
case AttachmentsRole:
return QVariant();
default:
Expand All @@ -30,10 +36,13 @@ QVariant CommentsModel::data(const QModelIndex &index, int role) const {

QHash<int, QByteArray> CommentsModel::roleNames() const {
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles[IdRole] = "commentId";
roles[AvatarRole] = "avatarSource";
roles[TitleRole] = "title";
roles[TextRole] = "commentText";
roles[DateRole] = "datetime";
roles[LikeCountRole] = "likeCount";
roles[UserLikedRole] = "userLiked";
roles[AttachmentsRole] = "attachments";
return roles;
}
Expand Down
3 changes: 3 additions & 0 deletions vksdk/src/models/commentsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class CommentsModel : public QAbstractListModel
public:
enum Roles {
AvatarRole = Qt::UserRole + 1,
IdRole,
TitleRole,
TextRole,
DateRole,
LikeCountRole,
UserLikedRole,
AttachmentsRole,
};

Expand Down
24 changes: 24 additions & 0 deletions vksdk/src/objects/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Comment *Comment::fromJsonObject(QJsonObject object) {
if (object.contains("text")) comment->setText(object.value("text").toString());
if (object.contains("reply_to_user")) comment->setReplyToUser(object.value("reply_to_user").toInt());
if (object.contains("reply_to_comment")) comment->setReplyToComment(object.value("reply_to_comment").toInt());
if (object.contains("likes")) {
QJsonObject likes = object.value("likes").toObject();
if (likes.contains("count")) comment->setLikesCount(likes.value("count").toInt());
if (likes.contains("user_likes")) comment->setUserLiked(likes.value("user_likes").toInt() == 1);
}
if (object.contains("attachments")) {
QJsonArray attachments = object.value("attachments").toArray();
for (int index = 0; index < attachments.size(); ++index) {
Expand Down Expand Up @@ -124,6 +129,25 @@ void Comment::setReplyToComment(int replyToComment)
_replyToComment = replyToComment;
}

int Comment::likesCount() const
{
return _likeCount;
}

void Comment::setLikesCount(int count) {
_likeCount=count;
}

bool Comment::userLiked() const
{
return _userLiked;
}

void Comment::setUserLiked(bool liked)
{
_userLiked = liked;
}

QVariant Comment::audios() const
{
return QVariant::fromValue(_audios);
Expand Down
9 changes: 9 additions & 0 deletions vksdk/src/objects/comment.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class Comment : public QObject
int replyToComment() const;
void setReplyToComment(int replyToComment);

int likesCount() const;
void setLikesCount(int count);

bool userLiked() const ;
void setUserLiked(bool liked);


QVariant audios() const;
QList<QObject *> audiosList() const;
void addAudio(Audio *audio);
Expand Down Expand Up @@ -65,6 +72,8 @@ class Comment : public QObject
QString _text = 0;
int _replyToUser = 0;
int _replyToComment = 0;
int _likeCount = 0;
bool _userLiked = false;
QList<QObject*> _audios;
QList<QObject*> _documents;
QList<QObject*> _links;
Expand Down
8 changes: 8 additions & 0 deletions vksdk/src/requests/likes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ void Likes::addPost(int ownerId, int itemId) {
_api->makeApiGetRequest("likes.add", query, ApiRequest::LIKES_ADD);
}

void Likes::addComment(int ownerId, int itemId) {
QUrlQuery query;
query.addQueryItem("type", "comment");
query.addQueryItem("owner_id", QString::number(ownerId));
query.addQueryItem("item_id", QString::number(itemId));
_api->makeApiGetRequest("likes.add", query, ApiRequest::LIKES_ADD);
}

void Likes::addPhoto(int ownerId, int itemId) {
QUrlQuery query;
query.addQueryItem("type", "photo");
Expand Down
1 change: 1 addition & 0 deletions vksdk/src/requests/likes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Likes : public RequestBase
explicit Likes(QObject *parent = 0);

Q_INVOKABLE void addPost(int ownerId, int itemId);
Q_INVOKABLE void addComment(int ownerId, int itemId);
Q_INVOKABLE void addPhoto(int ownerId, int itemId);

};
Expand Down
1 change: 1 addition & 0 deletions vksdk/src/requests/wall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void Wall::getComments(int ownerId, int postId, int offset) {
query.addQueryItem("owner_id", QString::number(ownerId));
query.addQueryItem("post_id", QString::number(postId));
query.addQueryItem("count", "100");
query.addQueryItem("need_likes", "1");
query.addQueryItem("sort", "asc");
query.addQueryItem("extended", "1");
query.addQueryItem("fields", "photo_50");
Expand Down

0 comments on commit f105274

Please sign in to comment.