achive from the beginning memorizing bugfix, limitation of the requests in the model
This commit is contained in:
parent
e0ef1ef797
commit
270a32db9e
@ -434,13 +434,13 @@ void Core::Account::requestArchive(const QString& jid, int count, const QString&
|
|||||||
|
|
||||||
if (contact == 0) {
|
if (contact == 0) {
|
||||||
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the contact with such id wasn't found, skipping";
|
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the contact with such id wasn't found, skipping";
|
||||||
emit responseArchive(jid, std::list<Shared::Message>());
|
emit responseArchive(jid, std::list<Shared::Message>(), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state != Shared::ConnectionState::connected) {
|
if (state != Shared::ConnectionState::connected) {
|
||||||
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the account is not online, skipping";
|
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the account is not online, skipping";
|
||||||
emit responseArchive(contact->jid, std::list<Shared::Message>());
|
emit responseArchive(contact->jid, std::list<Shared::Message>(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
contact->requestHistory(count, before);
|
contact->requestHistory(count, before);
|
||||||
@ -909,3 +909,13 @@ void Core::Account::handleDisconnection()
|
|||||||
ownVCardRequestInProgress = false;
|
ownVCardRequestInProgress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::Account::onContactHistoryResponse(const std::list<Shared::Message>& list, bool last)
|
||||||
|
{
|
||||||
|
RosterItem* contact = static_cast<RosterItem*>(sender());
|
||||||
|
|
||||||
|
qDebug() << "Collected history for contact " << contact->jid << list.size() << "elements";
|
||||||
|
if (last) {
|
||||||
|
qDebug() << "The response contains the first accounted message";
|
||||||
|
}
|
||||||
|
emit responseArchive(contact->jid, list, last);
|
||||||
|
}
|
||||||
|
@ -127,7 +127,7 @@ signals:
|
|||||||
void removePresence(const QString& jid, const QString& name);
|
void removePresence(const QString& jid, const QString& name);
|
||||||
void message(const Shared::Message& data);
|
void message(const Shared::Message& data);
|
||||||
void changeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
|
void changeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
|
||||||
void responseArchive(const QString& jid, const std::list<Shared::Message>& list);
|
void responseArchive(const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||||
void error(const QString& text);
|
void error(const QString& text);
|
||||||
void addRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
|
void addRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
|
||||||
void changeRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
|
void changeRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
|
||||||
@ -183,6 +183,7 @@ private slots:
|
|||||||
|
|
||||||
void onDiscoveryItemsReceived (const QXmppDiscoveryIq& items);
|
void onDiscoveryItemsReceived (const QXmppDiscoveryIq& items);
|
||||||
void onDiscoveryInfoReceived (const QXmppDiscoveryIq& info);
|
void onDiscoveryInfoReceived (const QXmppDiscoveryIq& info);
|
||||||
|
void onContactHistoryResponse(const std::list<Shared::Message>& list, bool last);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleDisconnection();
|
void handleDisconnection();
|
||||||
|
@ -502,8 +502,9 @@ long unsigned int Core::Archive::size() const
|
|||||||
mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
|
mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
|
||||||
MDB_stat stat;
|
MDB_stat stat;
|
||||||
mdb_stat(txn, order, &stat);
|
mdb_stat(txn, order, &stat);
|
||||||
|
size_t amount = stat.ms_entries;
|
||||||
mdb_txn_abort(txn);
|
mdb_txn_abort(txn);
|
||||||
return stat.ms_entries;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Shared::Message> Core::Archive::getBefore(int count, const QString& id)
|
std::list<Shared::Message> Core::Archive::getBefore(int count, const QString& id)
|
||||||
@ -603,10 +604,10 @@ void Core::Archive::setFromTheBeginning(bool is)
|
|||||||
MDB_txn *txn;
|
MDB_txn *txn;
|
||||||
mdb_txn_begin(environment, NULL, 0, &txn);
|
mdb_txn_begin(environment, NULL, 0, &txn);
|
||||||
bool success = setStatValue("beginning", is, txn);
|
bool success = setStatValue("beginning", is, txn);
|
||||||
if (success != 0) {
|
if (success) {
|
||||||
mdb_txn_abort(txn);
|
|
||||||
} else {
|
|
||||||
mdb_txn_commit(txn);
|
mdb_txn_commit(txn);
|
||||||
|
} else {
|
||||||
|
mdb_txn_abort(txn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ void Core::RosterHandler::removeContactRequest(const QString& jid)
|
|||||||
void Core::RosterHandler::handleNewRosterItem(Core::RosterItem* contact)
|
void Core::RosterHandler::handleNewRosterItem(Core::RosterItem* contact)
|
||||||
{
|
{
|
||||||
connect(contact, &RosterItem::needHistory, this->acc, &Account::onContactNeedHistory);
|
connect(contact, &RosterItem::needHistory, this->acc, &Account::onContactNeedHistory);
|
||||||
connect(contact, &RosterItem::historyResponse, this, &RosterHandler::onContactHistoryResponse);
|
connect(contact, &RosterItem::historyResponse, this->acc, &Account::onContactHistoryResponse);
|
||||||
connect(contact, &RosterItem::nameChanged, this, &RosterHandler::onContactNameChanged);
|
connect(contact, &RosterItem::nameChanged, this, &RosterHandler::onContactNameChanged);
|
||||||
connect(contact, &RosterItem::avatarChanged, this, &RosterHandler::onContactAvatarChanged);
|
connect(contact, &RosterItem::avatarChanged, this, &RosterHandler::onContactAvatarChanged);
|
||||||
connect(contact, &RosterItem::requestVCard, this->acc, &Account::requestVCard);
|
connect(contact, &RosterItem::requestVCard, this->acc, &Account::requestVCard);
|
||||||
@ -315,14 +315,6 @@ void Core::RosterHandler::removeFromGroup(const QString& jid, const QString& gro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::RosterHandler::onContactHistoryResponse(const std::list<Shared::Message>& list)
|
|
||||||
{
|
|
||||||
RosterItem* contact = static_cast<RosterItem*>(sender());
|
|
||||||
|
|
||||||
qDebug() << "Collected history for contact " << contact->jid << list.size() << "elements";
|
|
||||||
emit acc->responseArchive(contact->jid, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid)
|
Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid)
|
||||||
{
|
{
|
||||||
RosterItem* item = 0;
|
RosterItem* item = 0;
|
||||||
|
@ -86,7 +86,6 @@ private slots:
|
|||||||
void onContactGroupRemoved(const QString& group);
|
void onContactGroupRemoved(const QString& group);
|
||||||
void onContactNameChanged(const QString& name);
|
void onContactNameChanged(const QString& name);
|
||||||
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
|
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
|
||||||
void onContactHistoryResponse(const std::list<Shared::Message>& list);
|
|
||||||
void onContactAvatarChanged(Shared::Avatar, const QString& path);
|
void onContactAvatarChanged(Shared::Avatar, const QString& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -122,7 +122,20 @@ void Core::RosterItem::nextRequest()
|
|||||||
{
|
{
|
||||||
if (syncronizing) {
|
if (syncronizing) {
|
||||||
if (requestedCount != -1) {
|
if (requestedCount != -1) {
|
||||||
emit historyResponse(responseCache);
|
bool last = false;
|
||||||
|
if (archiveState == beginning || archiveState == complete) {
|
||||||
|
QString firstId = archive->oldestId();
|
||||||
|
if (responseCache.size() == 0) {
|
||||||
|
if (requestedBefore == firstId) {
|
||||||
|
last = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (responseCache.front().getId() == firstId) {
|
||||||
|
last = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit historyResponse(responseCache, last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestCache.size() > 0) {
|
if (requestCache.size() > 0) {
|
||||||
@ -529,7 +542,7 @@ void Core::RosterItem::clearArchiveRequests()
|
|||||||
requestedBefore = "";
|
requestedBefore = "";
|
||||||
for (const std::pair<int, QString>& pair : requestCache) {
|
for (const std::pair<int, QString>& pair : requestCache) {
|
||||||
if (pair.first != -1) {
|
if (pair.first != -1) {
|
||||||
emit historyResponse(responseCache); //just to notify those who still waits with whatever happened to be left in caches yet
|
emit historyResponse(responseCache, false); //just to notify those who still waits with whatever happened to be left in caches yet
|
||||||
}
|
}
|
||||||
responseCache.clear();
|
responseCache.clear();
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void nameChanged(const QString& name);
|
void nameChanged(const QString& name);
|
||||||
void subscriptionStateChanged(Shared::SubscriptionState state);
|
void subscriptionStateChanged(Shared::SubscriptionState state);
|
||||||
void historyResponse(const std::list<Shared::Message>& messages);
|
void historyResponse(const std::list<Shared::Message>& messages, bool last);
|
||||||
void needHistory(const QString& before, const QString& after, const QDateTime& afterTime = QDateTime());
|
void needHistory(const QString& before, const QString& after, const QDateTime& afterTime = QDateTime());
|
||||||
void avatarChanged(Shared::Avatar, const QString& path);
|
void avatarChanged(Shared::Avatar, const QString& path);
|
||||||
void requestVCard(const QString& jid);
|
void requestVCard(const QString& jid);
|
||||||
|
@ -357,10 +357,10 @@ void Core::Squawk::requestArchive(const QString& account, const QString& jid, in
|
|||||||
itr->second->requestArchive(jid, count, before);
|
itr->second->requestArchive(jid, count, before);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Squawk::onAccountResponseArchive(const QString& jid, const std::list<Shared::Message>& list)
|
void Core::Squawk::onAccountResponseArchive(const QString& jid, const std::list<Shared::Message>& list, bool last)
|
||||||
{
|
{
|
||||||
Account* acc = static_cast<Account*>(sender());
|
Account* acc = static_cast<Account*>(sender());
|
||||||
emit responseArchive(acc->getName(), jid, list);
|
emit responseArchive(acc->getName(), jid, list, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Squawk::modifyAccountRequest(const QString& name, const QMap<QString, QVariant>& map)
|
void Core::Squawk::modifyAccountRequest(const QString& name, const QMap<QString, QVariant>& map)
|
||||||
|
@ -64,7 +64,7 @@ signals:
|
|||||||
void removePresence(const QString& account, const QString& jid, const QString& name);
|
void removePresence(const QString& account, const QString& jid, const QString& name);
|
||||||
void stateChanged(Shared::Availability state);
|
void stateChanged(Shared::Availability state);
|
||||||
void accountMessage(const QString& account, const Shared::Message& data);
|
void accountMessage(const QString& account, const Shared::Message& data);
|
||||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list);
|
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||||
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||||
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||||
void removeRoom(const QString& account, const QString jid);
|
void removeRoom(const QString& account, const QString jid);
|
||||||
@ -146,7 +146,7 @@ private slots:
|
|||||||
void onAccountAddPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
void onAccountAddPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
||||||
void onAccountRemovePresence(const QString& jid, const QString& name);
|
void onAccountRemovePresence(const QString& jid, const QString& name);
|
||||||
void onAccountMessage(const Shared::Message& data);
|
void onAccountMessage(const Shared::Message& data);
|
||||||
void onAccountResponseArchive(const QString& jid, const std::list<Shared::Message>& list);
|
void onAccountResponseArchive(const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||||
void onAccountAddRoom(const QString jid, const QMap<QString, QVariant>& data);
|
void onAccountAddRoom(const QString jid, const QMap<QString, QVariant>& data);
|
||||||
void onAccountChangeRoom(const QString jid, const QMap<QString, QVariant>& data);
|
void onAccountChangeRoom(const QString jid, const QMap<QString, QVariant>& data);
|
||||||
void onAccountRemoveRoom(const QString jid);
|
void onAccountRemoveRoom(const QString jid);
|
||||||
|
@ -145,9 +145,9 @@ void Models::Element::changeMessage(const QString& id, const QMap<QString, QVari
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Models::Element::responseArchive(const std::list<Shared::Message> list)
|
void Models::Element::responseArchive(const std::list<Shared::Message> list, bool last)
|
||||||
{
|
{
|
||||||
feed->responseArchive(list);
|
feed->responseArchive(list, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Models::Element::isRoom() const
|
bool Models::Element::isRoom() const
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
void addMessage(const Shared::Message& data);
|
void addMessage(const Shared::Message& data);
|
||||||
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
||||||
unsigned int getMessagesCount() const;
|
unsigned int getMessagesCount() const;
|
||||||
void responseArchive(const std::list<Shared::Message> list);
|
void responseArchive(const std::list<Shared::Message> list, bool last);
|
||||||
bool isRoom() const;
|
bool isRoom() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -166,6 +166,7 @@ bool Models::MessageFeed::canFetchMore(const QModelIndex& parent) const
|
|||||||
void Models::MessageFeed::fetchMore(const QModelIndex& parent)
|
void Models::MessageFeed::fetchMore(const QModelIndex& parent)
|
||||||
{
|
{
|
||||||
if (syncState == incomplete) {
|
if (syncState == incomplete) {
|
||||||
|
syncState = syncing;
|
||||||
emit requestStateChange(true);
|
emit requestStateChange(true);
|
||||||
|
|
||||||
if (storage.size() == 0) {
|
if (storage.size() == 0) {
|
||||||
@ -176,12 +177,9 @@ void Models::MessageFeed::fetchMore(const QModelIndex& parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list)
|
void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list, bool last)
|
||||||
{
|
{
|
||||||
Storage::size_type size = storage.size();
|
Storage::size_type size = storage.size();
|
||||||
if (syncState == syncing) {
|
|
||||||
emit requestStateChange(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), size, size + list.size() - 1);
|
beginInsertRows(QModelIndex(), size, size + list.size() - 1);
|
||||||
for (const Shared::Message& msg : list) {
|
for (const Shared::Message& msg : list) {
|
||||||
@ -189,6 +187,15 @@ void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list)
|
|||||||
storage.insert(copy);
|
storage.insert(copy);
|
||||||
}
|
}
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
|
if (syncState == syncing) {
|
||||||
|
if (last) {
|
||||||
|
syncState = complete;
|
||||||
|
} else {
|
||||||
|
syncState = incomplete;
|
||||||
|
}
|
||||||
|
emit requestStateChange(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> Models::MessageFeed::roleNames() const
|
QHash<int, QByteArray> Models::MessageFeed::roleNames() const
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
void fetchMore(const QModelIndex & parent) override;
|
void fetchMore(const QModelIndex & parent) override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
void responseArchive(const std::list<Shared::Message> list);
|
void responseArchive(const std::list<Shared::Message> list, bool last);
|
||||||
|
|
||||||
unsigned int unreadMessagesCount() const;
|
unsigned int unreadMessagesCount() const;
|
||||||
|
|
||||||
|
@ -965,16 +965,16 @@ void Models::Roster::onElementRequestArchive(const QString& before)
|
|||||||
emit requestArchive(el->getAccountName(), el->getJid(), before);
|
emit requestArchive(el->getAccountName(), el->getJid(), before);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Models::Roster::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list)
|
void Models::Roster::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last)
|
||||||
{
|
{
|
||||||
ElId id(account, jid);
|
ElId id(account, jid);
|
||||||
std::map<ElId, Contact*>::iterator itr = contacts.find(id);
|
std::map<ElId, Contact*>::iterator itr = contacts.find(id);
|
||||||
if (itr != contacts.end()) {
|
if (itr != contacts.end()) {
|
||||||
itr->second->responseArchive(list);
|
itr->second->responseArchive(list, last);
|
||||||
} else {
|
} else {
|
||||||
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
std::map<ElId, Room*>::const_iterator rItr = rooms.find(id);
|
||||||
if (rItr != rooms.end()) {
|
if (rItr != rooms.end()) {
|
||||||
rItr->second->responseArchive(list);
|
rItr->second->responseArchive(list, last);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
Account* getAccount(const QString& name);
|
Account* getAccount(const QString& name);
|
||||||
QModelIndex getAccountIndex(const QString& name);
|
QModelIndex getAccountIndex(const QString& name);
|
||||||
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
||||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list);
|
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||||
|
|
||||||
Accounts* accountsModel;
|
Accounts* accountsModel;
|
||||||
|
|
||||||
|
@ -610,9 +610,9 @@ void Squawk::onConversationRequestArchive(const QString& account, const QString&
|
|||||||
emit requestArchive(account, jid, 20, before); //TODO amount as a settings value
|
emit requestArchive(account, jid, 20, before); //TODO amount as a settings value
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squawk::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list)
|
void Squawk::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last)
|
||||||
{
|
{
|
||||||
rosterModel.responseArchive(account, jid, list);
|
rosterModel.responseArchive(account, jid, list, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Squawk::removeAccount(const QString& account)
|
void Squawk::removeAccount(const QString& account)
|
||||||
|
@ -97,7 +97,7 @@ public slots:
|
|||||||
void removePresence(const QString& account, const QString& jid, const QString& name);
|
void removePresence(const QString& account, const QString& jid, const QString& name);
|
||||||
void stateChanged(Shared::Availability state);
|
void stateChanged(Shared::Availability state);
|
||||||
void accountMessage(const QString& account, const Shared::Message& data);
|
void accountMessage(const QString& account, const Shared::Message& data);
|
||||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list);
|
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||||
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||||
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
||||||
void removeRoom(const QString& account, const QString jid);
|
void removeRoom(const QString& account, const QString jid);
|
||||||
|
Loading…
Reference in New Issue
Block a user