mirror of
https://gitlab.com/comunic/comunicmessages
synced 2024-12-04 11:14:09 +00:00
Display conversation messages.
This commit is contained in:
parent
640da86c0d
commit
41cd02dfec
@ -29,7 +29,8 @@ SOURCES += \
|
||||
widgets/conversationwidget.cpp \
|
||||
data/newconversationmessage.cpp \
|
||||
helpers/conversationhelper.cpp \
|
||||
data/conversationmessage.cpp
|
||||
data/conversationmessage.cpp \
|
||||
widgets/conversationmessagewidget.cpp
|
||||
|
||||
HEADERS += \
|
||||
helpers/accounthelper.h \
|
||||
@ -60,14 +61,16 @@ HEADERS += \
|
||||
widgets/conversationwidget.h \
|
||||
data/newconversationmessage.h \
|
||||
helpers/conversationhelper.h \
|
||||
data/conversationmessage.h
|
||||
data/conversationmessage.h \
|
||||
widgets/conversationmessagewidget.h
|
||||
|
||||
FORMS += \
|
||||
widgets/loginwidget.ui \
|
||||
widgets/mainwindow.ui \
|
||||
widgets/aboutthisappdialog.ui \
|
||||
widgets/conversationitemwidget.ui \
|
||||
widgets/conversationwidget.ui
|
||||
widgets/conversationwidget.ui \
|
||||
widgets/conversationmessagewidget.ui
|
||||
|
||||
RESOURCES += \
|
||||
res/ressources.qrc
|
||||
|
@ -54,3 +54,8 @@ void ConversationMessage::setImagePath(const QString &imagePath)
|
||||
{
|
||||
mImagePath = imagePath;
|
||||
}
|
||||
|
||||
bool ConversationMessage::operator<(const ConversationMessage &b) const
|
||||
{
|
||||
return b.iD() > iD();
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public:
|
||||
QString imagePath() const;
|
||||
void setImagePath(const QString &imagePath);
|
||||
|
||||
bool operator<(const ConversationMessage &b) const;
|
||||
|
||||
private:
|
||||
int mID;
|
||||
int mUserID;
|
||||
|
22
widgets/conversationmessagewidget.cpp
Normal file
22
widgets/conversationmessagewidget.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "conversationmessagewidget.h"
|
||||
#include "ui_conversationmessagewidget.h"
|
||||
#include "../data/user.h"
|
||||
#include "../data/conversationmessage.h"
|
||||
|
||||
ConversationMessageWidget::ConversationMessageWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ConversationMessageWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
ConversationMessageWidget::~ConversationMessageWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ConversationMessageWidget::setMessage(const ConversationMessage &message, const User &user)
|
||||
{
|
||||
ui->nameLabel->setText(user.displayName());
|
||||
ui->messageLabel->setText(message.message());
|
||||
}
|
32
widgets/conversationmessagewidget.h
Normal file
32
widgets/conversationmessagewidget.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef CONVERSATIONMESSAGEWIDGET_H
|
||||
#define CONVERSATIONMESSAGEWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class ConversationMessageWidget;
|
||||
}
|
||||
|
||||
class ConversationMessage;
|
||||
class User;
|
||||
|
||||
class ConversationMessageWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConversationMessageWidget(QWidget *parent = nullptr);
|
||||
~ConversationMessageWidget();
|
||||
|
||||
/**
|
||||
* Apply a new conversation message to the widget
|
||||
*
|
||||
* @param message The message to apply to the widget
|
||||
*/
|
||||
void setMessage(const ConversationMessage &message, const User &user);
|
||||
|
||||
private:
|
||||
Ui::ConversationMessageWidget *ui;
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONMESSAGEWIDGET_H
|
59
widgets/conversationmessagewidget.ui
Normal file
59
widgets/conversationmessagewidget.ui
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ConversationMessageWidget</class>
|
||||
<widget class="QWidget" name="ConversationMessageWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>183</width>
|
||||
<height>35</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="messageLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>3</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Message content</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -1,10 +1,14 @@
|
||||
#include <QMessageBox>
|
||||
#include <algorithm>
|
||||
|
||||
#include "conversationwidget.h"
|
||||
#include "ui_conversationwidget.h"
|
||||
#include "conversationmessagewidget.h"
|
||||
#include "../helpers/conversationslisthelper.h"
|
||||
#include "../helpers/conversationhelper.h"
|
||||
#include "../config.h"
|
||||
#include "../data/conversationmessage.h"
|
||||
#include "../utils/uiutils.h"
|
||||
|
||||
ConversationWidget::ConversationWidget(const Conversation &conversation, const UsersList &list, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
@ -21,6 +25,10 @@ ConversationWidget::ConversationWidget(const Conversation &conversation, const U
|
||||
//Initalize helpers
|
||||
mConversationHelper = new ConversationHelper(this);
|
||||
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());
|
||||
}
|
||||
|
||||
ConversationWidget::~ConversationWidget()
|
||||
@ -55,6 +63,36 @@ void ConversationWidget::sendMessage()
|
||||
mConversationHelper->sendMessage(newMessage);
|
||||
}
|
||||
|
||||
void ConversationWidget::getMessagesCallback(bool success, QList<ConversationMessage> list)
|
||||
{
|
||||
if(!success){
|
||||
QMessageBox::warning(this, tr("Error while getting messages list"), tr("Could not refresh messages list!"));
|
||||
return;
|
||||
}
|
||||
|
||||
//Stop now if the list of messages is empty
|
||||
if(list.empty())
|
||||
return;
|
||||
|
||||
mMessages.append(list);
|
||||
|
||||
std::sort(mMessages.begin(), mMessages.end());
|
||||
|
||||
//Remove previous list of messages
|
||||
UiUtils::emptyLayout(ui->messagesLayout);
|
||||
|
||||
//Apply the list of messages
|
||||
QList<ConversationMessage>::iterator it = mMessages.begin();
|
||||
while(it != mMessages.end()){
|
||||
|
||||
ConversationMessageWidget *convMessageWidget = new ConversationMessageWidget();
|
||||
convMessageWidget->setMessage(*it, mUsersList.get(it->userID()));
|
||||
ui->messagesLayout->addWidget(convMessageWidget);
|
||||
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
void ConversationWidget::sendMessageCallback(bool success)
|
||||
{
|
||||
setSendMessageFormLocked(false);
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "../data/conversation.h"
|
||||
#include "../data/userslist.h"
|
||||
#include "../data/conversationmessage.h"
|
||||
|
||||
namespace Ui {
|
||||
class ConversationWidget;
|
||||
@ -39,6 +40,14 @@ public slots:
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
* Method called once we have got the list of messages
|
||||
*
|
||||
* @param success TRUE in case of success of the operation / FALSE else
|
||||
* @param list The list of downloaded messages
|
||||
*/
|
||||
void getMessagesCallback(bool success, QList<ConversationMessage> list);
|
||||
|
||||
/**
|
||||
* Method called once the server replied to a send conversation
|
||||
* message request
|
||||
@ -66,6 +75,7 @@ private:
|
||||
ConversationHelper *mConversationHelper;
|
||||
Conversation mConversation;
|
||||
UsersList mUsersList;
|
||||
QList<ConversationMessage> mMessages;
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONWIDGET_H
|
||||
|
@ -28,17 +28,22 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget class="QWidget" name="conversationMessages">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>380</width>
|
||||
<height>224</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="messagesLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
|
Loading…
Reference in New Issue
Block a user