Added:
trunk/Theminds/Filters/Users.cs
Modified:
trunk/Theminds/App.cs
trunk/Theminds/AppControls.cs
trunk/Theminds/Buffer.cs
trunk/Theminds/Filters/JoinPartQuitFilter.cs
trunk/Theminds/Filters/NamesFilter.cs
trunk/Theminds/Tests/MockApp.cs
trunk/Theminds/Theminds.csproj
Log:
* OK, Broadcasting quit messages only to channels with the quitting user.
* GetRoom in Buffer, called from Users
* broadcastHelper takes a BufferData now
* broadcastId instead of a boolean
* quit.[user] semantics
* app.Buffer.Broadcast event hook in NamesFilter? Not the best place.
* Coming in as a filter for now.
* Buffer takes a Quirk: cutting off app.CurrentConnection shit
Modified: trunk/Theminds/App.cs
==============================================================================
--- trunk/Theminds/App.cs (original)
+++ trunk/Theminds/App.cs Sun Jun 10 08:23:12 2007
@@ -15,7 +15,7 @@
public static Ideas Lion = new Ideas(@"lion.txt");
- Buffer buffer; Quirk quirk; Users users;
+ Buffer buffer; Quirk quirk;
public App() {
this.SetUpForm(); // SetUpForm.cs
@@ -25,8 +25,7 @@
mozNet.User = "USER cryptoliter2 8 * :Hi";
quirk = new Quirk(mozNet);
- this.buffer = new Buffer(this);
- this.users = new Users();
+ this.buffer = new Buffer(this, quirk);
quirk.NewLine += new Quirk.NewLineDel(Buffer.AddLine);
App.LoadAttributeLovers(
typeof(DesiresAppControlsAttribute), this);
Modified: trunk/Theminds/AppControls.cs
==============================================================================
--- trunk/Theminds/AppControls.cs (original)
+++ trunk/Theminds/AppControls.cs Sun Jun 10 08:23:12 2007
@@ -9,7 +9,6 @@
Tabber Tabber { get; }
Quirk Connection { get;}
Buffer Buffer { get;}
- Users Users { get;}
UserList UserList { get;}
InputBox InputBox { get;}
string CurrentChannel { get; set;}
@@ -45,10 +44,6 @@
public Buffer Buffer {
get { return buffer; }
- }
-
- public Users Users {
- get { return users; }
}
public void SwitchLogBox(LogBox l) {
Modified: trunk/Theminds/Buffer.cs
==============================================================================
--- trunk/Theminds/Buffer.cs (original)
+++ trunk/Theminds/Buffer.cs Sun Jun 10 08:23:12 2007
@@ -16,10 +16,12 @@
// I need the two-way-osity for AddLine.
TwoWayDictionary<ITab, Room> proust = new TwoWayDictionary<ITab, Room>(5);
- public Buffer(IAppControls app) {
+ Quirk connection;
+ public Buffer(IAppControls app, Quirk quirk) {
this.app = app;
+ this.connection = quirk;
- Room id = new Room(app.Connection, null, app.LogBox);
+ Room id = new Room(quirk, null, app.LogBox);
proust[app.Tabber.Current] = id;
// Page.Buffering events.
@@ -41,9 +43,9 @@
if (data.Ignore) return;
if (data.BroadcastId != null)
- broadcastHelper(data.Line, data.Color);
+ broadcastHelper(data);
else {
- Room tab = new Room(app.Connection, data.Channel, null);
+ Room tab = new Room(this.connection, data.Channel, null);
if (!proust.ContainsKey(tab))
app.Invoke((M)delegate { AddChannel(tab); });
@@ -56,18 +58,18 @@
}
}
- private void broadcastHelper(string line, Color color) {
+ private void broadcastHelper(BufferData data) {
List<Room> tabs = proust.Values;
- Broadcast(ref tabs);
+ Broadcast(ref tabs, data.BroadcastId);
app.BeginInvoke((M)delegate {
tabs.ForEach((Action<Room>)delegate(Room tab) {
- tab.LogBox.AddLine(line, color);
+ tab.LogBox.AddLine(data.Line, data.Color);
});
});
}
public void AddChannel() {
- AddChannel(new Room(app.Connection, null, null));
+ AddChannel(new Room(this.connection, null, null));
}
public void AddChannel(Room tab) {
app.CurrentChannel = tab.Channel;
@@ -100,6 +102,10 @@
app.Connection.Message("PART {0}", channel);
}
+ public Room GetRoom(BufferData data) {
+ return new Room(this.connection, data.Channel, null);
+ }
+
public event LineDel PreLine = delegate { };
public event LineDel Line = delegate { };
public event LineDel SelfLine = delegate { };
@@ -109,5 +115,5 @@
}
public delegate void LineDel(ref BufferData data);
- public delegate void BroadcastDel(ref List<Room> tabs);
+ public delegate void BroadcastDel(ref List<Room> tabs, string id);
}
Modified: trunk/Theminds/Filters/JoinPartQuitFilter.cs
==============================================================================
--- trunk/Theminds/Filters/JoinPartQuitFilter.cs (original)
+++ trunk/Theminds/Filters/JoinPartQuitFilter.cs Sun Jun 10 08:23:12 2007
@@ -40,7 +40,7 @@
reasonIndex = spaces[2] + 1; break;
case "quit":
reasonIndex = spaces[1] + 1;
- data.BroadcastId = "quit"; break;
+ data.BroadcastId = "quit." + notes.Nick; break;
default: return;
}
notes.ReasonIndex = reasonIndex;
Modified: trunk/Theminds/Filters/NamesFilter.cs
==============================================================================
--- trunk/Theminds/Filters/NamesFilter.cs (original)
+++ trunk/Theminds/Filters/NamesFilter.cs Sun Jun 10 08:23:12 2007
@@ -16,8 +16,6 @@
public NamesFilter(IAppControls app) {
this.app = app;
app.Buffer.Line += new LineDel(filter);
- app.Buffer.Broadcast += delegate(ref List<Room> tabs) {
- };
}
// line ~ "[server] = <channel> :[[@|+]<nick> [[@|+]<nick> [...]]]"
@@ -32,11 +30,14 @@
string test = S.Format("{0} = ", serverPrefix);
if (!data.Line.StartsWith(test)) return;
-
+
+ // Remember the colon! Rememebr the weird tacked space!
int[] spaces = Sx.FindSpaces(data.Line, 4);
- // Remember the colon! Remember the weird tacked space!
+ data.Channel = Sx.Tween(data.Line, spaces[1], spaces[2] - 1);
string[] nicks = data.Line.Substring(spaces[2] + 1).Trim().Split(' ');
+ Users.Instance.Clear(data);
foreach (string nick in nicks) {
+ Users.Instance[data] = nick;
app.UserList.Push(nick);
}
data.Ignore = true;
Added: trunk/Theminds/Filters/Users.cs
==============================================================================
--- (empty file)
+++ trunk/Theminds/Filters/Users.cs Sun Jun 10 08:23:12 2007
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+
+namespace Theminds {
+ [DesiresAppControls]
+ public class Users : Dictionary<Room, List<string>> {
+ IAppControls app;
+ public static Users Instance;
+ public Users(IAppControls app) : base(5) {
+ this.app = app;
+ Users.Instance = this;
+
+ // Only broadcast quit messages to the channels
+ // that actually contain the quitting user.
+ // The `id` is "quit.[user]". See JPQF.cs.
+ app.Buffer.Broadcast += delegate(ref List<Room> tabs, string id) {
+ if (!id.StartsWith("quit.")) return;
+ string quitter = id.Split('.')[1];
+ // Todo: Handle @+% fun.
+ tabs = tabs.FindAll(delegate(Room room) {
+ List<string> nicks = Users.Instance[room];
+ return nicks.Contains(quitter);
+ });
+ };
+ }
+
+ public void Clear(BufferData data) {
+ this[app.Buffer.GetRoom(data)] = new List<string>(20);
+ }
+
+ public new List<string> this[Room index] {
+ get {
+ if (!this.ContainsKey(index)) return new List<string>();
+ else return base[index];
+ }
+ set { base[index] = value; }
+ }
+
+ public string this[BufferData index] {
+ set {
+ Room room = app.Buffer.GetRoom(index);
+ if (this.ContainsKey(room)) this[room].Add(value);
+ else {
+ this[room] = new List<string>(20);
+ this[room].Add(value);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Theminds/Tests/MockApp.cs
==============================================================================
--- trunk/Theminds/Tests/MockApp.cs (original)
+++ trunk/Theminds/Tests/MockApp.cs Sun Jun 10 08:23:12 2007
@@ -23,10 +23,9 @@
quirk = new Quirk(mozNet);
this.tabber = new Tabber(this, "(new)");
- tabber.NewTab += delegate {
- };
+ tabber.NewTab += delegate { };
tabber.Add("(server)");
- this.buffer = new Buffer(this);
+ this.buffer = new Buffer(this, quirk);
this.userList = new UserList();
}
Modified: trunk/Theminds/Theminds.csproj
==============================================================================
--- trunk/Theminds/Theminds.csproj (original)
+++ trunk/Theminds/Theminds.csproj Sun Jun 10 08:23:12 2007
@@ -70,7 +70,7 @@
<Compile Include="Tests\MockApp.cs" />
<Compile Include="Tests\NamesFilter.cs" />
<Compile Include="Tests\PrivmsgFilter.cs" />
- <Compile Include="Users.cs" />
+ <Compile Include="Filters\Users.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Plainclothes\lion.txt" />