Merge branch 'Attach-picture-for-Posted-links' into master

This commit is contained in:
defnax 2019-03-20 11:01:21 +01:00 committed by GitHub
commit 2233af4702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1903 additions and 1241 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,29 @@
#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") ;
// Do not serialize mImage member if it is empty (keeps compatibility of new posts without image toward older RS)
// and do not expect to deserialize mImage member if the data block has been consummed entirely (keeps compatibility
// of new RS with older posts.
if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize)
return ;
if((j == RsGenericSerializer::SIZE_ESTIMATE || j == RsGenericSerializer::SERIALIZE) && mImage.empty())
return ;
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 +61,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

@ -33,18 +33,19 @@
class RsTlvImage: public RsTlvItem
{
public:
RsTlvImage();
RsTlvImage(const RsTlvImage& );
virtual ~RsTlvImage() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
public:
RsTlvImage();
RsTlvImage(const RsTlvImage& );
virtual ~RsTlvImage() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
bool empty() const { return binData.bin_len == 0 ; }
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
uint32_t image_type; // Mandatory:
uint32_t image_type; // Mandatory:
RsTlvBinaryData binData; // Mandatory: serialised file info
};

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;