localHistoryStorage #5

Merged
blue merged 6 commits from localHistoryStorage into master 2019-05-15 17:39:54 +00:00
2 changed files with 66 additions and 51 deletions
Showing only changes of commit 1f450ad3e0 - Show all commits

View File

@ -148,12 +148,8 @@ void Core::Contact::performRequest(int count, const QString& before)
emit needEarlierHistory(before, "", QDateTime(), QDateTime()); emit needEarlierHistory(before, "", QDateTime(), QDateTime());
break; break;
case beginning: { case beginning: {
QString lBefore;
bool found = false; bool found = false;
if (appendCache.size() != 0) { if (appendCache.size() != 0) {
if (before.size() == 0) {
lBefore = appendCache.back().getId();
}
for (std::list<Shared::Message>::const_reverse_iterator itr = appendCache.rbegin(), end = appendCache.rend(); itr != end; ++itr) { for (std::list<Shared::Message>::const_reverse_iterator itr = appendCache.rbegin(), end = appendCache.rend(); itr != end; ++itr) {
const Shared::Message& msg = *itr; const Shared::Message& msg = *itr;
if (found) { if (found) {
@ -177,39 +173,15 @@ void Core::Contact::performRequest(int count, const QString& before)
} }
} }
if (found) { if (found) {
lBefore = responseCache.front().getId(); emit needEarlierHistory(responseCache.front().getId(), "", QDateTime(), QDateTime());
emit needEarlierHistory(lBefore, "", QDateTime(), QDateTime());
} else { } else {
std::list<Shared::Message> arc; if (requiestFromArchive(before)) {
if (responseCache.size() > 0) {
lBefore = responseCache.front().getId();
} else {
lBefore = before;
}
if (count != -1) {
try {
arc = archive->getBefore(requestedCount - receivedCount, lBefore);
responseCache.insert(responseCache.begin(), arc.begin(), arc.end());
emit historyResponse(responseCache);
nextRequest(); nextRequest();
} catch (Archive::NotFound e) {
requestCache.emplace_back(count, before);
requestedCount = -1;
emit needEarlierHistory("", archive->newestId(), QDateTime(), QDateTime());
}
} else {
try {
arc = archive->getBefore(1, lBefore);
//just do nothing since response is not required
nextRequest(); //may be even it's a signal that the history is now complete?
} catch (Archive::NotFound e) {
emit needEarlierHistory("", archive->newestId(), QDateTime(), QDateTime());
}
} }
} }
} }
break; break;
case end: case end: {
std::list<Shared::Message> arc; std::list<Shared::Message> arc;
if (count != -1) { if (count != -1) {
try { try {
@ -220,7 +192,7 @@ void Core::Contact::performRequest(int count, const QString& before)
} catch (Archive::NotFound e) { } catch (Archive::NotFound e) {
requestCache.emplace_back(count, before); requestCache.emplace_back(count, before);
requestedCount = -1; requestedCount = -1;
emit needEarlierHistory("", archive->newestId(), QDateTime(), QDateTime()); emit needEarlierHistory(archive->oldestId(), "", QDateTime(), QDateTime());
} }
} else { } else {
try { try {
@ -228,7 +200,8 @@ void Core::Contact::performRequest(int count, const QString& before)
//just do nothing since response is not required //just do nothing since response is not required
nextRequest(); //may be even it's a signal that the history is now complete? nextRequest(); //may be even it's a signal that the history is now complete?
} catch (Archive::NotFound e) { } catch (Archive::NotFound e) {
emit needEarlierHistory("", archive->newestId(), QDateTime(), QDateTime()); emit needEarlierHistory(archive->oldestId(), "", QDateTime(), QDateTime());
}
} }
} }
break; break;
@ -241,6 +214,47 @@ void Core::Contact::performRequest(int count, const QString& before)
} }
} }
bool Core::Contact::requiestFromArchive(const QString& before)
{
std::list<Shared::Message> arc;
QString lBefore;
if (responseCache.size() > 0) {
lBefore = responseCache.front().getId();
} else {
lBefore = before;
}
if (requestedCount != -1) {
try {
arc = archive->getBefore(requestedCount - receivedCount, lBefore);
responseCache.insert(responseCache.begin(), arc.begin(), arc.end());
emit historyResponse(responseCache);
return true;
} catch (Archive::NotFound e) {
requestCache.emplace_back(requestedCount, before);
requestedCount = -1;
switch (archiveState) {
case empty:
case beginning:
case end:
case chunk:
case complete:
}
emit needEarlierHistory("", archive->newestId(), QDateTime(), QDateTime());
return false;
}
} else {
try {
arc = archive->getBefore(1, lBefore);
//just do nothing since response is not required
//may be even it's a signal that the history is now complete?
return true;
} catch (Archive::NotFound e) {
emit needEarlierHistory("", archive->newestId(), QDateTime(), QDateTime());
return false;
}
}
}
void Core::Contact::appendMessageToArchive(const Shared::Message& msg) void Core::Contact::appendMessageToArchive(const Shared::Message& msg)
{ {

View File

@ -83,6 +83,7 @@ private:
private: private:
void nextRequest(); void nextRequest();
void performRequest(int count, const QString& before); void performRequest(int count, const QString& before);
bool requiestFromArchive(const QString& before);
}; };
} }