Added attach picture for posted links

This commit is contained in:
defnax 2019-01-30 14:33:50 +01:00
parent d63655c9b6
commit 7cf17569c5
18 changed files with 993 additions and 363 deletions

View file

@ -25,10 +25,12 @@
#include <inttypes.h>
#include <string>
#include <list>
#include <functional>
#include "retroshare/rstokenservice.h"
#include "retroshare/rsgxsifacehelper.h"
#include "retroshare/rsgxscommon.h"
#include "serialiser/rsserializable.h"
/* The Main Interface Class - for information about your Posted */
class RsPosted;
@ -42,6 +44,7 @@ class RsPostedGroup
RsGroupMetaData mMeta;
std::string mDescription;
};
@ -52,7 +55,7 @@ class RsPostedGroup
#define RSPOSTED_PERIOD_YEAR 1
#define RSPOSTED_PERIOD_MONTH 2
#define RSPOSTED_PERIOD_WEEK 3
#define RSPOSTED_PERIOD_DAY 4
#define RSPOSTED_PERIOD_DAY 4
#define RSPOSTED_PERIOD_HOUR 5
#define RSPOSTED_VIEWMODE_LATEST 1
@ -102,7 +105,6 @@ virtual bool updateGroup(uint32_t &token, RsPostedGroup &group) = 0;
};
class RsPostedPost
{
public:
@ -137,6 +139,24 @@ class RsPostedPost
double mHotScore;
double mTopScore;
double mNewScore;
RsGxsImage mImage;
/// @see RsSerializable
/*virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mImage);
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mLink);
RS_SERIAL_PROCESS(mHaveVoted);
RS_SERIAL_PROCESS(mUpVotes);
RS_SERIAL_PROCESS(mDownVotes);
RS_SERIAL_PROCESS(mComments);
RS_SERIAL_PROCESS(mHotScore);
RS_SERIAL_PROCESS(mTopScore);
RS_SERIAL_PROCESS(mNewScore);
}*/
};

View file

@ -22,15 +22,18 @@
#include "rsitems/rsposteditems.h"
#include "serialiser/rstypeserializer.h"
void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_LINK,mPost.mLink,"mPost.mLink") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG ,mPost.mNotes,"mPost.mNotes") ;
RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mImage,"mImage") ;
}
void RsGxsPostedGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,mGroup.mDescription,"mGroup.mDescription") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,mGroup.mDescription,"mGroup.mDescription") ;
}
RsItem *RsGxsPostedSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
@ -47,12 +50,54 @@ RsItem *RsGxsPostedSerialiser::create_item(uint16_t service_id,uint8_t item_subt
}
}
bool RsGxsPostedPostItem::fromPostedPost(RsPostedPost &post, bool moveImage)
{
clear();
mPost = post;
meta = post.mMeta;
if (moveImage)
{
mImage.binData.bin_data = post.mImage.mData;
mImage.binData.bin_len = post.mImage.mSize;
post.mImage.shallowClear();
}
else
{
mImage.binData.setBinData(post.mImage.mData, post.mImage.mSize);
}
return true;
}
bool RsGxsPostedPostItem::toPostedPost(RsPostedPost &post, bool moveImage)
{
post = mPost;
post.mMeta = meta;
if (moveImage)
{
post.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
// mImage doesn't have a ShallowClear at the moment!
mImage.binData.TlvShallowClear();
}
else
{
post.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len);
}
return true;
}
void RsGxsPostedPostItem::clear()
{
mPost.mLink.clear();
mPost.mNotes.clear();
mImage.TlvClear();
}
void RsGxsPostedGroupItem::clear()
{
mGroup.mDescription.clear();
}

View file

@ -25,6 +25,7 @@
#include "rsitems/rsserviceids.h"
#include "rsitems/rsgxscommentitems.h"
#include "rsitems/rsgxsitems.h"
#include "serialiser/rstlvimage.h"
#include "retroshare/rsposted.h"
@ -38,9 +39,12 @@ public:
virtual ~RsGxsPostedGroupItem() {}
void clear();
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsPostedGroup mGroup;
};
class RsGxsPostedPostItem : public RsGxsMsgItem
@ -51,8 +55,14 @@ public:
void clear();
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
// Slightly unusual structure.
// use conversion functions to transform:
bool fromPostedPost(RsPostedPost &post, bool moveImage);
bool toPostedPost(RsPostedPost &post, bool moveImage);
RsPostedPost mPost;
RsTlvImage mImage;
};
class RsGxsPostedSerialiser : public RsGxsCommentSerialiser

View file

@ -123,6 +123,7 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msg
{
RsPostedPost msg = postItem->mPost;
msg.mMeta = postItem->meta;
postItem->toPostedPost(msg, true);
msg.calculateScores(now);
msgs.push_back(msg);
@ -291,8 +292,10 @@ bool p3Posted::createPost(uint32_t &token, RsPostedPost &msg)
std::cerr << std::endl;
RsGxsPostedPostItem* msgItem = new RsGxsPostedPostItem();
msgItem->mPost = msg;
msgItem->meta = msg.mMeta;
//msgItem->mPost = msg;
//msgItem->meta = msg.mMeta;
msgItem->fromPostedPost(msg, true);
RsGenExchange::publishMsg(token, msgItem);
return true;