From b5910e03149b47b02d9e10066e71c6ed71bff6a2 Mon Sep 17 00:00:00 2001 From: drbob Date: Wed, 14 Nov 2012 21:27:37 +0000 Subject: [PATCH] * Updated wiki service to support new MsgRelated data. * Added Wiki Dummy pages to explain it briefly. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5821 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/libretroshare.pro | 3 + libretroshare/src/retroshare/rswiki.h | 2 + libretroshare/src/services/p3wiki.cc | 262 +++++++++++++++++++++++++- libretroshare/src/services/p3wiki.h | 14 ++ 4 files changed, 280 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 6b3331d93..7a84059c1 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -482,6 +482,7 @@ HEADERS += retroshare/rsgame.h \ pqi/pqiqosstreamer.cc \ pqi/sslfns.cc \ pqi/pqinetstatebox.cc + SOURCES += rsserver/p3discovery.cc \ rsserver/p3face-config.cc \ rsserver/p3face-msgs.cc \ @@ -495,9 +496,11 @@ HEADERS += retroshare/rsgame.h \ rsserver/rsloginhandler.cc \ rsserver/rstypes.cc \ rsserver/p3serverconfig.cc + SOURCES += plugins/pluginmanager.cc \ plugins/dlfcn_win32.cc \ serialiser/rspluginitems.cc + SOURCES += serialiser/rsbaseitems.cc \ serialiser/rsbaseserial.cc \ serialiser/rsblogitems.cc \ diff --git a/libretroshare/src/retroshare/rswiki.h b/libretroshare/src/retroshare/rswiki.h index 3a4648e2b..0c5d507d3 100644 --- a/libretroshare/src/retroshare/rswiki.h +++ b/libretroshare/src/retroshare/rswiki.h @@ -125,6 +125,8 @@ virtual bool getCollections(const uint32_t &token, std::vector virtual bool getSnapshots(const uint32_t &token, std::vector &snapshots) = 0; virtual bool getComments(const uint32_t &token, std::vector &comments) = 0; +virtual bool getRelatedSnapshots(const uint32_t &token, std::vector &snapshots) = 0; + virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection) = 0; virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot) = 0; virtual bool submitComment(uint32_t &token, RsWikiComment &comment) = 0; diff --git a/libretroshare/src/services/p3wiki.cc b/libretroshare/src/services/p3wiki.cc index ab75282cd..508f5fed9 100644 --- a/libretroshare/src/services/p3wiki.cc +++ b/libretroshare/src/services/p3wiki.cc @@ -40,10 +40,14 @@ p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes) { + // Setup of dummy Pages. + mAboutActive = false; + mImprovActive = false; } void p3Wiki::service_tick() { + dummyTick(); return; } @@ -136,6 +140,44 @@ bool p3Wiki::getSnapshots(const uint32_t &token, std::vector &sn } +bool p3Wiki::getRelatedSnapshots(const uint32_t &token, std::vector &snapshots) +{ + GxsMsgRelatedDataMap msgData; + bool ok = RsGenExchange::getMsgRelatedData(token, msgData); + + if(ok) + { + GxsMsgRelatedDataMap::iterator mit = msgData.begin(); + + for(; mit != msgData.end(); mit++) + { + std::vector& msgItems = mit->second; + std::vector::iterator vit = msgItems.begin(); + + for(; vit != msgItems.end(); vit++) + { + RsGxsWikiSnapshotItem* item = dynamic_cast(*vit); + + if(item) + { + RsWikiSnapshot snapshot = item->snapshot; + snapshot.mMeta = item->meta; + snapshots.push_back(snapshot); + delete item; + } + else + { + std::cerr << "Not a WikiSnapshot Item, deleting!" << std::endl; + delete *vit; + } + } + } + } + + return ok; +} + + bool p3Wiki::getComments(const uint32_t &token, std::vector &comments) { GxsMsgDataMap msgData; @@ -264,10 +306,44 @@ std::string p3Wiki::genRandomId() return randomId; } +const int about_len = 10; +const std::string about_txt[] = + { "Welcome to RsWiki, a fully distributed Wiki system that anyone can edit.", + "Please read through these dummy Wiki pages to learn how it should work\n", + "Basic Functionality:", + " - New Group: creates a collection of Wiki Pages, the creator of group", + " and anyone they share the publish keys with) is the moderator\n", + " - New Page: Create a new Wiki Page, only Group Moderators can do this\n", + " - Edit: Anyone Can Edit the Wiki Page, and the changes form a tree under the original\n", + " - RePublish: This is used by the Moderators to accept and reject Edits.", + " the republished page becomes a new version of the Root Page, allowing more edits to be done\n", + "Please read the improvements section to see how we envision the wiki's working", + }; + + +const int improvements_len = 14; +const std::string improvements_txt[] = + { "As you can see, the current Wiki is a basic framework waiting to be expanded.", + "There are lots of potential improvements... some of my ideas are listed below\n", + "Ideas:", + " - Formatting: No HTML, lets use Markdown or something similar.\n", + " - Diffs, lots of edits will lead to complex merges - a robust merge tool is essential\n", + " - Read Mode... hide all the Edits, and only show the most recently published versions\n", + " - Easy Duplication - to take over an Abandoned or badly moderated Wiki. Copies All base versions to a new group\n", + " - WikiLinks. A generic Wiki Cross Linking system. This should be combined with Easy Duplication option,\n", + " to allow easy replacement of groups if necessary... A good design here is critical to a successful Wiki ecosystem", + " the republished page becomes a new version of the Root Page, allowing more edits to be done\n", + " - work out how to include media (photos, audio, video, etc) without embedding in pages", + " this would leverage the turtle transfer system somehow - maybe like channels.\n", + " - Comments, reviews etc can be incorporated - ideas here are welcome.\n", + " - Any other suggestion???" + }; + + void p3Wiki::generateDummyData() { -#define GEN_COLLECTIONS 10 +#define GEN_COLLECTIONS 0 int i; for(i = 0; i < GEN_COLLECTIONS; i++) @@ -280,7 +356,191 @@ void p3Wiki::generateDummyData() uint32_t dummyToken = 0; submitCollection(dummyToken, wiki); } + + + RsWikiCollection wiki; + wiki.mMeta.mGroupFlags = 0; + wiki.mMeta.mGroupName = "About RsWiki"; + + submitCollection(mAboutToken, wiki); + + wiki.mMeta.mGroupFlags = 0; + wiki.mMeta.mGroupName = "RsWiki Improvements"; + + submitCollection(mImprovToken, wiki); + + mAboutLines = 0; + mImprovLines = 0; + + mAboutActive = true; + mImprovActive = true; +} + + +bool generateNextDummyPage(const RsGxsMessageId &threadId, const int lines, const RsGxsGrpMsgIdPair &parentId, + const std::string *page_lines, const int num_pagelines, RsWikiSnapshot &snapshot) +{ + snapshot.mMeta.mGroupId = parentId.first; + + // Create an About Page. +#define NUM_SUB_PAGES 3 + + if ((lines % NUM_SUB_PAGES == 0) || (lines == num_pagelines)) + { + /* do a new baseline */ + snapshot.mMeta.mOrigMsgId = threadId; + } + else + { + snapshot.mMeta.mParentId = parentId.second; + snapshot.mMeta.mThreadId = threadId; + } + + std::string page; + for(int i = 0; (i < lines) && (i < num_pagelines); i++) + { + snapshot.mPage += page_lines[i]; + snapshot.mPage += '\n'; + } + + return (lines <= num_pagelines); +} + + +void p3Wiki::dummyTick() +{ + if (mAboutActive) + { + std::cerr << "p3Wiki::dummyTick() AboutActive"; + std::cerr << std::endl; + + uint32_t status = RsGenExchange::getTokenService()->requestStatus(mAboutToken); + + if (status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE) + { + std::cerr << "p3Wiki::dummyTick() AboutActive, Lines: " << mAboutLines; + std::cerr << std::endl; + + if (mAboutLines == 0) + { + /* get the group Id */ + RsGxsGroupId groupId; + if (!acknowledgeTokenGrp(mAboutToken, groupId)) + { + std::cerr << " ERROR "; + std::cerr << std::endl; + mAboutActive = false; + } + + /* create baseline snapshot */ + RsWikiSnapshot page; + page.mMeta.mGroupId = groupId; + page.mPage = "Baseline page... a placeholder for About Wiki"; + page.mMeta.mMsgName = "About RsWiki"; + + submitSnapshot(mAboutToken, page); + mAboutLines++; + } + else + { + /* get the msg Id, and generate next snapshot */ + RsGxsGrpMsgIdPair msgId; + if (!acknowledgeTokenMsg(mAboutToken, msgId)) + { + std::cerr << " ERROR "; + std::cerr << std::endl; + mAboutActive = false; + } + + if (mAboutLines == 1) + { + mAboutThreadId = msgId.second; + } + + RsWikiSnapshot page; + page.mMeta.mMsgName = "About RsWiki"; + if (!generateNextDummyPage(mAboutThreadId, mAboutLines, msgId, about_txt, about_len, page)) + { + std::cerr << "About Pages Done"; + std::cerr << std::endl; + mAboutActive = false; + } + else + { + mAboutLines++; + submitSnapshot(mAboutToken, page); + } + } + } + } + + if (mImprovActive) + { + std::cerr << "p3Wiki::dummyTick() ImprovActive"; + std::cerr << std::endl; + + uint32_t status = RsGenExchange::getTokenService()->requestStatus(mImprovToken); + + if (status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE) + { + std::cerr << "p3Wiki::dummyTick() ImprovActive, Lines: " << mImprovLines; + std::cerr << std::endl; + + if (mImprovLines == 0) + { + /* get the group Id */ + RsGxsGroupId groupId; + if (!acknowledgeTokenGrp(mImprovToken, groupId)) + { + std::cerr << " ERROR "; + std::cerr << std::endl; + mImprovActive = false; + } + + /* create baseline snapshot */ + RsWikiSnapshot page; + page.mMeta.mGroupId = groupId; + page.mPage = "Baseline page... a placeholder for Improv Wiki"; + page.mMeta.mMsgName = "Improv RsWiki"; + + submitSnapshot(mImprovToken, page); + mImprovLines++; + } + else + { + /* get the msg Id, and generate next snapshot */ + RsGxsGrpMsgIdPair msgId; + if (!acknowledgeTokenMsg(mImprovToken, msgId)) + { + std::cerr << " ERROR "; + std::cerr << std::endl; + mImprovActive = false; + } + + if (mImprovLines == 1) + { + mImprovThreadId = msgId.second; + } + + RsWikiSnapshot page; + page.mMeta.mMsgName = "Improv RsWiki"; + if (!generateNextDummyPage(mImprovThreadId, mImprovLines, msgId, improvements_txt, improvements_len, page)) + { + std::cerr << "Improv Pages Done"; + std::cerr << std::endl; + mImprovActive = false; + } + else + { + mImprovLines++; + submitSnapshot(mImprovToken, page); + } + } + } + } } + + diff --git a/libretroshare/src/services/p3wiki.h b/libretroshare/src/services/p3wiki.h index 11e347cf1..01d82767e 100644 --- a/libretroshare/src/services/p3wiki.h +++ b/libretroshare/src/services/p3wiki.h @@ -56,6 +56,8 @@ virtual bool getCollections(const uint32_t &token, std::vector virtual bool getSnapshots(const uint32_t &token, std::vector &snapshots); virtual bool getComments(const uint32_t &token, std::vector &comments); +virtual bool getRelatedSnapshots(const uint32_t &token, std::vector &snapshots); + virtual bool submitCollection(uint32_t &token, RsWikiCollection &collection); virtual bool submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot); virtual bool submitComment(uint32_t &token, RsWikiComment &comment); @@ -68,6 +70,18 @@ std::string genRandomId(); // RsMutex mWikiMtx; + // Dummy Stuff. + void dummyTick(); + + bool mAboutActive; + uint32_t mAboutToken; + int mAboutLines; + RsGxsMessageId mAboutThreadId; + + bool mImprovActive; + uint32_t mImprovToken; + int mImprovLines; + RsGxsMessageId mImprovThreadId; }; #endif