[smuxi: 52/111] Engine: implemented engine/session/on-group-chat-person-(added|removed|updated) hook points
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi: 52/111] Engine: implemented engine/session/on-group-chat-person-(added|removed|updated) hook points
- Date: Sun, 16 Feb 2014 13:17:37 +0000 (UTC)
commit cce2df80fb91737f84d59eac0ea42735fc18fdda
Author: Mirco Bauer <meebey meebey net>
Date: Fri Jan 3 21:14:15 2014 +0100
Engine: implemented engine/session/on-group-chat-person-(added|removed|updated) hook points
src/Engine/Engine.csproj | 1 +
.../Hooks/Environments/PersonHookEnvironment.cs | 43 ++++++
.../Environments/ProtocolManagerHookEnvironment.cs | 1 +
src/Engine/Makefile.am | 1 +
src/Engine/Session.cs | 136 +++++++++++++++++++-
5 files changed, 181 insertions(+), 1 deletions(-)
---
diff --git a/src/Engine/Engine.csproj b/src/Engine/Engine.csproj
index b2a4a07..8bd8d98 100644
--- a/src/Engine/Engine.csproj
+++ b/src/Engine/Engine.csproj
@@ -106,6 +106,7 @@
<Compile Include="Hooks\Commands\SessionHookCommand.cs" />
<Compile Include="Hooks\Environments\CommandHookEnvironment.cs" />
<Compile Include="Config\MessageBuilderSettings.cs" />
+ <Compile Include="Hooks\Environments\PersonHookEnvironment.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Protocols\" />
diff --git a/src/Engine/Hooks/Environments/PersonHookEnvironment.cs
b/src/Engine/Hooks/Environments/PersonHookEnvironment.cs
new file mode 100644
index 0000000..904da3b
--- /dev/null
+++ b/src/Engine/Hooks/Environments/PersonHookEnvironment.cs
@@ -0,0 +1,43 @@
+// Smuxi - Smart MUltipleXed Irc
+//
+// Copyright (c) 2014 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;
+
+namespace Smuxi.Engine
+{
+ public class PersonHookEnvironment : HookEnvironment
+ {
+ public PersonHookEnvironment(PersonModel person) :
+ this(null, person)
+ {
+ }
+
+ public PersonHookEnvironment(string prefix, PersonModel person)
+ {
+ if (person == null) {
+ throw new ArgumentNullException("person");
+ }
+
+ this[prefix + "PERSON_ID"] = person.ID;
+ this[prefix + "PERSON_IDENTITY_NAME"] = person.IdentityName;
+ this[prefix + "PERSON_NETWORK_ID"] = person.NetworkID;
+ this[prefix + "PERSON_NETWORK_PROTOCOL"] = person.NetworkProtocol;
+ }
+ }
+}
diff --git a/src/Engine/Hooks/Environments/ProtocolManagerHookEnvironment.cs
b/src/Engine/Hooks/Environments/ProtocolManagerHookEnvironment.cs
index bf545bf..b6220d2 100644
--- a/src/Engine/Hooks/Environments/ProtocolManagerHookEnvironment.cs
+++ b/src/Engine/Hooks/Environments/ProtocolManagerHookEnvironment.cs
@@ -36,6 +36,7 @@ namespace Smuxi.Engine
if (protocolManager.Me != null) {
this["PROTOCOL_MANAGER_ME_ID"] = protocolManager.Me.ID;
}
+ this["PROTOCOL_PRESENCE_STATUS"] = protocolManager.PresenceStatus.ToString();
}
}
}
diff --git a/src/Engine/Makefile.am b/src/Engine/Makefile.am
index 9b8dc18..1403715 100644
--- a/src/Engine/Makefile.am
+++ b/src/Engine/Makefile.am
@@ -109,6 +109,7 @@ FILES = \
Hooks/Environments/CommandHookEnvironment.cs \
Hooks/Environments/HookEnvironment.cs \
Hooks/Environments/MessageHookEnvironment.cs \
+ Hooks/Environments/PersonHookEnvironment.cs \
Hooks/Environments/ProtocolManagerHookEnvironment.cs
DATA_FILES =
diff --git a/src/Engine/Session.cs b/src/Engine/Session.cs
index 9c552c1..7bebecd 100644
--- a/src/Engine/Session.cs
+++ b/src/Engine/Session.cs
@@ -1,7 +1,7 @@
/*
* Smuxi - Smart MUltipleXed Irc
*
- * Copyright (c) 2005-2013 Mirco Bauer <meebey meebey net>
+ * Copyright (c) 2005-2014 Mirco Bauer <meebey meebey net>
*
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
*
@@ -59,6 +59,10 @@ namespace Smuxi.Engine
TimeSpan NewsFeedUpdateInterval { get; set; }
TimeSpan NewsFeedRetryInterval { get; set; }
+ public event EventHandler<GroupChatPersonAddedEventArgs> GroupChatPersonAdded;
+ public event EventHandler<GroupChatPersonRemovedEventArgs> GroupChatPersonRemoved;
+ public event EventHandler<GroupChatPersonUpdatedEventArgs> GroupChatPersonUpdated;
+
public IList<IProtocolManager> ProtocolManagers {
get {
return _ProtocolManagers;
@@ -1278,6 +1282,10 @@ namespace Smuxi.Engine
fm.AddPersonToGroupChat(groupChat, person);
}
}
+
+ OnGroupChatPersonAdded(
+ new GroupChatPersonAddedEventArgs(groupChat, person)
+ );
}
public void UpdatePersonInGroupChat(GroupChatModel groupChat, PersonModel oldPerson, PersonModel
newPerson)
@@ -1308,6 +1316,10 @@ namespace Smuxi.Engine
fm.UpdatePersonInGroupChat(groupChat, oldPerson, newPerson);
}
}
+
+ OnGroupChatPersonUpdated(
+ new GroupChatPersonUpdatedEventArgs(groupChat, oldPerson, newPerson)
+ );
}
public void UpdateTopicInGroupChat(GroupChatModel groupChat, MessageModel topic)
@@ -1348,6 +1360,10 @@ namespace Smuxi.Engine
fm.RemovePersonFromGroupChat(groupChat, person);
}
}
+
+ OnGroupChatPersonRemoved(
+ new GroupChatPersonRemovedEventArgs(groupChat, person)
+ );
}
public void SetNetworkStatus(string status)
@@ -1827,9 +1843,127 @@ namespace Smuxi.Engine
}
}
+ protected virtual void OnGroupChatPersonAdded(GroupChatPersonAddedEventArgs e)
+ {
+ if (GroupChatPersonAdded != null) {
+ GroupChatPersonAdded(this, e);
+ }
+
+ var pm = e.GroupChat.ProtocolManager;
+ var hooks = new HookRunner("engine", "session", "on-group-chat-person-added");
+ hooks.Environments.Add(new ChatHookEnvironment(e.GroupChat));
+ if (pm != null) {
+ hooks.Environments.Add(new ProtocolManagerHookEnvironment(pm));
+ }
+ hooks.Environments.Add(new PersonHookEnvironment(e.AddedPerson));
+
+ var cmdChar = (string) UserConfig["Interface/Entry/CommandCharacter"];
+ hooks.Commands.Add(new SessionHookCommand(this, e.GroupChat, cmdChar));
+ if (pm != null) {
+ hooks.Commands.Add(new ProtocolManagerHookCommand(pm, e.GroupChat, cmdChar));
+ }
+
+ // show time
+ hooks.Init();
+ hooks.Run();
+ }
+
+ protected virtual void OnGroupChatPersonRemoved(GroupChatPersonRemovedEventArgs e)
+ {
+ if (GroupChatPersonRemoved != null) {
+ GroupChatPersonRemoved(this, e);
+ }
+
+ var pm = e.GroupChat.ProtocolManager;
+ var hooks = new HookRunner("engine", "session", "on-group-chat-person-removed");
+ hooks.Environments.Add(new ChatHookEnvironment(e.GroupChat));
+ if (pm != null) {
+ hooks.Environments.Add(new ProtocolManagerHookEnvironment(pm));
+ }
+ hooks.Environments.Add(new PersonHookEnvironment(e.RemovedPerson));
+
+ var cmdChar = (string) UserConfig["Interface/Entry/CommandCharacter"];
+ hooks.Commands.Add(new SessionHookCommand(this, e.GroupChat, cmdChar));
+ if (pm != null) {
+ hooks.Commands.Add(new ProtocolManagerHookCommand(pm, e.GroupChat, cmdChar));
+ }
+
+ // show time
+ hooks.Init();
+ hooks.Run();
+ }
+
+ protected virtual void OnGroupChatPersonUpdated(GroupChatPersonUpdatedEventArgs e)
+ {
+ if (GroupChatPersonUpdated != null) {
+ GroupChatPersonUpdated(this, e);
+ }
+
+ var pm = e.GroupChat.ProtocolManager;
+ var hooks = new HookRunner("engine", "session", "on-group-chat-person-updated");
+ hooks.Environments.Add(new ChatHookEnvironment(e.GroupChat));
+ if (pm != null) {
+ hooks.Environments.Add(new ProtocolManagerHookEnvironment(pm));
+ }
+ hooks.Environments.Add(new PersonHookEnvironment("OLD_", e.OldPerson));
+ hooks.Environments.Add(new PersonHookEnvironment("NEW_", e.NewPerson));
+
+ var cmdChar = (string) UserConfig["Interface/Entry/CommandCharacter"];
+ hooks.Commands.Add(new SessionHookCommand(this, e.GroupChat, cmdChar));
+ if (pm != null) {
+ hooks.Commands.Add(new ProtocolManagerHookCommand(pm, e.GroupChat, cmdChar));
+ }
+
+ // show time
+ hooks.Init();
+ hooks.Run();
+ }
+
private static string _(string msg)
{
return LibraryCatalog.GetString(msg, _LibraryTextDomain);
}
}
+
+ public abstract class GroupChatEventArgs : EventArgs
+ {
+ public GroupChatModel GroupChat { get; protected set; }
+ }
+
+ public class GroupChatPersonAddedEventArgs : GroupChatEventArgs
+ {
+ public PersonModel AddedPerson { get; private set; }
+
+ public GroupChatPersonAddedEventArgs(GroupChatModel groupChat, PersonModel addedPerson)
+ {
+ GroupChat = groupChat;
+ AddedPerson = addedPerson;
+ }
+ }
+
+ public class GroupChatPersonRemovedEventArgs : GroupChatEventArgs
+ {
+ public PersonModel RemovedPerson { get; private set; }
+
+ public GroupChatPersonRemovedEventArgs(GroupChatModel groupChat, PersonModel removedPerson)
+ {
+ GroupChat = groupChat;
+ RemovedPerson = removedPerson;
+ }
+ }
+
+ public class GroupChatPersonUpdatedEventArgs : GroupChatEventArgs
+ {
+ public PersonModel OldPerson { get; private set; }
+ public PersonModel NewPerson { get; private set; }
+
+ public GroupChatPersonUpdatedEventArgs(GroupChatModel groupChat,
+ PersonModel oldPerson,
+ PersonModel newPerson)
+ {
+ GroupChat = groupChat;
+ OldPerson = oldPerson;
+ NewPerson = newPerson;
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]