예제 #1
0
 public void MakeRoomLoadNext(JabbRRoom room)
 {
     // bump room to load next
     if (loadingRooms != null)
     {
         lock (loadingRooms)
         {
             if (loadingRooms.Contains(room))
             {
                 //Debug.WriteLine(string.Format("Bumping room from {0}", loadingRooms.IndexOf(room)));
                 loadingRooms.Remove(room);
                 loadingRooms.Insert(0, room);
             }
         }
     }
 }
예제 #2
0
        void HookupEvents()
        {
            Client.MessageReceived += (message, room) =>
            {
                Debug.Print("MessageReceived, Room: {3}, When: {0}, User: {1}, Content: {2}", message.When, message.User.Name, message.Content, room);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    channel.TriggerMessage(channel.CreateMessage(message));
                    OnChannelInfoChanged(new ChannelEventArgs(channel));
                }
            };
            Client.Disconnected += () =>
            {
                Debug.Print("Disconnected");
                if (disconnectTask != null)
                {
                    disconnectTask.TrySetResult(null);
                }
                if (timer != null)
                {
                    timer.Dispose();
                    timer = null;
                }
                OnDisconnected(EventArgs.Empty);
            };
            Client.FlagChanged += (user, flag) =>
            {
                Debug.Print("FlagChanged, User: {0}, Flag: {1}", user.Name, flag);
            };
            Client.GravatarChanged += (user, gravatar) =>
            {
                Debug.Print("GravatarChanged, User: {0}, Gravatar: {1}", user.Name, gravatar);
            };
            Client.Kicked += user =>
            {
                Debug.Print("Kicked: {0}", user);
            };
            Client.LoggedOut += rooms =>
            {
                Debug.Print("LoggedOut, Rooms: {0}", string.Join(", ", rooms));
            };
            Client.MeMessageReceived += (user, content, room) =>
            {
                Debug.Print("MeMessageReceived, User: {0}, Content: {1}, Room: {2}", user, content, room);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    channel.TriggerMeMessage(user, content);
                }
            };
            Client.NoteChanged += (user, room) =>
            {
                Debug.Print("NoteChanged, User: {0}, Room: {1}", user.Name, room);
            };
            Client.OwnerAdded += (user, room) =>
            {
                Debug.Print("OwnerAdded, User: {0}, Room: {1}", user.Name, room);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    channel.TriggerOwnerAdded(user);
                }
            };
            Client.OwnerRemoved += (user, room) =>
            {
                Debug.Print("OwnerRemoved, User: {0}, Room: {1}", user.Name, room);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    channel.TriggerOwnerRemoved(user);
                }
            };
            Client.PrivateMessage += (from, to, message) =>
            {
                Debug.Print("PrivateMessage, From: {0}, To: {1}, Message: {2} ", from, to, message);

                var       user = from == CurrentUser.Name ? to : from;
                JabbRChat chat;
                if (InternalStartChat(new JabbRUser(this, user)
                {
                    Active = true
                }, false, message, out chat))
                {
                    chat.TriggerMessage(new ChannelMessage(Guid.NewGuid().ToString(), DateTimeOffset.Now, from, message));
                    OnChannelInfoChanged(new ChannelEventArgs(chat));
                }
            };
            Client.RoomChanged += room =>
            {
                Debug.Print("RoomChanged, Room: {0}", room.Name);
            };
            Client.TopicChanged += (roomName, topic, who) =>
            {
                Debug.Print("TopicChanged, Room: {0}, Topic: {1}", roomName, topic);
                var channel = GetRoom(roomName);
                if (channel != null)
                {
                    channel.SetNewTopic(topic, who);
                }
            };
            Client.UserActivityChanged += user =>
            {
                Debug.Print("UserActivityChanged, User: {0}, Activity: {1}", user.Name, user.Active);
                foreach (var channel in Channels.OfType <JabbRChannel>())
                {
                    channel.TriggerActivityChanged(new [] { user });
                }
            };
            Client.JoinedRoom += async room =>
            {
                Debug.Print("JoinedRoom, Room: {0}", room.Name);
                var  channel    = GetRoom(room.Name);
                bool newChannel = channel == null;
                if (channel == null)
                {
                    channel = new JabbRRoom(this, room);
                }
                OnOpenChannel(new OpenChannelEventArgs(channel, true, newChannel));
                if (newChannel)
                {
                    await channel.LoadRoomInfo();
                }
            };
            Client.UserJoined += (user, room, isOwner) =>
            {
                Debug.Print("UserJoined, User: {0}, Room: {1}", user.Name, room);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    if (isOwner)
                    {
                        channel.TriggerOwnerAdded(user);
                    }
                    channel.TriggerUserJoined(new UserEventArgs(new JabbRUser(this, user), DateTimeOffset.Now));
                }
            };
            Client.UserLeft += (user, room) =>
            {
                Debug.Print("UserLeft, User: {0}, Room: {1}", user.Name, room);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    if (user.Name == CurrentJabbRUser.Name)
                    {
                        channel.TriggerClosed(EventArgs.Empty);
                        OnCloseChannel(new ChannelEventArgs(channel));
                    }
                    else
                    {
                        channel.TriggerUserLeft(new UserEventArgs(new JabbRUser(this, user), DateTimeOffset.Now));
                    }
                }
            };
            Client.UsernameChanged += (oldUserName, user, room) =>
            {
                Debug.Print("UsernameChanged, OldUserName: {0}, NewUserName: {1}, Room: {2}", oldUserName, user.Name, room);
                if (oldUserName == CurrentUser.Name)
                {
                    // current user, so update all chat channels with new name as well
                    CurrentUser.Name = user.Name;
                    foreach (var chat in Channels.OfType <JabbRChat> ())
                    {
                        chat.TriggerUsernameChanged(oldUserName, user, true);
                    }
                }
                else
                {
                    var chat = GetChat(oldUserName);
                    if (chat != null)
                    {
                        chat.TriggerUsernameChanged(oldUserName, user, false);
                    }
                }

                var channel = GetRoom(room);
                if (channel != null)
                {
                    channel.TriggerUsernameChanged(oldUserName, user);
                }
            };
            Client.UsersInactive += users =>
            {
                Debug.Print("UsersInactive, Users: {0}", string.Join(", ", users.Select(r => r.Name)));
                foreach (var channel in Channels.OfType <JabbRChannel>())
                {
                    channel.TriggerActivityChanged(users);
                }
            };
            Client.UserTyping += (user, room) =>
            {
                Debug.Print("UserTyping, User: {0}, Room: {1}", user.Name, room);
            };
            Client.AddMessageContent += (messageId, content, room) =>
            {
                Debug.Print("AddMessageContent, Id: {0}, Room: {1}, Content: {2}", messageId, room, content);
                var channel = GetRoom(room);
                if (channel != null)
                {
                    channel.TriggerMessageContent(messageId, content);
                }
            };
            Client.StateChanged += status =>
            {
                Debug.Print("StateChange, Old State: {0}, New State: {1}", status.OldState, status.NewState);

                /*if (this.IsConnected && status.NewState == ConnectionState.Disconnected) {
                 *  OnDisconnected(EventArgs.Empty);
                 * }*/
            };
        }
예제 #3
0
 void HookupEvents()
 {
     Client.MessageReceived += (message, room) =>
     {
         Debug.Print("MessageReceived, Room: {3}, When: {0}, User: {1}, Content: {2}", message.When, message.User.Name, message.Content, room);
         var channel = GetRoom(room);
         if (channel != null)
         {
             channel.TriggerMessage(channel.CreateMessage(message));
             OnChannelInfoChanged(new ChannelEventArgs(channel));
         }
     };
     Client.Disconnected += () =>
     {
         Debug.Print("Disconnected");
         if (disconnectTask != null)
             disconnectTask.TrySetResult(null);
         if (timer != null)
         {
             timer.Dispose();
             timer = null;
         }
         OnDisconnected(EventArgs.Empty);
     };
     Client.FlagChanged += (user, flag) =>
     {
         Debug.Print("FlagChanged, User: {0}, Flag: {1}", user.Name, flag);
     };
     Client.GravatarChanged += (user, gravatar) =>
     {
         Debug.Print("GravatarChanged, User: {0}, Gravatar: {1}", user.Name, gravatar);
     };
     Client.Kicked += user =>
     {
         Debug.Print("Kicked: {0}", user);
     };
     Client.LoggedOut += rooms =>
     {
         Debug.Print("LoggedOut, Rooms: {0}", string.Join(", ", rooms));
     };
     Client.MeMessageReceived += (user, content, room) =>
     {
         Debug.Print("MeMessageReceived, User: {0}, Content: {1}, Room: {2}", user, content, room);
         var channel = GetRoom(room);
         if (channel != null)
             channel.TriggerMeMessage(user, content);
     };
     Client.NoteChanged += (user, room) =>
     {
         Debug.Print("NoteChanged, User: {0}, Room: {1}", user.Name, room);
     };
     Client.OwnerAdded += (user, room) =>
     {
         Debug.Print("OwnerAdded, User: {0}, Room: {1}", user.Name, room);
         var channel = GetRoom(room);
         if (channel != null)
             channel.TriggerOwnerAdded(user);
     };
     Client.OwnerRemoved += (user, room) =>
     {
         Debug.Print("OwnerRemoved, User: {0}, Room: {1}", user.Name, room);
         var channel = GetRoom(room);
         if (channel != null)
             channel.TriggerOwnerRemoved(user);
     };
     Client.PrivateMessage += (from, to, message) =>
     {
         Debug.Print("PrivateMessage, From: {0}, To: {1}, Message: {2} ", from, to, message);
         
         var user = from == CurrentUser.Name ? to : from;
         JabbRChat chat;
         if (InternalStartChat(new JabbRUser(this, user) { Active = true }, false, message, out chat))
         {
             chat.TriggerMessage(new ChannelMessage(Guid.NewGuid().ToString(), DateTimeOffset.Now, from, message));
             OnChannelInfoChanged(new ChannelEventArgs(chat));
         }
     };
     Client.RoomChanged += room =>
     {
         Debug.Print("RoomChanged, Room: {0}", room.Name);
     };
     Client.TopicChanged += (roomName, topic, who) =>
     {
         Debug.Print("TopicChanged, Room: {0}, Topic: {1}", roomName, topic);
         var channel = GetRoom(roomName);
         if (channel != null)
         {
             channel.SetNewTopic(topic, who);
         }
     };
     Client.UserActivityChanged += user =>
     {
         Debug.Print("UserActivityChanged, User: {0}, Activity: {1}", user.Name, user.Active);
         foreach (var channel in Channels.OfType<JabbRChannel>())
         {
             channel.TriggerActivityChanged(new [] { user });
         }
     };
     Client.JoinedRoom += async room =>
     {
         Debug.Print("JoinedRoom, Room: {0}", room.Name);
         var channel = GetRoom(room.Name);
         bool newChannel = channel == null;
         if (channel == null)
         {
             channel = new JabbRRoom(this, room);
         }
         OnOpenChannel(new OpenChannelEventArgs(channel, true, newChannel));
         if (newChannel)
             await channel.LoadRoomInfo();
     };
     Client.UserJoined += (user, room, isOwner) =>
     {
         Debug.Print("UserJoined, User: {0}, Room: {1}", user.Name, room);
         var channel = GetRoom(room);
         if (channel != null)
         {
             if (isOwner)
                 channel.TriggerOwnerAdded(user);
             channel.TriggerUserJoined(new UserEventArgs(new JabbRUser(this, user), DateTimeOffset.Now));
         }
     };
     Client.UserLeft += (user, room) =>
     {
         Debug.Print("UserLeft, User: {0}, Room: {1}", user.Name, room);
         var channel = GetRoom(room);
         if (channel != null)
         {
             if (user.Name == CurrentJabbRUser.Name)
             {
                 channel.TriggerClosed(EventArgs.Empty);
                 OnCloseChannel(new ChannelEventArgs(channel));
             }
             else
             {
                 channel.TriggerUserLeft(new UserEventArgs(new JabbRUser(this, user), DateTimeOffset.Now));
             }
         }
     };
     Client.UsernameChanged += (oldUserName, user, room) =>
     {
         Debug.Print("UsernameChanged, OldUserName: {0}, NewUserName: {1}, Room: {2}", oldUserName, user.Name, room);
         if (oldUserName == CurrentUser.Name)
         {
             // current user, so update all chat channels with new name as well
             CurrentUser.Name = user.Name;
             foreach (var chat in Channels.OfType<JabbRChat> ())
             {
                 chat.TriggerUsernameChanged(oldUserName, user, true);
             }
         }
         else
         {
             var chat = GetChat(oldUserName);
             if (chat != null)
             {
                 chat.TriggerUsernameChanged(oldUserName, user, false);
             }
         }
         
         var channel = GetRoom(room);
         if (channel != null)
         {
             channel.TriggerUsernameChanged(oldUserName, user);
         }
     };
     Client.UsersInactive += users =>
     {
         Debug.Print("UsersInactive, Users: {0}", string.Join(", ", users.Select(r => r.Name)));
         foreach (var channel in Channels.OfType<JabbRChannel>())
         {
             channel.TriggerActivityChanged(users);
         }
     };
     Client.UserTyping += (user, room) =>
     {
         Debug.Print("UserTyping, User: {0}, Room: {1}", user.Name, room);   
     };
     Client.AddMessageContent += (messageId, content, room) =>
     {
         Debug.Print("AddMessageContent, Id: {0}, Room: {1}, Content: {2}", messageId, room, content);
         var channel = GetRoom(room);
         if (channel != null)
             channel.TriggerMessageContent(messageId, content);
     };
     Client.StateChanged += status =>
     {
         Debug.Print("StateChange, Old State: {0}, New State: {1}", status.OldState, status.NewState);
         /*if (this.IsConnected && status.NewState == ConnectionState.Disconnected) {
             OnDisconnected(EventArgs.Empty);
         }*/
     };
 }
예제 #4
0
 public void MakeRoomLoadNext(JabbRRoom room)
 {
     // bump room to load next
     if (loadingRooms != null)
     {
         lock (loadingRooms)
         {
             if (loadingRooms.Contains(room))
             {
                 //Debug.WriteLine(string.Format("Bumping room from {0}", loadingRooms.IndexOf(room)));
                 loadingRooms.Remove(room);
                 loadingRooms.Insert(0, room);
             }
         }
     }
 }