Commit 69c4fbea authored by scuq's avatar scuq

* show offline contact in roster if unread message is pending

* setting which which allows to hide muc channels
* show incoming muc messages even if muc channels are hidden
* messagebox has tab position 1 in chat window
* no close to tray warning
* exit waits for disconnect (beta) to prevent lingering mattermost
sessions
* fixed message duplication on disconnect/reconnect
parent b4a7ac63
Pipeline #392 failed with stage
in 4 minutes and 56 seconds
......@@ -60,7 +60,9 @@ void dialogChat::loadMessageHistrory()
void dialogChat::sendMessage(QString message)
{
this->session->newChannelPost(this->contact->getDirectChannelId(),message);
if ( this->session->newChannelPost(this->contact->getDirectChannelId(),message) == false ) {
QMessageBox::warning(this, appname, "Unable to send message!", QMessageBox::Ok);
}
}
......
......@@ -9,6 +9,7 @@
#include <QDesktopServices>
#include <QPainter>
#include <QCloseEvent>
#include <QMessageBox>
#include "imsession.h"
#include "imcontact.h"
#include "dialogfileviewer.h"
......
......@@ -101,6 +101,10 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>plainTextEditChatInput</tabstop>
<tabstop>textBrowserChatOutput</tabstop>
</tabstops>
<resources>
<include location="res.qrc"/>
</resources>
......
......@@ -449,6 +449,12 @@ void DialogPreferences::slGlobalSettingsChanged(QMap<QString, QVariant> globalSe
void DialogPreferences::slRosterSettingsChanged(QMap<QString, QVariant> rosterSettings)
{
if (rosterSettings.value("roster_hide_muc").toInt() > 0) {
this->ui->checkBoxHideMuc->setCheckState(Qt::CheckState::Checked);
} else {
this->ui->checkBoxHideMuc->setCheckState(Qt::CheckState::Unchecked);
}
if (rosterSettings.value("roster_hide_offline").toInt() > 0) {
this->ui->checkBoxHideOffline->setCheckState(Qt::CheckState::Checked);
} else {
......@@ -594,3 +600,8 @@ void DialogPreferences::on_checkBoxCloseToTray_stateChanged(int arg1)
{
this->m_mp->setGlobalCloseToTray(arg1);
}
void DialogPreferences::on_checkBoxHideMuc_stateChanged(int arg1)
{
this->m_mp->setRosterHideMuc(arg1);
}
......@@ -154,6 +154,8 @@ private slots:
void on_checkBoxCloseToTray_stateChanged(int arg1);
void on_checkBoxHideMuc_stateChanged(int arg1);
private:
Ui::DialogPreferences *ui;
manipulator *m_mp;
......
......@@ -30,9 +30,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-564</y>
<y>-208</y>
<width>444</width>
<height>1125</height>
<height>1144</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
......@@ -80,43 +80,78 @@
<string>Roster</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnminimumwidth="0,10,100">
<item row="22" column="0">
<widget class="QLabel" name="labelHideOffline">
<item row="2" column="0">
<widget class="QLabel" name="labelOnlineColor">
<property name="text">
<string>Hide &quot;Offline&quot;</string>
<string>Online Color</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="pushButtonChooseAwaycolor">
<item row="1" column="0">
<widget class="QLabel" name="labelRosterStatusShapeBaseSize">
<property name="text">
<string>Shape base size</string>
</property>
</widget>
</item>
<item row="12" column="2">
<widget class="QPushButton" name="pushButtonChooseUnreadcolor2">
<property name="text">
<string>Choose ...</string>
</property>
</widget>
</item>
<item row="20" column="2">
<widget class="QComboBox" name="comboBoxChannelShape">
<item row="0" column="0">
<widget class="QLabel" name="labelRosterStatusShape">
<property name="text">
<string>Roster status shape</string>
</property>
</widget>
</item>
<item row="25" column="0">
<widget class="QLabel" name="labelRosterFont">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="22" column="2">
<widget class="QCheckBox" name="checkBoxHideOffline">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBoxStatusShape">
<item>
<property name="text">
<string>Triangle</string>
<string>Ellipse</string>
</property>
</item>
<item>
<property name="text">
<string>Ellipse</string>
<string>Rectangle</string>
</property>
</item>
<item>
<property name="text">
<string>Rectangle</string>
<string>Triangle</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelRosterStatusShapeBaseSize">
<item row="7" column="0">
<widget class="QLabel" name="labelOfflineColor">
<property name="text">
<string>Shape base size</string>
<string>Offline color</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="pushButtonChooseAwaycolor">
<property name="text">
<string>Choose ...</string>
</property>
</widget>
</item>
......@@ -127,31 +162,64 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelRosterStatusShape">
<item row="12" column="0">
<widget class="QLabel" name="labelColorUnreadSample2">
<property name="text">
<string>Roster status shape</string>
<string/>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelUnreadColor">
<item row="26" column="0">
<widget class="QTextEdit" name="textEditRosterSample">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;user1&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;user2&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;user3&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="labelChannelColor">
<property name="text">
<string>Unread color</string>
<string>Channel color</string>
</property>
</widget>
</item>
<item row="24" column="0">
<widget class="QLabel" name="labelRosterFont">
<item row="26" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="23" column="0">
<widget class="QLabel" name="labelHideStatusText">
<property name="text">
<string>Font</string>
<string>Hide &quot;Status Text&quot;</string>
</property>
</widget>
</item>
<item row="12" column="2">
<widget class="QPushButton" name="pushButtonChooseUnreadcolor2">
<item row="6" column="0">
<widget class="QLabel" name="labelColorAwaySample">
<property name="text">
<string>Choose ...</string>
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelColorOfflineSample">
<property name="text">
<string/>
</property>
</widget>
</item>
......@@ -175,50 +243,24 @@
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="labelUnreadColor2">
<item row="23" column="2">
<widget class="QCheckBox" name="checkBoxHideStatusText">
<property name="text">
<string>Unread color 2</string>
<string/>
</property>
</widget>
</item>
<item row="14" column="2">
<widget class="QPushButton" name="pushButtonChooseChannelcolor">
<item row="20" column="0">
<widget class="QLabel" name="labelChannelShape">
<property name="text">
<string>Choose ...</string>
</property>
</widget>
</item>
<item row="25" column="0">
<widget class="QTextEdit" name="textEditRosterSample">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;user1&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;user2&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;user3&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="21" column="2">
<widget class="QSpinBox" name="spinBoxChannelShapeBaseSize">
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="singleStep">
<number>5</number>
<string>Channel shape</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="labelChannelColor">
<item row="10" column="0">
<widget class="QLabel" name="labelColorUnreadSample">
<property name="text">
<string>Channel color</string>
<string/>
</property>
</widget>
</item>
......@@ -229,43 +271,24 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBoxStatusShape">
<item>
<property name="text">
<string>Ellipse</string>
</property>
</item>
<item>
<property name="text">
<string>Rectangle</string>
</property>
</item>
<item>
<property name="text">
<string>Triangle</string>
</property>
</item>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelColorOfflineSample">
<item row="21" column="0">
<widget class="QLabel" name="labelChannelShapeBaseSize">
<property name="text">
<string/>
<string>Shape base size</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelColorAwaySample">
<item row="9" column="0">
<widget class="QLabel" name="labelUnreadColor">
<property name="text">
<string/>
<string>Unread color</string>
</property>
</widget>
</item>
<item row="23" column="2">
<widget class="QCheckBox" name="checkBoxHideStatusText">
<item row="11" column="0">
<widget class="QLabel" name="labelUnreadColor2">
<property name="text">
<string/>
<string>Unread color 2</string>
</property>
</widget>
</item>
......@@ -276,30 +299,36 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="25" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="23" column="0">
<widget class="QLabel" name="labelHideStatusText">
<item row="26" column="2">
<widget class="QPushButton" name="pushButtonRosterFont">
<property name="text">
<string>Hide &quot;Status Text&quot;</string>
<string>Choose ...</string>
</property>
</widget>
</item>
<item row="25" column="2">
<widget class="QPushButton" name="pushButtonRosterFont">
<item row="20" column="2">
<widget class="QComboBox" name="comboBoxChannelShape">
<item>
<property name="text">
<string>Triangle</string>
</property>
</item>
<item>
<property name="text">
<string>Ellipse</string>
</property>
</item>
<item>
<property name="text">
<string>Rectangle</string>
</property>
</item>
</widget>
</item>
<item row="22" column="0">
<widget class="QLabel" name="labelHideOffline">
<property name="text">
<string>Choose ...</string>
<string>Hide &quot;Offline&quot;</string>
</property>
</widget>
</item>
......@@ -313,59 +342,44 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="20" column="0">
<widget class="QLabel" name="labelChannelShape">
<property name="text">
<string>Channel shape</string>
</property>
</widget>
</item>
<item row="22" column="2">
<widget class="QCheckBox" name="checkBoxHideOffline">
<item row="14" column="2">
<widget class="QPushButton" name="pushButtonChooseChannelcolor">
<property name="text">
<string/>
<string>Choose ...</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelOnlineColor">
<item row="3" column="2">
<widget class="QPushButton" name="pushButtonChooseOnlinecolor">
<property name="text">
<string>Online Color</string>
<string>Choose ...</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelColorUnreadSample">
<property name="text">
<string/>
<item row="21" column="2">
<widget class="QSpinBox" name="spinBoxChannelShapeBaseSize">
<property name="minimum">
<number>5</number>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelOfflineColor">
<property name="text">
<string>Offline color</string>
<property name="maximum">
<number>30</number>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="labelColorUnreadSample2">
<property name="text">
<string/>
<property name="singleStep">
<number>5</number>
</property>
</widget>
</item>
<item row="21" column="0">
<widget class="QLabel" name="labelChannelShapeBaseSize">
<item row="24" column="0">
<widget class="QLabel" name="labelHideMuc">
<property name="text">
<string>Shape base size</string>
<string>Hide &quot;Multi user channels&quot;</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pushButtonChooseOnlinecolor">
<item row="24" column="2">
<widget class="QCheckBox" name="checkBoxHideMuc">
<property name="text">
<string>Choose ...</string>
<string/>
</property>
</widget>
</item>
......
......@@ -62,10 +62,35 @@ void ImSession::authenticate()
netReplies[reply] = "mmapi::authenticate";
}
void ImSession::deAuthenticate()
{
qDebug() << QString("%1: logout").arg(this->metaObject()->className());
QUrl url ( this->m_account->getServer() + "/api/v4/users/logout" );
QNetworkRequest req ( url );
QJsonObject logoutJson;
req.setRawHeader("Content-Type", "application/json");
req.setRawHeader("X-Requested-With", "XMLHttpRequest");
req.setRawHeader("Authorization", "Bearer "+this->getAuthtoken().toUtf8());
req.setRawHeader("X-CSRF-Token", this->getCsrftoken().toUtf8());
req.setRawHeader("Cookie", this->getCookie().toUtf8());
QNetworkReply *reply = m_WebCtrl.post(req,QJsonDocument(logoutJson).toJson());
new ReplyTimeout( this, reply, 5000, url.toString() );
netReplies[reply] = QString("mmapi::deauthenticate__%1").arg( this->getAccount()->getAccountname() );
}
void ImSession::authenticateWs()
{
QJsonObject wsloginDataJson;
......@@ -250,12 +275,12 @@ void ImSession::getChannelPosts(QString channelid)
}
}
void ImSession::newChannelPost(QString channelid, QString message)
bool ImSession::newChannelPost(QString channelid, QString message)
{
if ( (this->getNetworkConnection()) && this->isAuthenticated() ) {
QUrl url ( this->m_account->getServer() + QString("/api/v4/posts").arg( channelid ) );
QUrl url ( this->m_account->getServer() + QString("/api/v4/posts") );
QNetworkRequest req ( url );
......@@ -273,6 +298,9 @@ void ImSession::newChannelPost(QString channelid, QString message)
netReplies[reply] = QString("mmapi::newChannelPost__%1").arg( channelid );
return true;
} else {
return false;
}
}
......@@ -450,6 +478,9 @@ void ImSession::setupSignals()
this, SLOT (slOnWebsocketDisconnected() )
);
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &ImSession::slOnWebsocketMessageReceived);
connect( &this->m_webSocket, SIGNAL (error(QAbstractSocket::SocketError) ),
this, SLOT (slOnWebsocketError(QAbstractSocket::SocketError) )
);
......@@ -459,6 +490,26 @@ void ImSession::setupSignals()
}
QString ImSession::getCsrftoken() const
{
return m_csrftoken;
}
void ImSession::setCsrftoken(const QString &csrftoken)
{
m_csrftoken = csrftoken;
}
QString ImSession::getCookie() const
{
return m_cookie;
}
void ImSession::setCookie(const QString &cookie)
{
m_cookie = cookie;
}
bool ImSession::getNetworkConnection() const
{
......@@ -648,6 +699,19 @@ void ImSession::parseNetworkResponse(QNetworkReply *pReply)
if ( pReply->error() == QNetworkReply::NoError ) {
if (callingFuncName == "mmapi::authenticate") {
this->setAuthtoken(pReply->rawHeader("Token"));
QStringList _cookielist = QString(pReply->rawHeader("Set-Cookie")).split("\n");
QString _cookies = "";
QString cookies;
foreach(QString _cookie, _cookielist) {
cookies.append(_cookie.split(";")[0]+"; ");
if ( _cookie.split(";")[0].startsWith("MMCSRF=") ) {
this->setCsrftoken(_cookie.split(";")[0].split("=")[1]);
}
}
this->setCookie(cookies.trimmed());
if (this->getAuthtoken().length() > 0) {
emit siMmAuthenticationSuccessful( QJsonDocument::fromJson(pReply->readAll()) );
}
......@@ -675,6 +739,11 @@ void ImSession::parseNetworkResponse(QNetworkReply *pReply)
}
if (callingFuncName.startsWith( "mmapi::deauthenticate" )) {
QString _accountname = callingFuncName.split("__")[1];
qDebug() << "deAuthenticate: " << pReply->readAll();