[smuxi: 154/179] Engine-IRC, Frontend-GNOME: add enhanced Slack support



commit 4a56d4f0a8ff4a19d1dba779e0e131322eb088c2
Author: Mirco Bauer <meebey meebey net>
Date:   Sat Jun 3 10:04:54 2017 +0800

    Engine-IRC, Frontend-GNOME: add enhanced Slack support
    
    Using the same approach as with the FacebookProtocolManager of having a
    specialized protocol manager that is based on a generic one but with tweaks
    specific to a service, like Facebook or Slack. This change introduces a
    SlackProtocolManager that is based on the IrcProtocolManager.
    
    Enable rendering emojis by default on Slack connections as emojis are natively
    supported on Slack. (closes: #1103)

 src/Engine-IRC/Engine-IRC.csproj                   |    1 +
 src/Engine-IRC/Makefile.am                         |    1 +
 .../Protocols/Irc/SlackProtocolManager.cs          |   47 +++++++++++++
 src/Frontend-GNOME/Views/Chats/ProtocolChatView.cs |    3 +
 src/Frontend-GNOME/Views/ServerWidget.cs           |   72 +++++++++++++++++++-
 5 files changed, 121 insertions(+), 3 deletions(-)
---
diff --git a/src/Engine-IRC/Engine-IRC.csproj b/src/Engine-IRC/Engine-IRC.csproj
index 1d83f4f..fba339f 100644
--- a/src/Engine-IRC/Engine-IRC.csproj
+++ b/src/Engine-IRC/Engine-IRC.csproj
@@ -47,6 +47,7 @@
     <Compile Include="..\AssemblyVersion.cs" />
     <Compile Include="Protocols\Irc\IrcMessageBuilder.cs" />
     <Compile Include="Config\IrcServerModel.cs" />
+    <Compile Include="Protocols\Irc\SlackProtocolManager.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\po-Engine-IRC\de.po" />
diff --git a/src/Engine-IRC/Makefile.am b/src/Engine-IRC/Makefile.am
index 9d5220d..8ed53dd 100644
--- a/src/Engine-IRC/Makefile.am
+++ b/src/Engine-IRC/Makefile.am
@@ -64,6 +64,7 @@ FILES = \
        Protocols/Irc/IrcProtocolManager.cs \
        Protocols/Irc/IrcPersonModel.cs \
        Protocols/Irc/IrcTextColor.cs \
+       Protocols/Irc/SlackProtocolManager.cs \
        Config/IrcServerModel.cs \
        ../AssemblyVersion.cs \
        AssemblyInfo.cs 
diff --git a/src/Engine-IRC/Protocols/Irc/SlackProtocolManager.cs 
b/src/Engine-IRC/Protocols/Irc/SlackProtocolManager.cs
new file mode 100644
index 0000000..dcbebbb
--- /dev/null
+++ b/src/Engine-IRC/Protocols/Irc/SlackProtocolManager.cs
@@ -0,0 +1,47 @@
+// Smuxi - Smart MUltipleXed Irc
+//
+// Copyright (c) 2017 Mirco Bauer <meebey meebey net>
+//
+// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+using System;
+using Smuxi.Common;
+
+namespace Smuxi.Engine
+{
+    [ProtocolManagerInfo(Name = "Slack", Description = "Slack IRC", Alias = "slack")]
+    public class SlackProtocolManager : IrcProtocolManager
+    {
+        public override string Protocol {
+            get {
+                return "Slack";
+            }
+        }
+
+        public SlackProtocolManager(Session session) :
+                               base(session)
+        {
+            Trace.Call(session);
+        }
+
+        protected override T CreateMessageBuilder<T>()
+        {
+            var builder = base.CreateMessageBuilder<T>();
+            builder.Settings.Emojis = true;
+            return builder;
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/Frontend-GNOME/Views/Chats/ProtocolChatView.cs 
b/src/Frontend-GNOME/Views/Chats/ProtocolChatView.cs
index 32b1fc6..4fb9844 100644
--- a/src/Frontend-GNOME/Views/Chats/ProtocolChatView.cs
+++ b/src/Frontend-GNOME/Views/Chats/ProtocolChatView.cs
@@ -80,6 +80,9 @@ namespace Smuxi.Frontend.Gnome
             NetworkWebsiteUrls.Add("Infinity-IRC", "http://www.infinityirc.com/";);
             NetworkWebsiteUrls.Add("GeekShed", "http://www.geekshed.net/";);
 
+            // IRC bridges
+            NetworkWebsiteUrls.Add("Slack", "https://slack.com/";);
+
             // Twitter
             NetworkWebsiteUrls.Add("Twitter", "http://www.twitter.com/";);
 
diff --git a/src/Frontend-GNOME/Views/ServerWidget.cs b/src/Frontend-GNOME/Views/ServerWidget.cs
index 8704030..f8f6841 100644
--- a/src/Frontend-GNOME/Views/ServerWidget.cs
+++ b/src/Frontend-GNOME/Views/ServerWidget.cs
@@ -46,6 +46,15 @@ namespace Smuxi.Frontend.Gnome
         }
 
         public string Protocol {
+            get {
+                Gtk.TreeIter activeIter;
+                if (!f_ProtocolComboBox.GetActiveIter(out activeIter)) {
+                    return null;
+                }
+                var store = (Gtk.ListStore) ProtocolComboBox.Model;
+                var protocolId = (string) store.GetValue(activeIter, 1);
+                return protocolId;
+            }
             set {
                 if (value == null) {
                     // clear selection
@@ -235,10 +244,18 @@ namespace Smuxi.Frontend.Gnome
             server.Network  = f_NetworkComboBoxEntry.Entry.Text.Trim();
             server.Port     = f_PortSpinButton.ValueAsInt;
             server.Username = f_UsernameEntry.Text.Trim();
-            // HACK: use Twitter username as hostname for multi-account support
-            if (f_ProtocolComboBox.ActiveText == "Twitter") {
-                server.Hostname = server.Username;
+
+            switch (Protocol) {
+                case "Twitter":
+                    // HACK: use Twitter username as hostname for multi-account support
+                    server.Hostname = server.Username;
+                    break;
+                case "Slack":
+                    // HACK: on Slack the nickname has to match the username
+                    server.Nickname =  server.Username;
+                    break;
             }
+
             server.Password = f_PasswordEntry.Text;
             server.Nickname = f_NicknameEntry.Text.Trim();
             server.Realname = f_RealnameEntry.Text.Trim();
@@ -310,6 +327,9 @@ namespace Smuxi.Frontend.Gnome
             f_ProtocolComboBox.Changed += delegate {
                 CheckProtocolComboBox();
             };
+            f_HostnameEntry.Changed += delegate {
+                CheckHostnameEntry();
+            };
             f_ShowPasswordCheckButton.Clicked += delegate {
                 CheckShowPasswordCheckButton();
             };
@@ -352,6 +372,7 @@ namespace Smuxi.Frontend.Gnome
             }
             switch (f_ProtocolComboBox.ActiveText) {
                 case "IRC":
+                case "Slack":
                     if (f_PortSpinButton.Value == 6667 ||
                         f_PortSpinButton.Value == 6697) {
                         f_PortSpinButton.Value = useEncryption ? 6697 : 6667;
@@ -484,6 +505,32 @@ namespace Smuxi.Frontend.Gnome
                     f_NetworkComboBoxEntry.Entry.Text = String.Empty;
                     f_PasswordEntry.Text = String.Empty;
                     break;
+                case "Slack":
+                    // https://my.slack.com/account/gateways
+                    ShowHostname = true;
+                    // we map the 4rd level domain (foo.irc.slacke.com) to the
+                    // network name as it is guaranteed to be unique, see
+                    // CheckHostnameEntry()
+                    ShowNetwork = false;
+                    // on Slack the nickname has to match the username
+                    ShowNickname = false;
+                    // the realname is ignored by the IRC bridge
+                    ShowRealname = false;
+                    ShowPassword = true;
+                    SupportUseEncryption = true;
+
+                    // use TLS by default
+                    f_UseEncryptionCheckButton.Active = true;
+
+                    f_HostnameEntry.Text = ".irc.slack.com";
+                    f_HostnameEntry.Sensitive = true;
+
+                    // Slack only supports 6667 or 6697
+                    f_PortSpinButton.Sensitive = false;
+
+                    f_NetworkComboBoxEntry.Entry.Text = String.Empty;
+                    f_PasswordEntry.Text = String.Empty;
+                    break;
                 // in case we don't know / handle the protocol here, make
                 // sure we grant maximum flexibility for the input
                 default:
@@ -502,6 +549,25 @@ namespace Smuxi.Frontend.Gnome
             }
         }
 
+        void CheckHostnameEntry()
+        {
+            Trace.Call();
+
+            var hostname = f_HostnameEntry.Text ?? String.Empty;
+            switch (Protocol) {
+                case "Slack":
+                    var colonPosition = hostname.IndexOf('.');
+                    if (colonPosition < 0) {
+                        return;
+                    }
+                    // map 4th level domain to the network name, e.g.
+                    // "foo.irc.slack.come" as host becomes "foo" as network
+                    var fourthLevelDomain = hostname.Substring(0, colonPosition);
+                    f_NetworkComboBoxEntry.Entry.Text = fourthLevelDomain;
+                    break;
+            }
+        }
+
         private static string _(string msg)
         {
             return Mono.Unix.Catalog.GetString(msg);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]