Skip to content

Commit

Permalink
add remove likes draft
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseysidorov committed Jun 10, 2012
1 parent 1f68e82 commit bbf9097
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
32 changes: 17 additions & 15 deletions src/qml/harmattan/subpages/CommentsPage.qml
Expand Up @@ -103,7 +103,7 @@ Page {
Comments {
id: commentsTools

function _like(repost)
function addLike(repost)
{
var isRepost = repost
//TODO move to C++ code
Expand All @@ -112,35 +112,37 @@ Page {
"post_id" : postId,
"repost": repost
}
var reply = client.request("wall.addLike", args)
reply.resultReady.connect(function(response) {
console.log(response.cid)
isLiked = true
isRetweet = isRepost
})
wallModel.addLike(postId, repost)
//var reply = client.request("wall.addLike", args)
//reply.resultReady.connect(function(response) {
// console.log(response.cid)
// isLiked = true
// isRetweet = isRepost
//})
}

function _unlike()
function deleteLike()
{
var isRepost = repost
//TODO move to C++ code
var args = {
"owner_id" : from.id,
"post_id" : postId
}
var reply = client.request("wall.deleteLike", args)
reply.resultReady.connect(function(response) {
console.log(response.cid)
isLiked = false
isRetweet = false
})
wallModel.deleteLike(postId, repost)
//var reply = client.request("wall.deleteLike", args)
//reply.resultReady.connect(function(response) {
// console.log(response.cid)
// isLiked = false
// isRetweet = false
//})
}

onPost: {
postSheet.open()
}

onLike: _like(false)
onLike: addLike(false)
onRetweet: -like(true)


Expand Down
46 changes: 43 additions & 3 deletions src/wallmodel.cpp
Expand Up @@ -37,6 +37,8 @@ void WallModel::setContact(vk::Contact *contact)
return;
auto session = new vk::WallSession(contact);
connect(session, SIGNAL(postAdded(vk::WallPost)), SLOT(addPost(vk::WallPost)));
connect(session, SIGNAL(postLikeAdded(int,int,int,bool)), SLOT(onPostLikeAdded(int,int,int,bool)));
connect(session, SIGNAL(postLikeDeleted(int,int)), SLOT(onPostLikeDeleted(int,int)));

m_contact = contact;
m_session = session;
Expand Down Expand Up @@ -84,12 +86,30 @@ int WallModel::count() const

void WallModel::getLastPosts(int count, vk::WallSession::Filter filter)
{
if (m_session.isNull()) {
if (m_session.isNull())
qWarning("WallModel: contact is null! Please set a contact!");
return;
}
else {
auto reply = m_session.data()->getPosts(filter, count, 0, false);
connect(reply, SIGNAL(resultReady(QVariant)), SIGNAL(requestFinished()));
}
}

void WallModel::addLike(int postId, bool retweet, const QString &message)
{
if (m_session.isNull())
qWarning("WallModel: contact is null! Please set a contact!");
else {
m_session.data()->addLike(postId, retweet, message);
}
}

void WallModel::deleteLike(int postId)
{
if (m_session.isNull())
qWarning("WallModel: contact is null! Please set a contact!");
else {
m_session.data()->deleteLike(postId);
}
}

void WallModel::clear()
Expand Down Expand Up @@ -129,6 +149,26 @@ void WallModel::addPost(const vk::WallPost &post)
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
}

void WallModel::replacePost(int index, const vk::WallPost &post)
{
}

void WallModel::onPostLikeAdded(int postId, int likesCount, int repostsCount, bool isRetweeted)
{
int id = findPost(postId);
if (id != -1) {
vk::WallPost post = m_posts.at(id);
auto likes = post.likes();
likes.insert("count", likesCount);
post.setLikes(likes);
replacePost(id, post);
}
}

void WallModel::onPostLikeDeleted(int id, int likesCount)
{
}

vk::Roster *WallModel::roster() const
{
return m_contact.data()->client()->roster();
Expand Down
5 changes: 5 additions & 0 deletions src/wallmodel.h
Expand Up @@ -31,13 +31,18 @@ class WallModel : public QAbstractListModel
int count() const;
public slots:
void getLastPosts(int count = 16, vk::WallSession::Filter filter = vk::WallSession::All);
void addLike(int postId, bool retweet = false, const QString &message = QString());
void deleteLike(int postId);
void clear();
int findPost(int id);
signals:
void contactChanged(vk::Contact* arg);
void requestFinished();
private slots:
void addPost(const vk::WallPost &post);
void replacePost(int index, const vk::WallPost &post);
void onPostLikeAdded(int id, int likesCount, int repostsCount, bool isRetweeted);
void onPostLikeDeleted(int id, int likesCount);
private:
vk::Roster *roster() const;
QWeakPointer<vk::Contact> m_contact;
Expand Down
2 changes: 1 addition & 1 deletion vk
Submodule vk updated from 927757 to 41fc6e

0 comments on commit bbf9097

Please sign in to comment.