Automatically refresh conversations list

This commit is contained in:
Pierre HUBERT 2019-01-15 10:18:08 +01:00
parent 4fda88d735
commit 222ed61c8a
3 changed files with 42 additions and 6 deletions

View File

@ -23,12 +23,19 @@
#define API_SERVICE_TOKEN "cWHlmMS5A1"
/**
* Conversations list information
*/
#define CONVERSATION_LIST_REFRESH_INTERVAL 10
/**
* Settings information
*/
#define SETTINGS_ACCOUNT_LOGIN_TOKEN_1 "account_login_token_1"
#define SETTINGS_ACCOUNT_LOGIN_TOKEN_2 "account_login_token_2"
/**
* Conversations information
*/

View File

@ -1,5 +1,6 @@
#include <QMessageBox>
#include <QVBoxLayout>
#include <QTimer>
#include "conversationslistwidget.h"
#include "conversationitemwidget.h"
@ -7,6 +8,7 @@
#include "../helpers/usershelper.h"
#include "../data/conversationslist.h"
#include "../utils/uiutils.h"
#include "../config.h"
ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
QWidget(parent)
@ -21,6 +23,12 @@ ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
//Set conversations list layout
new QVBoxLayout(this);
//Automatically refresh at a regular interval the list of conversations
mTimer = new QTimer();
mTimer->setInterval(CONVERSATION_LIST_REFRESH_INTERVAL*1000);
connect(mTimer, &QTimer::timeout, this, &ConversationsListWidget::refresh);
mTimer->start();
}
ConversationsListWidget::~ConversationsListWidget()
@ -69,6 +77,9 @@ void ConversationsListWidget::onGotUsersInfo(bool success, const UsersList &user
connect(item, &ConversationItemWidget::openConversation, this, &ConversationsListWidget::onRequestOpenConversation);
layout()->addWidget(item);
}
//Make sure selected conversation is highlighted
refreshSelectedConversation();
}
void ConversationsListWidget::onRequestOpenConversation()
@ -86,9 +97,14 @@ void ConversationsListWidget::setCurrentConversation(const Conversation &current
{
mCurrentConversation = currentConversation;
refreshSelectedConversation();
}
void ConversationsListWidget::refreshSelectedConversation()
{
//Update UI
for(int i = 0; i < layout()->count(); i++){
ConversationItemWidget *widget = qobject_cast<ConversationItemWidget *>(layout()->itemAt(i)->widget());
widget->setActive(widget->currentConversation().iD() == currentConversation.iD());
widget->setActive(widget->currentConversation().iD() == mCurrentConversation.iD());
}
}

View File

@ -7,6 +7,8 @@
#include "../data/userslist.h"
#include "../data/user.h"
class QTimer;
class ConversationsListHelper;
class UsersHelper;
@ -18,11 +20,6 @@ public:
explicit ConversationsListWidget(QWidget *parent = nullptr);
~ConversationsListWidget();
/**
* Refresh the list of conversations of the user
*/
void refresh();
/**
* This method is used to update the currently active conversation
*
@ -30,6 +27,19 @@ public:
*/
void setCurrentConversation(const Conversation &currentConversation);
/**
* Update the UI to select the currently active conversation
*/
void refreshSelectedConversation();
public slots:
/**
* Refresh the list of conversations of the user
*/
void refresh();
signals:
/**
@ -72,6 +82,9 @@ private:
//Current opened conversation
Conversation mCurrentConversation;
//Refresh timer
QTimer *mTimer;
};
#endif // CONVERSATIONSLISTWIDGET_H