Merge pull request #1683 from defnax/distant-chat-settings

added distant chat settings for store/load
This commit is contained in:
csoler 2019-10-14 13:41:52 +02:00 committed by GitHub
commit 98c1a34ab9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 2716 additions and 58 deletions

View file

@ -48,10 +48,13 @@ p3HistoryMgr::p3HistoryMgr()
mPublicEnable = false;
mPrivateEnable = true;
mLobbyEnable = true;
mDistantEnable = true;
mPublicSaveCount = 0;
mLobbySaveCount = 0;
mPrivateSaveCount = 0;
mDistantSaveCount = 0;
mLastCleanTime = 0 ;
mMaxStorageDurationSeconds = 10*86400 ; // store for 10 days at most.
@ -99,7 +102,7 @@ void p3HistoryMgr::addMessage(const ChatMessage& cm)
enabled = true;
}
if(cm.chat_id.isDistantChatId())
if(cm.chat_id.isDistantChatId()&& mDistantEnable == true)
{
DistantChatPeerInfo dcpinfo;
if (rsMsgs->getDistantChatStatus(cm.chat_id.toDistantChatId(), dcpinfo))
@ -272,6 +275,10 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list<RsItem*>& saveData)
kv.key = "LOBBY_ENABLE";
kv.value = mLobbyEnable ? "TRUE" : "FALSE";
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "DISTANT_ENABLE";
kv.value = mDistantEnable ? "TRUE" : "FALSE";
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "MAX_STORAGE_TIME";
rs_sprintf(kv.value,"%d",mMaxStorageDurationSeconds) ;
@ -288,6 +295,10 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list<RsItem*>& saveData)
kv.key = "PRIVATE_SAVECOUNT";
rs_sprintf(kv.value, "%lu", mPrivateSaveCount);
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "DISTANT_SAVECOUNT";
rs_sprintf(kv.value, "%lu", mDistantSaveCount);
vitem->tlvkvs.pairs.push_back(kv);
saveData.push_back(vitem);
saveCleanupList.push_back(vitem);
@ -357,6 +368,11 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
mLobbyEnable = (kit->value == "TRUE") ? true : false;
continue;
}
if (kit->key == "DISTANT_ENABLE") {
mDistantEnable = (kit->value == "TRUE") ? true : false;
continue;
}
if (kit->key == "MAX_STORAGE_TIME") {
uint32_t val ;
@ -381,6 +397,10 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
mLobbySaveCount = atoi(kit->value.c_str());
continue;
}
if (kit->key == "DISTANT_SAVECOUNT") {
mDistantSaveCount = atoi(kit->value.c_str());
continue;
}
}
delete (*it);
@ -458,7 +478,7 @@ bool p3HistoryMgr::getMessages(const ChatId &chatId, std::list<HistoryMsg> &msgs
if (chatId.isLobbyId() && mLobbyEnable == true) {
enabled = true;
}
if (chatId.isDistantChatId() && mPrivateEnable == true) {
if (chatId.isDistantChatId() && mDistantEnable == true) {
enabled = true;
}
@ -600,6 +620,7 @@ bool p3HistoryMgr::getEnable(uint32_t chat_type)
case RS_HISTORY_TYPE_PUBLIC : return mPublicEnable ;
case RS_HISTORY_TYPE_LOBBY : return mLobbyEnable ;
case RS_HISTORY_TYPE_PRIVATE: return mPrivateEnable ;
case RS_HISTORY_TYPE_DISTANT: return mDistantEnable ;
default:
std::cerr << "Unexpected value " << chat_type<< " in p3HistoryMgr::getEnable(): this is a bug." << std::endl;
return 0 ;
@ -637,6 +658,9 @@ void p3HistoryMgr::setEnable(uint32_t chat_type, bool enable)
case RS_HISTORY_TYPE_PRIVATE: oldValue = mPrivateEnable ;
mPrivateEnable = enable ;
break ;
case RS_HISTORY_TYPE_DISTANT: oldValue = mDistantEnable ;
mDistantEnable = enable ;
break ;
default:
return;
}

View file

@ -82,10 +82,12 @@ private:
bool mPublicEnable;
bool mLobbyEnable;
bool mPrivateEnable;
bool mDistantEnable;
uint32_t mPublicSaveCount;
uint32_t mLobbySaveCount;
uint32_t mPrivateSaveCount;
uint32_t mDistantSaveCount;
uint32_t mMaxStorageDurationSeconds ;
rstime_t mLastCleanTime ;

View file

@ -39,6 +39,7 @@ extern RsHistory *rsHistory;
static const uint32_t RS_HISTORY_TYPE_PUBLIC = 0 ;
static const uint32_t RS_HISTORY_TYPE_PRIVATE = 1 ;
static const uint32_t RS_HISTORY_TYPE_LOBBY = 2 ;
static const uint32_t RS_HISTORY_TYPE_DISTANT = 3 ;
class HistoryMsg
{