Fixing BR #233 - redirecting chanservs welcome messages to the channel buffer
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 3 Nov 2008 13:46:03 +0000 (14:46 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Mon, 3 Nov 2008 13:46:03 +0000 (14:46 +0100)
src/common/network.cpp
src/common/network.h
src/core/CMakeLists.txt
src/core/corenetwork.h
src/core/ircserverhandler.cpp

index 6c0d252..ed66ee3 100644 (file)
@@ -256,7 +256,7 @@ IrcUser *Network::ircUser(QString nickname) const {
 
 IrcChannel *Network::newIrcChannel(const QString &channelname) {
   if(!_ircChannels.contains(channelname.toLower())) {
-    IrcChannel *channel = new IrcChannel(channelname, this);
+    IrcChannel *channel = ircChannelFactory(channelname);
 
     if(proxy())
       proxy()->synchronize(channel);
@@ -587,7 +587,7 @@ void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
 
   while(channelIter != channelIterEnd) {
     channelName = channelIter.key();
-    ircChannel = new IrcChannel(channelName, this);
+    ircChannel = ircChannelFactory(channelName);
     ircChannel->fromVariantMap(channelIter.value().toMap());
     ircChannel->setInitialized();
     proxy()->synchronize(ircChannel);
index 4bbd984..ee6ba7f 100644 (file)
@@ -298,6 +298,9 @@ signals:
   void disconnectRequested(NetworkId id = 0) const;
   void setNetworkInfoRequested(const NetworkInfo &) const;
 
+protected:
+  inline virtual IrcChannel *ircChannelFactory(const QString &channelname) { return new IrcChannel(channelname, this); }
+
 private:
   QPointer<SignalProxy> _proxy;
 
index 21388ae..4491f56 100644 (file)
@@ -16,6 +16,7 @@ set(SOURCES
     corebufferviewconfig.cpp
     corebufferviewmanager.cpp
     corecoreinfo.cpp
+    coreircchannel.cpp
     coreirclisthelper.cpp
     corenetwork.cpp
     coresession.cpp
@@ -39,6 +40,7 @@ set(MOC_HDRS
     corebufferviewconfig.h
     corebufferviewmanager.h
     corecoreinfo.h
+    coreircchannel.h
     coreirclisthelper.h
     corenetwork.h
     coresession.h
index fd96ff6..2989932 100644 (file)
@@ -22,6 +22,7 @@
 #define CORENETWORK_H
 
 #include "network.h"
+#include "coreircchannel.h"
 
 class CoreSession;
 
@@ -40,6 +41,9 @@ public slots:
   virtual void requestDisconnect() const;
   virtual void requestSetNetworkInfo(const NetworkInfo &info);
 
+protected:
+  inline virtual IrcChannel *ircChannelFactory(const QString &channelname) { return new CoreIrcChannel(channelname, this); }
+
 private:
   CoreSession *_coreSession;
 };
index ea0d695..4d32f1d 100644 (file)
@@ -29,7 +29,7 @@
 #include "ctcphandler.h"
 
 #include "ircuser.h"
-#include "ircchannel.h"
+#include "coreircchannel.h"
 #include "logger.h"
 
 #include <QDebug>
@@ -41,7 +41,6 @@ IrcServerHandler::IrcServerHandler(NetworkConnection *parent)
 }
 
 IrcServerHandler::~IrcServerHandler() {
-
 }
 
 /*! Handle a raw message string sent by the server. We try to find a suitable handler, otherwise we call a default handler. */
@@ -326,6 +325,24 @@ void IrcServerHandler::handleNotice(const QString &prefix, const QList<QByteArra
     return;
 
   QString target = serverDecode(params[0]);
+
+  // special treatment for welcome messages like:
+  // :ChanServ!ChanServ@services. NOTICE egst :[#apache] Welcome, this is #apache. Please read the in-channel topic message. This channel is being logged by IRSeekBot. If you have any question please see http://blog.freenode.net/?p=68
+  if(!network()->isChannelName(target)) {
+    QString msg = serverDecode(params[1]);
+    QRegExp welcomeRegExp("^\\[([^\\]]+)\\] ");
+    if(welcomeRegExp.indexIn(msg) != -1) {
+      QString channelname = welcomeRegExp.cap(1);
+      msg = msg.mid(welcomeRegExp.matchedLength());
+      CoreIrcChannel *chan = static_cast<CoreIrcChannel *>(network()->ircChannel(channelname)); // we only have CoreIrcChannels in the core, so this cast is safe
+      if(chan && !chan->receivedWelcomeMsg()) {
+       chan->setReceivedWelcomeMsg();
+       emit displayMsg(Message::Notice, BufferInfo::ChannelBuffer, channelname, msg, prefix);
+       return;
+      }
+    }
+  }
+
   if(prefix.isEmpty() || target == "AUTH") {
     target = "";
   } else {