mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
smol irc fixes
This commit is contained in:
parent
2f39f4246c
commit
b20fdc0da6
|
@ -164,41 +164,45 @@ ChannelPtr AbstractIrcServer::getOrAddChannel(const QString &dirtyChannelName)
|
||||||
return Channel::getEmpty();
|
return Channel::getEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString clojuresInCppAreShit = channelName;
|
|
||||||
|
|
||||||
this->channels.insert(channelName, chan);
|
this->channels.insert(channelName, chan);
|
||||||
chan->destroyed.connect([this, clojuresInCppAreShit] {
|
this->connections_.emplace_back(chan->destroyed.connect([this,
|
||||||
|
channelName] {
|
||||||
// fourtf: issues when the server itself is destroyed
|
// fourtf: issues when the server itself is destroyed
|
||||||
|
|
||||||
log("[AbstractIrcServer::addChannel] {} was destroyed",
|
log("[AbstractIrcServer::addChannel] {} was destroyed", channelName);
|
||||||
clojuresInCppAreShit);
|
this->channels.remove(channelName);
|
||||||
this->channels.remove(clojuresInCppAreShit);
|
|
||||||
|
|
||||||
if (this->readConnection_)
|
if (this->readConnection_)
|
||||||
{
|
{
|
||||||
this->readConnection_->sendRaw("PART #" + clojuresInCppAreShit);
|
this->readConnection_->sendRaw("PART #" + channelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->writeConnection_ && this->hasSeparateWriteConnection())
|
if (this->writeConnection_ && this->hasSeparateWriteConnection())
|
||||||
{
|
{
|
||||||
this->writeConnection_->sendRaw("PART #" + clojuresInCppAreShit);
|
this->writeConnection_->sendRaw("PART #" + channelName);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
// join irc channel
|
// join irc channel
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock2(this->connectionMutex_);
|
std::lock_guard<std::mutex> lock2(this->connectionMutex_);
|
||||||
|
|
||||||
if (this->readConnection_)
|
if (this->readConnection_)
|
||||||
|
{
|
||||||
|
if (this->readConnection_->isConnected())
|
||||||
{
|
{
|
||||||
this->readConnection_->sendRaw("JOIN #" + channelName);
|
this->readConnection_->sendRaw("JOIN #" + channelName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this->writeConnection_ && this->hasSeparateWriteConnection())
|
if (this->writeConnection_ && this->hasSeparateWriteConnection())
|
||||||
|
{
|
||||||
|
if (this->readConnection_->isConnected())
|
||||||
{
|
{
|
||||||
this->writeConnection_->sendRaw("JOIN #" + channelName);
|
this->writeConnection_->sendRaw("JOIN #" + channelName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <IrcMessage>
|
#include <IrcMessage>
|
||||||
#include <pajlada/signals/signal.hpp>
|
#include <pajlada/signals/signal.hpp>
|
||||||
|
#include <pajlada/signals/signalholder.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -84,6 +85,7 @@ private:
|
||||||
std::mutex connectionMutex_;
|
std::mutex connectionMutex_;
|
||||||
|
|
||||||
// bool autoReconnect_ = false;
|
// bool autoReconnect_ = false;
|
||||||
|
pajlada::Signals::SignalHolder connections_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -57,8 +57,10 @@ void IrcServer::initializeConnection(IrcConnection *connection, bool isRead,
|
||||||
connection->setPort(this->data_->port);
|
connection->setPort(this->data_->port);
|
||||||
|
|
||||||
connection->setUserName(this->data_->user);
|
connection->setUserName(this->data_->user);
|
||||||
connection->setNickName(this->data_->nick);
|
connection->setNickName(this->data_->nick.isEmpty() ? this->data_->user
|
||||||
connection->setRealName(this->data_->real);
|
: this->data_->nick);
|
||||||
|
connection->setRealName(this->data_->real.isEmpty() ? this->data_->user
|
||||||
|
: this->data_->nick);
|
||||||
connection->setPassword(this->data_->password);
|
connection->setPassword(this->data_->password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +74,21 @@ bool IrcServer::hasSeparateWriteConnection() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IrcServer::onReadConnected(IrcConnection *connection)
|
||||||
|
{
|
||||||
|
AbstractIrcServer::onReadConnected(connection);
|
||||||
|
|
||||||
|
std::lock_guard lock(this->channelMutex);
|
||||||
|
|
||||||
|
for (auto &&weak : this->channels)
|
||||||
|
{
|
||||||
|
if (auto channel = weak.lock())
|
||||||
|
{
|
||||||
|
connection->sendRaw("JOIN #" + channel->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
||||||
{
|
{
|
||||||
auto target = message->target();
|
auto target = message->target();
|
||||||
|
@ -81,6 +98,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
||||||
{
|
{
|
||||||
MessageBuilder builder;
|
MessageBuilder builder;
|
||||||
|
|
||||||
|
builder.emplace<TimestampElement>();
|
||||||
builder.emplace<TextElement>(message->nick() + ":",
|
builder.emplace<TextElement>(message->nick() + ":",
|
||||||
MessageElementFlag::Username);
|
MessageElementFlag::Username);
|
||||||
builder.emplace<TextElement>(message->content(),
|
builder.emplace<TextElement>(message->content(),
|
||||||
|
|
|
@ -25,6 +25,8 @@ protected:
|
||||||
bool isWrite) override;
|
bool isWrite) override;
|
||||||
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
|
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
|
||||||
bool hasSeparateWriteConnection() const override;
|
bool hasSeparateWriteConnection() const override;
|
||||||
|
|
||||||
|
void onReadConnected(IrcConnection *connection) override;
|
||||||
void privateMessageReceived(Communi::IrcPrivateMessage *message) override;
|
void privateMessageReceived(Communi::IrcPrivateMessage *message) override;
|
||||||
void readConnectionMessageReceived(Communi::IrcMessage *message) override;
|
void readConnectionMessageReceived(Communi::IrcMessage *message) override;
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,10 @@ public:
|
||||||
|
|
||||||
QStringSetting cachePath = {"/cache/path", ""};
|
QStringSetting cachePath = {"/cache/path", ""};
|
||||||
|
|
||||||
|
/// UI
|
||||||
|
IntSetting lastSelectChannelTab = {"/ui/lastSelectChannelTab", 0};
|
||||||
|
IntSetting lastSelectIrcConn = {"/ui/lastSelectIrcConn", 0};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateModerationActions();
|
void updateModerationActions();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>IrcConnectionEditor</class>
|
<class>IrcConnectionEditor</class>
|
||||||
<widget class="QWidget" name="IrcConnectionEditor">
|
<widget class="QDialog" name="IrcConnectionEditor">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
|
|
|
@ -147,23 +147,29 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||||
|
|
||||||
view->getTableView()->horizontalHeader()->setSectionHidden(1, true);
|
view->getTableView()->horizontalHeader()->setSectionHidden(1, true);
|
||||||
view->getTableView()->horizontalHeader()->setSectionHidden(2, true);
|
view->getTableView()->horizontalHeader()->setSectionHidden(2, true);
|
||||||
|
view->getTableView()->horizontalHeader()->setSectionHidden(4, true);
|
||||||
|
view->getTableView()->horizontalHeader()->setSectionHidden(5, true);
|
||||||
view->getTableView()->horizontalHeader()->setSectionHidden(6, true);
|
view->getTableView()->horizontalHeader()->setSectionHidden(6, true);
|
||||||
view->getTableView()->horizontalHeader()->setSectionHidden(7, true);
|
view->getTableView()->horizontalHeader()->setSectionHidden(7, true);
|
||||||
|
|
||||||
view->addButtonPressed.connect([] {
|
view->addButtonPressed.connect([] {
|
||||||
auto unique = IrcConnection_{};
|
auto unique = IrcConnection_{};
|
||||||
unique.id = Irc::getInstance().uniqueId();
|
unique.id = Irc::getInstance().uniqueId();
|
||||||
|
|
||||||
|
auto editor = new IrcConnectionEditor(unique);
|
||||||
|
if (editor->exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
Irc::getInstance().connections.appendItem(unique);
|
Irc::getInstance().connections.appendItem(unique);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
view->getTableView(), &QTableView::clicked,
|
view->getTableView(), &QTableView::doubleClicked,
|
||||||
[](const QModelIndex &index) {
|
[](const QModelIndex &index) {
|
||||||
auto data =
|
auto editor = new IrcConnectionEditor(
|
||||||
Irc::getInstance()
|
Irc::getInstance()
|
||||||
.connections.getVector()[size_t(index.row())];
|
.connections.getVector()[size_t(index.row())]);
|
||||||
|
|
||||||
auto editor = new IrcConnectionEditor(data);
|
|
||||||
if (editor->exec() == QDialog::Accepted)
|
if (editor->exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
auto data = editor->data();
|
auto data = editor->data();
|
||||||
|
@ -219,10 +225,24 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
||||||
auto *shortcut_cancel = new QShortcut(QKeySequence("Esc"), this);
|
auto *shortcut_cancel = new QShortcut(QKeySequence("Esc"), this);
|
||||||
QObject::connect(shortcut_cancel, &QShortcut::activated,
|
QObject::connect(shortcut_cancel, &QShortcut::activated,
|
||||||
[=] { this->close(); });
|
[=] { this->close(); });
|
||||||
|
|
||||||
|
// restore ui state
|
||||||
|
this->ui_.notebook->selectIndex(getSettings()->lastSelectChannelTab);
|
||||||
|
this->ui_.irc.servers->getTableView()->selectRow(
|
||||||
|
getSettings()->lastSelectIrcConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectChannelDialog::ok()
|
void SelectChannelDialog::ok()
|
||||||
{
|
{
|
||||||
|
// save ui state
|
||||||
|
getSettings()->lastSelectChannelTab =
|
||||||
|
this->ui_.notebook->getSelectedIndex();
|
||||||
|
getSettings()->lastSelectIrcConn = this->ui_.irc.servers->getTableView()
|
||||||
|
->selectionModel()
|
||||||
|
->currentIndex()
|
||||||
|
.row();
|
||||||
|
|
||||||
|
// accept and close
|
||||||
this->hasSelectedChannel_ = true;
|
this->hasSelectedChannel_ = true;
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
@ -339,14 +359,14 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
|
||||||
if (row >= 0 && row < int(vector.size()))
|
if (row >= 0 && row < int(vector.size()))
|
||||||
{
|
{
|
||||||
return Irc::getInstance().getOrAddChannel(
|
return Irc::getInstance().getOrAddChannel(
|
||||||
vector[row].id, this->ui_.irc.channel->text());
|
vector[size_t(row)].id, this->ui_.irc.channel->text());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Channel::getEmpty();
|
return Channel::getEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->selectedChannel_;
|
return this->selectedChannel_;
|
||||||
|
@ -360,7 +380,7 @@ bool SelectChannelDialog::hasSeletedChannel() const
|
||||||
bool SelectChannelDialog::EventFilter::eventFilter(QObject *watched,
|
bool SelectChannelDialog::EventFilter::eventFilter(QObject *watched,
|
||||||
QEvent *event)
|
QEvent *event)
|
||||||
{
|
{
|
||||||
auto *widget = (QWidget *)watched;
|
auto *widget = static_cast<QWidget *>(watched);
|
||||||
|
|
||||||
if (event->type() == QEvent::FocusIn)
|
if (event->type() == QEvent::FocusIn)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue