reflect connection to server onto all contacts

This commit is contained in:
Green Sky 2024-06-18 18:42:59 +02:00
parent ae817987c6
commit d7280771ce
No known key found for this signature in database
2 changed files with 29 additions and 2 deletions

View File

@ -31,6 +31,8 @@ IRCClientContactModel::IRCClientContactModel(
_ircc.subscribe(this, IRCClient_Event::CTCP_REQ); _ircc.subscribe(this, IRCClient_Event::CTCP_REQ);
_ircc.subscribe(this, IRCClient_Event::DISCONNECT);
// dont create server self etc until connect event comes // dont create server self etc until connect event comes
for (const auto& [channel, should_join] : _conf.entries_bool("IRCClient", "autojoin")) { for (const auto& [channel, should_join] : _conf.entries_bool("IRCClient", "autojoin")) {
@ -211,6 +213,8 @@ bool IRCClientContactModel::onEvent(const IRCClient::Events::Connect& e) {
// since this might be a reconnect // since this might be a reconnect
// and reissue joins // and reissue joins
_cr.view<Contact::Components::IRC::ServerName, Contact::Components::IRC::ChannelName>().each([this](const auto c, const auto& sn_c, const auto& cn_c) { _cr.view<Contact::Components::IRC::ServerName, Contact::Components::IRC::ChannelName>().each([this](const auto c, const auto& sn_c, const auto& cn_c) {
// HACK: by name
// should be by parent instead
if (sn_c.name != _ircc.getServerName()) { if (sn_c.name != _ircc.getServerName()) {
return; return;
} }
@ -418,14 +422,13 @@ bool IRCClientContactModel::onEvent(const IRCClient::Events::Join& e) {
std::cout << "IRCCCM: joined '" << joined_channel_name << "' id:" << bin2hex(channel.get<Contact::Components::ID>().data) << "\n"; std::cout << "IRCCCM: joined '" << joined_channel_name << "' id:" << bin2hex(channel.get<Contact::Components::ID>().data) << "\n";
channel.emplace_or_replace<Contact::Components::ConnectionState>(Contact::Components::ConnectionState::State::cloud);
channel.emplace_or_replace<Contact::Components::TagBig>(); channel.emplace_or_replace<Contact::Components::TagBig>();
channel.emplace_or_replace<Contact::Components::TagGroup>(); channel.emplace_or_replace<Contact::Components::TagGroup>();
// add self to channel // add self to channel
channel.emplace_or_replace<Contact::Components::Self>(_self); channel.emplace_or_replace<Contact::Components::Self>(_self);
} }
channel.emplace_or_replace<Contact::Components::ConnectionState>(Contact::Components::ConnectionState::State::cloud);
auto user = getU(e.origin); auto user = getU(e.origin);
if (!user.valid()) { if (!user.valid()) {
@ -563,3 +566,26 @@ bool IRCClientContactModel::onEvent(const IRCClient::Events::CTCP_Req& e) {
return false; return false;
} }
bool IRCClientContactModel::onEvent(const IRCClient::Events::Disconnect&) {
_connected = false;
if (!_cr.valid(_server)) {
// skip if where already offline
return false;
}
_cr.get<Contact::Components::ConnectionState>(_server).state = Contact::Components::ConnectionState::disconnected;
// HACK: by name
_cr.view<Contact::Components::IRC::ServerName, Contact::Components::ConnectionState>().each([this](const auto c, const auto& sn_c, auto& cs) {
// HACK: by name
// should be by parent instead
if (sn_c.name != _ircc.getServerName()) {
return;
}
cs.state = Contact::Components::ConnectionState::disconnected;
});
return false;
}

View File

@ -61,4 +61,5 @@ class IRCClientContactModel : public IRCClientEventI, public ContactModel3I {
bool onEvent(const IRCClient::Events::Topic& e) override; bool onEvent(const IRCClient::Events::Topic& e) override;
bool onEvent(const IRCClient::Events::Quit& e) override; bool onEvent(const IRCClient::Events::Quit& e) override;
bool onEvent(const IRCClient::Events::CTCP_Req&) override; bool onEvent(const IRCClient::Events::CTCP_Req&) override;
bool onEvent(const IRCClient::Events::Disconnect&) override;
}; };