[smuxi: 55/111] Engine-XMPP, Frontend-GNOME: XmppProtocolManager was getting crowded with custom code for special se
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi: 55/111] Engine-XMPP, Frontend-GNOME: XmppProtocolManager was getting crowded with custom code for special se
- Date: Sun, 16 Feb 2014 13:17:52 +0000 (UTC)
commit 45c282cd1d76e75630d011b31dbe4f2aca0c949a
Author: Oliver Schneider <mail oli-obk de>
Date: Thu Jan 9 09:25:26 2014 +0100
Engine-XMPP, Frontend-GNOME: XmppProtocolManager was getting crowded with custom code for special servers
took all facebook specific code out of XmppProtocolManager and placed the parts that are still in use in
FacebookProtocolManager
src/Engine-XMPP/Config/XmppServerModel.cs | 11 ---
src/Engine-XMPP/Engine-XMPP.csproj | 3 +-
src/Engine-XMPP/Makefile.am | 2 +-
.../Protocols/Xmpp/FacebookProtocolManager.cs | 47 ++++++++++
src/Engine-XMPP/Protocols/Xmpp/IQ/OwnMessage.cs | 85 ------------------
.../Protocols/Xmpp/XmppProtocolManager.cs | 90 +++++--------------
src/Frontend-GNOME/Views/ServerWidget.cs | 8 ++
7 files changed, 81 insertions(+), 165 deletions(-)
---
diff --git a/src/Engine-XMPP/Config/XmppServerModel.cs b/src/Engine-XMPP/Config/XmppServerModel.cs
index c29c3a7..c22127b 100644
--- a/src/Engine-XMPP/Config/XmppServerModel.cs
+++ b/src/Engine-XMPP/Config/XmppServerModel.cs
@@ -37,17 +37,6 @@ namespace Smuxi.Engine
Protocol = "XMPP";
}
- public virtual void Load(UserConfig config, string id)
- {
- if (config == null) {
- throw new ArgumentNullException("config");
- }
- if (String.IsNullOrEmpty(id)) {
- throw new ArgumentNullException("id");
- }
- Load(config, Protocol, id);
- }
-
public XmppServerModel()
{
InitDefaults();
diff --git a/src/Engine-XMPP/Engine-XMPP.csproj b/src/Engine-XMPP/Engine-XMPP.csproj
index 0e88bb5..c82373f 100644
--- a/src/Engine-XMPP/Engine-XMPP.csproj
+++ b/src/Engine-XMPP/Engine-XMPP.csproj
@@ -42,12 +42,11 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="..\AssemblyVersion.cs" />
<Compile Include="Protocols\Xmpp\XmppGroupChatModel.cs" />
- <Compile Include="Protocols\Xmpp\IQ\OwnMessage.cs" />
<Compile Include="Config\XmppServerModel.cs" />
<Compile Include="Config\XmppPersonModel.cs" />
</ItemGroup>
<ItemGroup>
- <Folder Include="Protocols\Xmpp\IQ\" />
+ <Compile Include="Protocols\Xmpp\FacebookProtocolManager.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
diff --git a/src/Engine-XMPP/Makefile.am b/src/Engine-XMPP/Makefile.am
index 352bec8..9feb5d6 100644
--- a/src/Engine-XMPP/Makefile.am
+++ b/src/Engine-XMPP/Makefile.am
@@ -10,7 +10,7 @@ SOURCES = \
Protocols/Xmpp/XmppGroupChatModel.cs \
Protocols/Xmpp/XmppProtocolManager.cs \
Config/XmppPersonModel.cs \
- Protocols/Xmpp/IQ/OwnMessage.cs
+ Protocols/Xmpp/FacebookProtocolManager.cs
REFERENCES = \
System \
diff --git a/src/Engine-XMPP/Protocols/Xmpp/FacebookProtocolManager.cs
b/src/Engine-XMPP/Protocols/Xmpp/FacebookProtocolManager.cs
new file mode 100644
index 0000000..97b1c17
--- /dev/null
+++ b/src/Engine-XMPP/Protocols/Xmpp/FacebookProtocolManager.cs
@@ -0,0 +1,47 @@
+// Smuxi - Smart MUltipleXed Irc
+//
+// Copyright (c) 2014 Oliver Schneider <smuxi oli-obk de>
+//
+// 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.Engine;
+using Smuxi.Common;
+
+namespace Smuxi.Engine
+{
+ [ProtocolManagerInfo(Name = "Facebook", Description = "Facebook XMPP", Alias = "facebook")]
+ public class FacebookProtocolManager : XmppProtocolManager
+ {
+ public override string Protocol {
+ get {
+ return "Facebook";
+ }
+ }
+
+ public FacebookProtocolManager(Session session) :
+ base(session)
+ {
+ Trace.Call(session);
+ }
+
+ override protected string GenerateIdString(PersonModel contact)
+ {
+ return "";
+ }
+ }
+}
+
diff --git a/src/Engine-XMPP/Protocols/Xmpp/XmppProtocolManager.cs
b/src/Engine-XMPP/Protocols/Xmpp/XmppProtocolManager.cs
index 5934f13..cb5381a 100644
--- a/src/Engine-XMPP/Protocols/Xmpp/XmppProtocolManager.cs
+++ b/src/Engine-XMPP/Protocols/Xmpp/XmppProtocolManager.cs
@@ -3,7 +3,7 @@
*
* Copyright (c) 2005-2013 Mirco Bauer <meebey meebey net>
* Copyright (c) 2011 Tuukka Hastrup <Tuukka Hastrup iki fi>
- * Copyright (c) 2013 Oliver Schneider <smuxi oli-obk de>
+ * Copyright (c) 2013-2014 Oliver Schneider <smuxi oli-obk de>
*
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
*
@@ -86,12 +86,8 @@ namespace Smuxi.Engine
ChatModel NetworkChat { get; set; }
GroupChatModel ContactChat { get; set; }
XmppServerModel Server { get; set; }
- // facebook messed up, this is part of a hack to fix that messup
- string LastSentMessage { get; set; }
- bool SupressLocalMessageEcho { get; set; }
bool AutoReconnect { get; set; }
TimeSpan AutoReconnectDelay { get; set; }
- bool IsFacebook { get; set; }
bool IsDisposed { get; set; }
bool ShowChatStates { get; set; }
// pidgin's psychic mode
@@ -127,7 +123,6 @@ namespace Smuxi.Engine
Contacts = new Dictionary<Jid, XmppPersonModel>();
DiscoCache = new Dictionary<string, DiscoInfo>();
- SupressLocalMessageEcho = false;
ShowChatStates = true;
OpenNewChatOnChatState = true;
@@ -144,7 +139,6 @@ namespace Smuxi.Engine
JabberClient.OnReadXml += OnReadXml;
JabberClient.OnWriteXml += OnWriteXml;
JabberClient.OnAuthError += OnAuthError;
- JabberClient.OnIq += OnIq;
JabberClient.SendingServiceUnavailable += OnSendingServiceUnavailable;
JabberClient.AutoAgents = false; // outdated feature
JabberClient.EnableCapabilities = true;
@@ -162,15 +156,11 @@ namespace Smuxi.Engine
JabberClient.DiscoInfo.AddFeature().Var = "jabber:iq:last";
JabberClient.DiscoInfo.AddFeature().Var = "http://jabber.org/protocol/muc";
JabberClient.DiscoInfo.AddFeature().Var = "http://jabber.org/protocol/disco#info";
- JabberClient.DiscoInfo.AddFeature().Var = "http://www.facebook.com/xmpp/messages";
JabberClient.DiscoInfo.AddFeature().Var = "http://jabber.org/protocol/xhtml-im";
Disco = new DiscoManager(JabberClient);
Disco.AutoAnswerDiscoInfoRequests = true;
- // facebook own message echo
- ElementFactory.AddElementType("own-message", "http://www.facebook.com/xmpp/messages",
typeof(OwnMessageQuery));
-
MucManager = new MucManager(JabberClient);
}
@@ -252,7 +242,7 @@ namespace Smuxi.Engine
} else {
Server = new XmppServerModel();
if (server.ServerID != null) {
- Server.Load(Session.UserConfig, server.ServerID);
+ Server.Load(Session.UserConfig, Protocol, server.ServerID);
}
// HACK: previous line overwrites any passed values with the values from config
// thus we have to copy the original values:
@@ -277,6 +267,14 @@ namespace Smuxi.Engine
NetworkID, String.Format("{0} {1}", Protocol, Host), this
);
Session.AddChat(NetworkChat);
+ if (Host.EndsWith("facebook.com") && !(this is FacebookProtocolManager)) {
+ var builder = CreateMessageBuilder();
+ builder.AppendEventPrefix();
+ builder.AppendMessage(_("This engine has native Facebook support, you should be using it
instead of connecting to facebook with xmpp"));
+ // cannot use AddMessageToFrontend because NetworkChat is not yet synced, causing
AddMessageToFrontend to drop it.
+ // cannot sync NetworkChat before this, because then the sync would swallow the message
+ Session.AddMessageToChat(NetworkChat, builder.ToMessage());
+ }
Session.SyncChat(NetworkChat);
Connect();
@@ -298,7 +296,6 @@ namespace Smuxi.Engine
#if LOG4NET
_Logger.Debug("calling JabberClient.Open()");
#endif
- IsFacebook = (JabberClient.Server == "chat.facebook.com");
JabberClient.Open();
}
@@ -345,7 +342,6 @@ namespace Smuxi.Engine
JabberClient.OnReadXml -= OnReadXml;
JabberClient.OnWriteXml -= OnWriteXml;
JabberClient.OnAuthError -= OnAuthError;
- JabberClient.OnIq -= OnIq;
JabberClient.ClientSocket.OnValidateCertificate -= ValidateCertificate;
JabberClient.SendingServiceUnavailable -= OnSendingServiceUnavailable;
JabberClient.SocketDisconnect();
@@ -1333,11 +1329,6 @@ namespace Smuxi.Engine
JabberClient.Send(new Message(chat.ID, XmppMessageType.groupchat, text));
return; // don't show now. the message will be echoed back if it's sent successfully
}
- if (IsFacebook && SupressLocalMessageEcho) {
- // don't show, facebook is bugging again
- return;
- }
- LastSentMessage = text;
}
var builder = CreateMessageBuilder();
@@ -1491,14 +1482,8 @@ namespace Smuxi.Engine
contact.Ask = rosterItem.Ask;
string oldIdentityName = contact.IdentityName;
var oldIdentityNameColored = contact.IdentityNameColored;
- if (IsFacebook) {
- // facebook bug. prevent clearing of name
- if (rosterItem.Name != null) {
- contact.IdentityName = rosterItem.Name;
- }
- } else {
- contact.IdentityName = rosterItem.Name ?? rosterItem.Jid;
- }
+
+ contact.IdentityName = rosterItem.Name ?? rosterItem.Jid;
if (oldIdentityName == contact.IdentityName) {
// identity name didn't change
@@ -1514,10 +1499,7 @@ namespace Smuxi.Engine
{
var builder = CreateMessageBuilder();
builder.AppendEventPrefix();
- string idstring = "";
- if (!IsFacebook && oldIdentityName != contact.Jid) {
- idstring = " [" + contact.Jid + "]";
- }
+ string idstring = (oldIdentityName == contact.Jid.Bare)?"":GenerateIdString(contact);
oldIdentityNameColored.BackgroundColor = TextColor.None;
builder.AppendFormat("{2}{1} is now known as {0}", contact, idstring, oldIdentityNameColored);
@@ -1543,6 +1525,15 @@ namespace Smuxi.Engine
}
}
+ protected virtual string GenerateIdString(PersonModel contact)
+ {
+ if (contact.ID == contact.IdentityName) {
+ return "";
+ }
+ var jid = new Jid(contact.ID);
+ return String.Format(" [{0}]", jid.Bare);
+ }
+
void RequestCapabilities(Jid jid, Capabilities caps)
{
string hash = caps.Node + "#" + caps.Version;
@@ -1628,11 +1619,7 @@ namespace Smuxi.Engine
{
var builder = CreateMessageBuilder();
builder.AppendEventPrefix();
- string idstring = "";
- // print jid (except in case of facebook where it is meaningless)
- if (!IsFacebook && jid.Bare != person.IdentityName) {
- idstring = String.Format(" [{0}]", jid.Bare);
- }
+ string idstring = GenerateIdString(person);
// print the type (and in case of available detailed type)
switch (pres.Type) {
case PresenceType.available:
@@ -1835,7 +1822,7 @@ namespace Smuxi.Engine
void OnGroupChatPresence(XmppGroupChatModel chat, Presence pres)
{
Jid jid = pres.From;
- var person = new PersonModel(jid, pres.From.Resource, NetworkID, Protocol, this);
+ var person = new XmppPersonModel(jid, pres.From.Resource, this);
PrintGroupChatPresence(chat, person, pres);
switch (pres.Type) {
case PresenceType.available:
@@ -2372,35 +2359,6 @@ namespace Smuxi.Engine
Session.AddMessageToChat(NetworkChat, builder.ToMessage());
}
- void OnIq(object sender, IQEventArgs e)
- {
- Trace.Call(sender, e);
-
- // not as pretty as the previous implementation, but it works
- var elem = e.IQ.SelectSingleElement("own-message");
- if (elem is OwnMessageQuery) {
- OnIQOwnMessage((OwnMessageQuery) elem);
- e.Handled = true;
- }
- }
-
- [MethodImpl(MethodImplOptions.Synchronized)]
- void OnIQOwnMessage(OwnMessageQuery query)
- {
- if (query.Self) {
- // we send this message from Smuxi, nothing to do...
- return;
- }
-
- if (!SupressLocalMessageEcho && (query.Body == LastSentMessage)) {
- SupressLocalMessageEcho = true;
- return;
- }
- var chat = GetOrCreatePersonChat(query.To);
-
- _Say(chat, query.Body, false);
- }
-
[MethodImpl(MethodImplOptions.Synchronized)]
PersonChatModel GetOrCreatePersonChat(Jid jid)
{
diff --git a/src/Frontend-GNOME/Views/ServerWidget.cs b/src/Frontend-GNOME/Views/ServerWidget.cs
index a71b9e6..37e78ca 100644
--- a/src/Frontend-GNOME/Views/ServerWidget.cs
+++ b/src/Frontend-GNOME/Views/ServerWidget.cs
@@ -310,6 +310,14 @@ namespace Smuxi.Frontend.Gnome
f_PortSpinButton.Value = 6667;
f_PortSpinButton.Sensitive = true;
break;
+ case "Facebook":
+ ShowHostname = false;
+ ShowNetwork = false;
+ ShowPassword = true;
+ SupportUseEncryption = true;
+ f_HostnameEntry.Text = "chat.facebook.com";
+ f_PortSpinButton.Value = 5222;
+ break;
case "XMPP":
ShowHostname = true;
ShowNetwork = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]