21#include "akonadi_serializer_socialfeeditem.h"
22#include "../socialfeeditem.h"
24#include "akonadi/config-akonadi.h"
25#include "akonadi/item.h"
27#include <QtCore/qplugin.h>
29#include <qjson/qobjecthelper.h>
30#include <qjson/parser.h>
31#include <qjson/serializer.h>
33using namespace Akonadi;
35bool SocialFeedItemSerializerPlugin::deserialize( Item &item,
36 const QByteArray &label,
42 if ( label != Item::FullPayload ) {
49 QVariantMap map = parser.parse( data.readAll() ).toMap();
51 feedItem.
setNetworkString( map.value( QLatin1String(
"networkString" ) ).toString() );
52 feedItem.
setPostId( map.value( QLatin1String(
"postId" ) ).toString() );
53 feedItem.
setPostText( map.value( QLatin1String(
"postText" ) ).toString() );
54 feedItem.
setPostLinkTitle( map.value( QLatin1String(
"postLinkTitle" ) ).toString() );
55 feedItem.
setPostLink( map.value( QLatin1String(
"postLink" ) ).toUrl() );
56 feedItem.
setPostImageUrl( map.value( QLatin1String(
"postImageUrl" ) ).toUrl() );
57 feedItem.
setPostInfo( map.value( QLatin1String(
"postInfo" ) ).toString() );
58 feedItem.
setUserName( map.value( QLatin1String(
"userName" ) ).toString() );
59 feedItem.
setUserDisplayName( map.value( QLatin1String(
"userDisplayName" ) ).toString() );
60 feedItem.
setUserId( map.value( QLatin1String(
"userId" ) ).toString() );
61 feedItem.
setAvatarUrl( map.value( QLatin1String(
"avatarUrl" ) ).toUrl() );
62 feedItem.
setPostTime( map.value( QLatin1String(
"postTimeString" ) ).toString(),
63 map.value( QLatin1String(
"postTimeFormat" ) ).toString() );
64 feedItem.
setShared( map.value( QLatin1String(
"shared" ) ).toBool() );
65 feedItem.
setSharedFrom( map.value( QLatin1String(
"sharedFrom" ) ).toString() );
66 feedItem.
setSharedFromId( map.value( QLatin1String(
"sharedFromId" ) ).toString() );
67 feedItem.
setLiked( map.value( QLatin1String(
"liked" ) ).toBool() );
68 feedItem.
setItemSourceMap( map.value( QLatin1String(
"itemSourceMap" ) ).toMap() );
70 if ( map.keys().contains( QLatin1String(
"postReplies" ) ) ) {
71 QList<SocialFeedItem> replies;
72 Q_FOREACH (
const QVariant &replyData, map.value( QLatin1String(
"postReplies" ) ).toList() ) {
73 QVariantMap reply = replyData.toMap();
75 postReply.
setUserId( reply.value( QLatin1String(
"userId" ) ).toString() );
76 postReply.
setUserName( reply.value( QLatin1String(
"userName" ) ).toString() );
77 postReply.
setAvatarUrl( reply.value( QLatin1String(
"userAvatarUrl" ) ).toString() );
78 postReply.
setPostText( reply.value( QLatin1String(
"replyText" ) ).toString() );
80 postReply.
setPostId( reply.value( QLatin1String(
"replyId" ) ).toString() );
83 replies.append( postReply );
89 item.setMimeType( QLatin1String(
"text/x-vnd.akonadi.socialfeeditem" ) );
95void SocialFeedItemSerializerPlugin::serialize(
const Item &item,
96 const QByteArray &label,
111 map.insert( QLatin1String(
"networkString" ), feedItem.
networkString() );
112 map.insert( QLatin1String(
"postId" ), feedItem.
postId() );
113 map.insert( QLatin1String(
"postText" ), feedItem.
postText() );
114 map.insert( QLatin1String(
"postLinkTitle" ), feedItem.
postLinkTitle() );
115 map.insert( QLatin1String(
"postLink" ), feedItem.
postLink() );
116 map.insert( QLatin1String(
"postImageUrl" ), feedItem.
postImageUrl() );
117 map.insert( QLatin1String(
"postInfo" ), feedItem.
postInfo() );
118 map.insert( QLatin1String(
"userName" ), feedItem.
userName() );
119 map.insert( QLatin1String(
"userDisplayName" ), feedItem.
userDisplayName() );
120 map.insert( QLatin1String(
"userId" ), feedItem.
userId() );
121 map.insert( QLatin1String(
"avatarUrl" ), feedItem.
avatarUrl() );
122 map.insert( QLatin1String(
"postTimeString" ), feedItem.
postTimeString() );
123 map.insert( QLatin1String(
"postTimeFormat" ), feedItem.
postTimeFormat() );
124 map.insert( QLatin1String(
"shared" ), feedItem.
isShared() );
125 map.insert( QLatin1String(
"sharedFrom" ), feedItem.
sharedFrom() );
126 map.insert( QLatin1String(
"sharedFromId" ), feedItem.
sharedFromId() );
127 map.insert( QLatin1String(
"liked" ), feedItem.
isLiked() );
128 map.insert( QLatin1String(
"itemSourceMap" ), feedItem.
itemSourceMap() );
131 QVariantList replies;
133 QVariantMap replyData;
134 replyData.insert( QLatin1String(
"userId" ), reply.
userId() );
135 replyData.insert( QLatin1String(
"userName" ), reply.
userName() );
136 replyData.insert( QLatin1String(
"userAvatarUrl" ), reply.
avatarUrl() );
137 replyData.insert( QLatin1String(
"replyText" ), reply.
postText() );
139 replyData.insert( QLatin1String(
"replyId" ), reply.
postId() );
141 replies.append( replyData );
144 map.insert( QLatin1String(
"postReplies" ), replies );
147 QJson::Serializer serializer;
148#if !defined( USE_QJSON_0_8 )
149 data.write( serializer.serialize( map ) );
151 data.write( serializer.serialize( map, 0 ) );
155QSet<QByteArray> SocialFeedItemSerializerPlugin::parts(
const Item &item )
const
159 return ItemSerializerPlugin::parts( item );
162Q_EXPORT_PLUGIN2( akonadi_serializer_socialfeeditem, Akonadi::SocialFeedItemSerializerPlugin )
Class representing one entry in the social feed.
void setPostReplies(const QList< SocialFeedItem > &replies)
Sets replies/comments for this post.
QUrl postImageUrl() const
void setUserId(const QString &userId)
Sets the network user id associated with this post.
QString networkString() const
This returns the service string such as "on Facebook", "on Twitter" It's used in the feed as the firs...
QString postTimeString() const
void setPostLinkTitle(const QString &linkTitle)
Sets the link title the posts links to.
QString sharedFrom() const
void setItemSourceMap(const QVariantMap &itemSourceMap)
Sets the original data which was received from the network and then mapped to a QVariantMap.
void setPostTime(const QString &postTimeString, const QString &postTimeFormat)
Sets the time string which was received from the network together with the format which could be rece...
QVariantMap itemSourceMap() const
void setSharedFromId(const QString &sharedFromId)
Sets the user id of the user this was shared from.
QList< SocialFeedItem > postReplies() const
void setPostImageUrl(const QUrl &imageUrl)
Sets the URL of an image associated with this post, it can be an image thumb, link thumb etc.
QString postTimeFormat() const
QString sharedFromId() const
void setSharedFrom(const QString &sharedFrom)
Sets the display name of the user which was the original author of this post.
void setNetworkString(const QString &networkString)
Sets the network string for this item.
void setLiked(bool liked)
Sets if the user has liked/favorited the post or not.
void setPostText(const QString &text)
Sets the post text to be displayed in the feed.
void setShared(bool shared)
Sets if this post was shared from other user.
void setPostId(const QString &postId)
Sets the original post id.
void setPostLink(const QUrl &link)
Sets the link the posts links to.
QString postLinkTitle() const
QString userDisplayName() const
void setPostInfo(const QString &postInfo)
Sets additional info for the post, like number of comments, likes, retweed from etc.
void setUserName(const QString &userName)
Sets the network user name associated with this post.
void setAvatarUrl(const QUrl &url)
Sets the url of the avatar picture to be displayed next to the post in the feed.
void setUserDisplayName(const QString &userDisplayName)
Sets the name to be displayed to the user (full name usually)