mirror of
https://gitlab.com/comunic/comunicmessages
synced 2024-12-04 11:14:09 +00:00
Automatically fetch new messages.
This commit is contained in:
parent
41cd02dfec
commit
6e7645f17b
@ -30,7 +30,8 @@ SOURCES += \
|
||||
data/newconversationmessage.cpp \
|
||||
helpers/conversationhelper.cpp \
|
||||
data/conversationmessage.cpp \
|
||||
widgets/conversationmessagewidget.cpp
|
||||
widgets/conversationmessagewidget.cpp \
|
||||
data/conversationmessageslist.cpp
|
||||
|
||||
HEADERS += \
|
||||
helpers/accounthelper.h \
|
||||
@ -62,7 +63,8 @@ HEADERS += \
|
||||
data/newconversationmessage.h \
|
||||
helpers/conversationhelper.h \
|
||||
data/conversationmessage.h \
|
||||
widgets/conversationmessagewidget.h
|
||||
widgets/conversationmessagewidget.h \
|
||||
data/conversationmessageslist.h
|
||||
|
||||
FORMS += \
|
||||
widgets/loginwidget.ui \
|
||||
|
1
config.h
1
config.h
@ -33,5 +33,6 @@
|
||||
* Conversations information
|
||||
*/
|
||||
#define CONVERSATION_MESSAGE_MIN_LENGTH 3
|
||||
#define CONVERSATION_MESSAGES_REFRESH_INTERVAL 1000
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
16
data/conversationmessageslist.cpp
Normal file
16
data/conversationmessageslist.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "conversationmessageslist.h"
|
||||
|
||||
ConversationMessagesList::ConversationMessagesList()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ConversationMessagesList::getLastMessageID()
|
||||
{
|
||||
|
||||
//Return -1 by default if there is not any message in the conversation
|
||||
if(count() == 0)
|
||||
return -1;
|
||||
|
||||
return at(count() -1).iD();
|
||||
}
|
28
data/conversationmessageslist.h
Normal file
28
data/conversationmessageslist.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Conversations messages list container
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#ifndef CONVERSATIONMESSAGESLIST_H
|
||||
#define CONVERSATIONMESSAGESLIST_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
#include "conversationmessage.h"
|
||||
|
||||
class ConversationMessagesList : public QList<ConversationMessage>
|
||||
{
|
||||
public:
|
||||
ConversationMessagesList();
|
||||
|
||||
/**
|
||||
* Get the ID of the oldest message of
|
||||
* the conversation
|
||||
*
|
||||
* @return The ID of the message / -1 in case of failure
|
||||
*/
|
||||
int getLastMessageID();
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONMESSAGESLIST_H
|
@ -1,5 +1,6 @@
|
||||
#include <QMessageBox>
|
||||
#include <algorithm>
|
||||
#include <QTimer>
|
||||
|
||||
#include "conversationwidget.h"
|
||||
#include "ui_conversationwidget.h"
|
||||
@ -27,13 +28,16 @@ ConversationWidget::ConversationWidget(const Conversation &conversation, const U
|
||||
connect(mConversationHelper, &ConversationHelper::sendMessageCallback, this, &ConversationWidget::sendMessageCallback);
|
||||
connect(mConversationHelper, &ConversationHelper::getMessagesCallback, this, &ConversationWidget::getMessagesCallback);
|
||||
|
||||
//Get the latest message of the conversation
|
||||
mConversationHelper->getMessages(conversation.iD());
|
||||
//Initialize refresh timeout
|
||||
mTimer = new QTimer(this);
|
||||
connect(mTimer, &QTimer::timeout, this, &ConversationWidget::refreshTimeout);
|
||||
emit refreshTimeout();
|
||||
}
|
||||
|
||||
ConversationWidget::~ConversationWidget()
|
||||
{
|
||||
delete ui;
|
||||
delete mTimer;
|
||||
}
|
||||
|
||||
void ConversationWidget::sendMessage()
|
||||
@ -63,8 +67,19 @@ void ConversationWidget::sendMessage()
|
||||
mConversationHelper->sendMessage(newMessage);
|
||||
}
|
||||
|
||||
void ConversationWidget::refreshTimeout()
|
||||
{
|
||||
mTimer->stop();
|
||||
|
||||
//Get the latest message of the conversation
|
||||
mConversationHelper->getMessages(mConversation.iD(), mMessages.getLastMessageID());
|
||||
}
|
||||
|
||||
void ConversationWidget::getMessagesCallback(bool success, QList<ConversationMessage> list)
|
||||
{
|
||||
//Restart counter
|
||||
mTimer->start(CONVERSATION_MESSAGES_REFRESH_INTERVAL);
|
||||
|
||||
if(!success){
|
||||
QMessageBox::warning(this, tr("Error while getting messages list"), tr("Could not refresh messages list!"));
|
||||
return;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../data/conversation.h"
|
||||
#include "../data/userslist.h"
|
||||
#include "../data/conversationmessage.h"
|
||||
#include "../data/conversationmessageslist.h"
|
||||
|
||||
namespace Ui {
|
||||
class ConversationWidget;
|
||||
@ -40,6 +41,12 @@ public slots:
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
* This slot is called at regular interval in order to
|
||||
* update regulary the list of messages
|
||||
*/
|
||||
void refreshTimeout();
|
||||
|
||||
/**
|
||||
* Method called once we have got the list of messages
|
||||
*
|
||||
@ -72,10 +79,11 @@ private:
|
||||
|
||||
//Private fields
|
||||
Ui::ConversationWidget *ui;
|
||||
QTimer *mTimer;
|
||||
ConversationHelper *mConversationHelper;
|
||||
Conversation mConversation;
|
||||
UsersList mUsersList;
|
||||
QList<ConversationMessage> mMessages;
|
||||
ConversationMessagesList mMessages;
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user