Esempio n. 1
0
        public TwitterSearchStream(TwitterProtocolManager protocolManager,
                                   GroupChatModel chat, string keyword,
                                   OAuthTokens tokens, WebProxy proxy)
        {
            if (protocolManager == null) {
                throw new ArgumentNullException("protocolManager");
            }
            if (chat == null) {
                throw new ArgumentNullException("chat");
            }
            if (keyword == null) {
                throw new ArgumentNullException("keyword");
            }
            if (tokens == null) {
                throw new ArgumentNullException("tokens");
            }

            ProtocolManager = protocolManager;
            Session = protocolManager.Session;
            Chat = chat;

            var options = new StreamOptions();
            options.Track.Add(keyword);

            Stream = new TwitterStream(tokens, null, options);
            Stream.Proxy = proxy;
            Stream.StartPublicStream(OnStreamStopped, OnStatusCreated, OnStatusDeleted, OnEvent);

            MessageRateLimiter = new RateLimiter(5, TimeSpan.FromSeconds(5));
        }
Esempio n. 2
0
 public CampfireEventStream(GroupChatModel chat, Uri baseuri, NetworkCredential cred)
 {
     this.Chat = chat;
     this.Cred = cred;
     this.Host = Host;
     this.BaseUri = baseuri;
     this.LastMessage = 0;
 }
Esempio n. 3
0
        public IrcGroupChatView(GroupChatModel groupChat)
            : base(groupChat)
        {
            Trace.Call(groupChat);

            if (PersonTreeView != null) {
                Gtk.CellRendererText cellr = new Gtk.CellRendererText();
                // HACK: for some reason GTK is giving the space of 2 chars which
                // we workaround using a char width of 0
                cellr.WidthChars = 0;
                Gtk.TreeViewColumn column = new Gtk.TreeViewColumn(String.Empty, cellr);
                column.Spacing = 0;
                column.SortIndicator = false;
                column.Sizing = Gtk.TreeViewColumnSizing.GrowOnly;
                column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(_RenderIrcGroupPersonMode));

                PersonTreeView.AppendColumn(column);
                PersonTreeView.MoveColumnAfter(IdentityNameColumn, column);
            }
        }
Esempio n. 4
0
        public void IsFilteredMessage()
        {
            var chat = new GroupChatModel("testchat", "Test Chat", Protocol);
            Assert.IsFalse(Session.IsFilteredMessage(chat, "foobar", MessageType.Normal));

            var filters = new List<FilterModel>(Session.Filters);
            filters.Add(
                new FilterModel() {
                    NetworkID = "TESTnet",
                    MessagePattern = "/^filter me$/"
                }
            );
            filters.Add(
                new FilterModel() {
                    NetworkID = "OTHERnet"
                }
            );
            Session.Filters = filters;
            Assert.IsTrue(Session.IsFilteredMessage(chat, "filter me", MessageType.Normal));
            Assert.IsFalse(Session.IsFilteredMessage(chat, "do not filter me", MessageType.Normal));
        }
Esempio n. 5
0
 public override IList<GroupChatModel> FindGroupChats(GroupChatModel filter)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
        public override IList<GroupChatModel> FindGroupChats(GroupChatModel filter)
        {
            Trace.Call(filter);

            RefreshRooms();
            string searchPattern = null;
            if (filter == null || String.IsNullOrEmpty(filter.Name)) {
                // full channel list
            } else {
                if (!filter.Name.StartsWith("*") && !filter.Name.EndsWith("*")) {
                    searchPattern = String.Format("*{0}*", filter.Name);
                } else {
                    searchPattern = filter.Name;
                }
            }

            List<GroupChatModel> chats = new List<GroupChatModel>(Rooms.Count());
            IEnumerable<Room> matching;

            matching = searchPattern == null ? Rooms :
                Rooms.Where(r => Pattern.IsMatch(r.Name, searchPattern));

            foreach (var room in matching) {
                GroupChatModel chat = new GroupChatModel(room.Id.ToString(), room.Name, null);
                var users = Client.Get<RoomResponse>(String.Format("/room/{0}.json", chat.ID)).Room.Users;

                /* Don't waste this data */
                lock (Users) {
                    foreach (var user in users) {
                        if (!Users.ContainsKey(user.Id))
                            Users[user.Id] = CreatePerson(user);
                    }
                }

                chat.PersonCount = users.Length;

                chat.Topic = CreateMessageBuilder().AppendMessage(room.Topic).ToMessage();
                lock (chat) {
                    chats.Add(chat);
                }
            }

            return chats;
        }
Esempio n. 7
0
        public void CommandJoin(CommandModel cmd)
        {
            Trace.Call(cmd);

            RefreshRooms();

            /*
             * cmd.DataArray is split at SP, but that's an allowed character
             * for Campfire. Instead of relying on that, we need to remove the "/join "
             * part and then split on ','
             */
            var chans = cmd.Parameter.Split(',');
            var list = Rooms.Where(r => chans.Any(r.Name.Equals));

            foreach(Room room in list) {
                var chat = new GroupChatModel(room.Id.ToString(), room.Name, null);
                OpenChat(cmd.FrontendManager, chat);
            }
        }
Esempio n. 8
0
        public override IList<GroupChatModel> FindGroupChats(GroupChatModel filter)
        {
            Trace.Call(filter);

            var list = new List<GroupChatModel>();
            if (ContactChat == null) {
                list.Add(new GroupChatModel("Contacts", "Contacts", this));
            }
            return list;
        }
Esempio n. 9
0
        public void UpdatePersonInGroupChat(GroupChatModel groupChat, PersonModel oldPerson, PersonModel newPerson)
        {
            Trace.Call(groupChat, oldPerson, newPerson);

            try {
                var chatView = _ChatViewManager.GetChat(groupChat);
                if (chatView == null) {
            #if LOG4NET
                    _Logger.Fatal(String.Format("UpdatePersonInGroupChat(): _ChatViewManager.GetChat(groupChat) groupChat.Name: {0} returned null!", groupChat.Name));
            #endif
                    return;
                }

                lock (chatView.Participants) {
                    chatView.Participants.Remove(oldPerson);
                    chatView.Participants.Add(newPerson);
                }
            } catch (Exception ex) {
            #if LOG4NET
                _Logger.Fatal(ex);
            #endif
            }
        }
Esempio n. 10
0
 private void _RemovePersonFromGroupChat(GroupChatModel groupChat, PersonModel person)
 {
     f_TaskQueue.Queue(delegate {
         _UI.RemovePersonFromGroupChat(groupChat, person);
     });
 }
Esempio n. 11
0
        public IrcGroupChatView(GroupChatModel groupChat)
            : base(groupChat)
        {
            Trace.Call(groupChat);

            //_IrcGroupChatModel = ircGroupChat;
            _IrcProtocolManager = (IrcProtocolManager) groupChat.ProtocolManager;

            if (PersonMenu != null) {
                Gtk.ImageMenuItem op_item = new Gtk.ImageMenuItem(_("Op"));
                op_item.Activated += new EventHandler(_OnUserListMenuOpActivated);
                PersonMenu.Append(op_item);

                Gtk.ImageMenuItem deop_item = new Gtk.ImageMenuItem(_("Deop"));
                deop_item.Activated += new EventHandler(_OnUserListMenuDeopActivated);
                PersonMenu.Append(deop_item);

                Gtk.ImageMenuItem voice_item = new Gtk.ImageMenuItem(_("Voice"));
                voice_item.Activated += new EventHandler(_OnUserListMenuVoiceActivated);
                PersonMenu.Append(voice_item);

                Gtk.ImageMenuItem devoice_item = new Gtk.ImageMenuItem(_("Devoice"));
                devoice_item.Activated += new EventHandler(_OnUserListMenuDevoiceActivated);
                PersonMenu.Append(devoice_item);

                Gtk.ImageMenuItem kick_item = new Gtk.ImageMenuItem(_("Kick"));
                kick_item.Activated += new EventHandler(_OnUserListMenuKickActivated);
                PersonMenu.Append(kick_item);

                Gtk.ImageMenuItem kickban_item = new Gtk.ImageMenuItem(_("Kick + Ban"));
                kickban_item.Activated += new EventHandler(_OnUserListMenuKickBanActivated);
                PersonMenu.Append(kickban_item);

                Gtk.ImageMenuItem ban_item = new Gtk.ImageMenuItem(_("Ban"));
                ban_item.Activated += new EventHandler(_OnUserListMenuBanActivated);
                PersonMenu.Append(ban_item);

                Gtk.ImageMenuItem unban_item = new Gtk.ImageMenuItem(_("Unban"));
                unban_item.Activated += new EventHandler(_OnUserListMenuUnbanActivated);
                PersonMenu.Append(unban_item);

                PersonMenu.Append(new Gtk.SeparatorMenuItem());

                Gtk.ImageMenuItem query_item = new Gtk.ImageMenuItem(_("Query"));
                query_item.Activated += new EventHandler(_OnUserListMenuQueryActivated);
                PersonMenu.Append(query_item);

                Gtk.ImageMenuItem whois_item = new Gtk.ImageMenuItem(_("Whois"));
                whois_item.Activated += _OnUserListMenuWhoisActivated;
                PersonMenu.Append(whois_item);
            }

            if (PersonTreeView != null) {
                Gtk.CellRendererText cellr = new Gtk.CellRendererText();
                cellr.WidthChars = 1;
                Gtk.TreeViewColumn column = new Gtk.TreeViewColumn(String.Empty, cellr);
                column.Spacing = 0;
                column.SortIndicator = false;
                column.Sizing = Gtk.TreeViewColumnSizing.GrowOnly;
                column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(_RenderIrcGroupPersonMode));

                PersonTreeView.AppendColumn(column);
                PersonTreeView.MoveColumnAfter(IdentityNameColumn, column);
            }
        }
Esempio n. 12
0
        public void UpdatePersonInGroupChat(GroupChatModel groupChat, PersonModel oldPerson, PersonModel newPerson)
        {
            TraceRemotingCall(groupChat, oldPerson, newPerson);

            MethodBase mb = Trace.GetMethodBase();
            Gtk.Application.Invoke(delegate {
                TraceRemotingCall(mb, groupChat, oldPerson, newPerson);

                try {
                    GroupChatView groupChatView = (GroupChatView) _ChatViewManager.GetChat(groupChat);
                    if (groupChatView == null) {
            #if LOG4NET
                        _Logger.Fatal(
                            String.Format(
                                "UpdatePersonInGroupChat(): " +
                                "_ChatViewManager.GetChat(groupChat) " +
                                "groupChat.Name: {0} returned null!",
                                groupChat.Name
                            )
                        );
            #endif
                        return;
                    }
                    groupChatView.UpdatePerson(oldPerson, newPerson);
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            });
        }
Esempio n. 13
0
 public abstract IList <GroupChatModel> FindGroupChats(GroupChatModel filter);
Esempio n. 14
0
        void OnLoggedOn(IEnumerable <Room> rooms)
        {
            Trace.Call(rooms);

            try {
                foreach (var room in rooms)
                {
                    var  groupChat = (GroupChatModel)GetChat(room.Name, ChatType.Group);
                    bool newChat;
                    if (groupChat == null)
                    {
                        groupChat = new GroupChatModel(room.Name, room.Name, this);
                        groupChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile);
                        newChat = true;
                    }
                    else
                    {
                        groupChat.UnsafePersons.Clear();
                        newChat = false;
                    }

                    var task = Client.GetRoomInfo(room.Name);
                    task.Wait();
                    // check task.Exception
                    var roomInfo = task.Result;
                    groupChat.Topic = CreateMessageBuilder <JabbrMessageBuilder>().
                                      AppendMessage(roomInfo.Topic).
                                      ToMessage();
                    foreach (var user in roomInfo.Users)
                    {
                        groupChat.UnsafePersons.Add(user.Name,
                                                    CreatePerson(user));
                    }
                    // add ourself if needed
                    if (!groupChat.UnsafePersons.ContainsKey(Username))
                    {
                        groupChat.UnsafePersons.Add(Username, Me);
                    }
                    foreach (var msg in roomInfo.RecentMessages)
                    {
                        AddMessage(groupChat, msg);
                    }
                    if (newChat)
                    {
                        Session.AddChat(groupChat);
                    }
                    else
                    {
                        Session.EnableChat(groupChat);
                    }
                    Session.SyncChat(groupChat);
                }
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error(ex);
#endif
                var msg = CreateMessageBuilder().
                          AppendEventPrefix().
                          AppendErrorText(_("Retrieving chat information failed. " +
                                            "Reason: {0}"),
                                          ex.Message).
                          ToMessage();
                Session.AddMessageToChat(ProtocolChat, msg);
            }
        }
Esempio n. 15
0
 public MessageReceivedEventArgs(GroupChatModel chat, Message message)
 {
     Chat    = chat;
     Message = message;
 }
Esempio n. 16
0
 private void _UpdatePersonInGroupChat(GroupChatModel groupChat, PersonModel oldPerson, PersonModel newPerson)
 {
     f_TaskQueue.Queue(delegate {
         _UI.UpdatePersonInGroupChat(groupChat, oldPerson, newPerson);
     });
 }
Esempio n. 17
0
        public override void Connect(FrontendManager fm, ServerModel server)
        {
            Trace.Call(fm, server);

            Network = server.Hostname.Substring(0, server.Hostname.IndexOf('.'));
            Host    = server.Hostname;
            BaseUri = new Uri(String.Format("https://{0}", Host));

            NetworkChat = new ProtocolChatModel(Network, "Campfire " + Network, this);
            NetworkChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile);
            NetworkChat.ApplyConfig(Session.UserConfig);
            Session.AddChat(NetworkChat);
            Session.SyncChat(NetworkChat);
            var msg = _("Connecting to campfire... ");

            if (fm != null)
            {
                fm.SetStatus(msg);
            }
            var bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg);

            Session.AddMessageToChat(NetworkChat, bld.ToMessage());

            if (!server.ValidateServerCertificate)
            {
                var whitelist = Session.CertificateValidator.HostnameWhitelist;
                lock (whitelist) {
                    // needed for favicon
                    if (!whitelist.Contains("campfirenow.com"))
                    {
                        whitelist.Add("campfirenow.com");
                    }
                    // needed for receiving messages
                    if (!whitelist.Contains("streaming.campfirenow.com"))
                    {
                        whitelist.Add("streaming.campfirenow.com");
                    }
                    if (!whitelist.Contains(Host))
                    {
                        whitelist.Add(Host);
                    }
                }
            }

            Client = new JsonServiceClient(BaseUri.AbsoluteUri);
            var creds = new NetworkCredential(server.Username, server.Password);

            Client.Credentials = creds;

            try {
                var me = Client.Get <UserResponse>("/users/me.json").User;
                Key = me.Api_Auth_Token;
                Me  = CreatePerson(me);
                // The blue color is hardcoded for now
                Me.IdentityNameColored.ForegroundColor = new TextColor(0x0000FF);
                Me.IdentityNameColored.BackgroundColor = TextColor.None;
                Me.IdentityNameColored.Bold            = true;
            } catch (Exception e) {
                FailedToConnect("Failed to connect to Campfire", e);
                return;
            }

            Client.Credentials = new NetworkCredential(Key, "X");
            msg = _("Connected to campfire");
            if (fm != null)
            {
                fm.SetStatus(msg);
            }
            bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg);
            Session.AddMessageToChat(NetworkChat, bld.ToMessage());

            // Campfire lets us know what channels the user is currently in, so
            // connect to those rooms automatically
            Rooms        = Client.Get <RoomsResponse>("/rooms.json").Rooms;
            RoomsUpdated = DateTime.Now;

            var myrooms = Client.Get <RoomsResponse>("/presence.json").Rooms;

            if (myrooms.Length > 0)
            {
                bld = CreateMessageBuilder().
                      AppendEventPrefix().
                      AppendText("Present in {0}",
                                 String.Join(", ", myrooms.Select(r => r.Name).ToArray())
                                 );
                Session.AddMessageToChat(NetworkChat, bld.ToMessage());
            }

            foreach (var room in myrooms)
            {
                var chat = new GroupChatModel(room.Id.ToString(), room.Name, null);
                OpenChat(fm, chat);
            }
        }
Esempio n. 18
0
 private void _AddPersonToGroupChat(GroupChatModel groupChat, PersonModel person)
 {
     f_TaskQueue.Queue(delegate {
         _UI.AddPersonToGroupChat(groupChat, person);
     });
 }
Esempio n. 19
0
        public void RemovePersonFromGroupChat(GroupChatModel groupChat, PersonModel person)
        {
            TraceRemotingCall(groupChat, person);

            MethodBase mb = Trace.GetMethodBase();
            _Dispatcher.Invoke(DispatcherPriority.Normal,new MethodInvoker(delegate {
                TraceRemotingCall(mb, groupChat, person);

                GroupChatView groupChatView = (GroupChatView) _ChatViewManager.GetChat(groupChat);
                groupChatView.RemovePerson(person);
            }));
        }
Esempio n. 20
0
 public void AddPersonToGroupChat(GroupChatModel cpage, PersonModel user)
 {
     Trace.Call(cpage, user);
 }
Esempio n. 21
0
        public void UpdateTopicInGroupChat(GroupChatModel ecpage, string topic)
        {
            TraceRemotingCall(ecpage, topic);

            MethodBase mb = Trace.GetMethodBase();
            _Dispatcher.Invoke(DispatcherPriority.Normal,new MethodInvoker(delegate {
                TraceRemotingCall(mb, ecpage, topic);

                /*
                GroupChatView cpage = (GroupChatView)Frontend.MainWindow.Notebook.GetChat(ecpage);
                if (cpage.TopicEntry != null) {
                    cpage.TopicEntry.Text = topic;
                }
                */
            }));
        }
Esempio n. 22
0
        public GroupChatView(GroupChatModel groupChat)
            : base(groupChat)
        {
            Trace.Call(groupChat);

            _GroupChatModel = groupChat;

            // person list
            _OutputHPaned = new Gtk.HPaned();

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            _PersonScrolledWindow = sw;
            //sw.WidthRequest = 150;
            sw.HscrollbarPolicy = Gtk.PolicyType.Never;

            Gtk.TreeView tv = new Gtk.TreeView();
            _PersonTreeView = tv;
            //tv.CanFocus = false;
            tv.BorderWidth = 0;
            tv.Selection.Mode = Gtk.SelectionMode.Multiple;
            sw.Add(tv);

            Gtk.TreeViewColumn column;
            Gtk.CellRendererText cellr = new Gtk.CellRendererText();
            cellr.WidthChars = 12;
            column = new Gtk.TreeViewColumn(String.Empty, cellr);
            column.SortColumnId = 0;
            column.Spacing = 0;
            column.SortIndicator = false;
            column.Sizing = Gtk.TreeViewColumnSizing.Autosize;
            column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName));
            tv.AppendColumn(column);
            _IdentityNameColumn = column;

            Gtk.ListStore liststore = new Gtk.ListStore(typeof(PersonModel));
            liststore.SetSortColumnId(0, Gtk.SortType.Ascending);
            liststore.SetSortFunc(0, new Gtk.TreeIterCompareFunc(SortPersonListStore));
            _PersonListStore = liststore;

            tv.Model = liststore;
            tv.RowActivated += new Gtk.RowActivatedHandler(OnPersonsRowActivated);
            tv.FocusOutEvent += OnPersonTreeViewFocusOutEvent;

            // popup menu
            _PersonMenu = new Gtk.Menu();
            // don't loose the focus else we lose the selection too!
            // see OnPersonTreeViewFocusOutEvent()
            _PersonMenu.TakeFocus = false;
            _PersonMenu.Shown += OnPersonMenuShown;

            _PersonTreeView.ButtonPressEvent += _OnPersonTreeViewButtonPressEvent;
            _PersonTreeView.KeyPressEvent += OnPersonTreeViewKeyPressEvent;
            // frame needed for events when selecting something in the treeview
            _PersonTreeViewFrame = new Gtk.Frame();
            _PersonTreeViewFrame.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(_OnUserListButtonReleaseEvent);
            _PersonTreeViewFrame.Add(sw);

            // topic
            // don't worry, ApplyConfig() will add us to the OutputVBox!
            _OutputVBox = new Gtk.VBox();

            _TopicTextView = new MessageTextView();
            _TopicTextView.Editable = false;
            _TopicTextView.WrapMode = Gtk.WrapMode.WordChar;
            _TopicScrolledWindow = new Gtk.ScrolledWindow();
            _TopicScrolledWindow.ShadowType = Gtk.ShadowType.In;
            // when using PolicyType.Never, it will try to grow but never shrinks!
            _TopicScrolledWindow.HscrollbarPolicy = Gtk.PolicyType.Automatic;
            _TopicScrolledWindow.VscrollbarPolicy = Gtk.PolicyType.Automatic;
            _TopicScrolledWindow.Add(_TopicTextView);
            // make sure the topic is invisible and remains by default and
            // visible when a topic gets set
            _TopicScrolledWindow.ShowAll();
            _TopicScrolledWindow.Visible = false;
            _TopicScrolledWindow.NoShowAll = true;
            _TopicScrolledWindow.SizeRequested += delegate(object o, Gtk.SizeRequestedArgs args) {
                // predict and set useful topic heigth
                Pango.Layout layout = _TopicTextView.CreatePangoLayout("Test Topic");
                int lineWidth, lineHeigth;
                layout.GetPixelSize(out lineWidth, out lineHeigth);
                var lineSpacing = _TopicTextView.PixelsAboveLines +
                                  _TopicTextView.PixelsBelowLines;
                var text = Topic != null ? Topic.ToString() : String.Empty;
                // hardcoded to 2 lines for now
                var newLines = text.Length > 0 ? 2 : 0;
                var bestSize = new Gtk.Requisition() {
                    Height = ((lineHeigth + lineSpacing) * newLines) + 2
                };
                args.Requisition = bestSize;
            };

            Add(_OutputHPaned);

            //ApplyConfig(Frontend.UserConfig);

            ShowAll();
        }
Esempio n. 23
0
 private void _UpdateTopicInGroupChat(GroupChatModel groupChat, MessageModel topic)
 {
     f_TaskQueue.Queue(delegate {
         _UI.UpdateTopicInGroupChat(groupChat, topic);
     });
 }
Esempio n. 24
0
        public void UpdateTopicInGroupChat(GroupChatModel groupChat, MessageModel topic)
        {
            TraceRemotingCall(groupChat, topic);

            MethodBase mb = Trace.GetMethodBase();
            Gtk.Application.Invoke(delegate {
                TraceRemotingCall(mb, groupChat, topic);

                try {
                    GroupChatView groupChatView = (GroupChatView)Frontend.MainWindow.Notebook.GetChat(groupChat);
                    if (groupChatView == null) {
            #if LOG4NET
                        _Logger.Fatal(
                            String.Format(
                                "UpdateTopicInGroupChat(): " +
                                "_ChatViewManager.GetChat(groupChat) " +
                                "groupChat.Name: {0} returned null!",
                                groupChat.Name
                            )
                        );
            #endif
                        return;
                    }
                    groupChatView.Topic = topic;
                } catch (Exception ex) {
                    Frontend.ShowException(ex);
                }
            });
        }
Esempio n. 25
0
 private void _UpdatePersonInGroupChat(GroupChatModel groupChat, PersonModel oldPerson, PersonModel newPerson)
 {
     f_TaskQueue.Queue(delegate {
         _UI.UpdatePersonInGroupChat(groupChat, oldPerson, newPerson);
     });
 }
Esempio n. 26
0
        public void UpdatePersonInGroupChat(GroupChatModel groupChat, PersonModel oldPerson, PersonModel newPerson)
        {
            TraceRemotingCall(groupChat, oldPerson, newPerson);

            MethodBase mb = Trace.GetMethodBase();
            _Dispatcher.Invoke(DispatcherPriority.Normal,new MethodInvoker(delegate {
                TraceRemotingCall(mb, groupChat, oldPerson, newPerson);

                GroupChatView groupChatView = (GroupChatView) _ChatViewManager.GetChat(groupChat);
                groupChatView.UpdatePerson(oldPerson, newPerson);
            }));
        }
Esempio n. 27
0
 private void _UpdateTopicInGroupChat(GroupChatModel groupChat, MessageModel topic)
 {
     f_TaskQueue.Queue(delegate {
         _UI.UpdateTopicInGroupChat(groupChat, topic);
     });
 }
Esempio n. 28
0
        public void AddPersonToGroupChat(GroupChatModel groupChat, PersonModel person)
        {
            Trace.Call(groupChat, person);

            try {
                var chatView = _ChatViewManager.GetChat(groupChat);
                if (chatView == null) {
            #if LOG4NET
                    _Logger.Fatal(String.Format("AddPersonToGroupChat(): _ChatViewManager.GetChat(chat) chat.Name: {0} returned null!", groupChat.Name));
            #endif
                    return;
                }

                lock (chatView.Participants) {
                    chatView.Participants.Add(person);
                }
            } catch (Exception ex) {
            #if LOG4NET
                _Logger.Fatal(ex);
            #endif
            }
        }
Esempio n. 29
0
        protected virtual void OnFindButtonClicked(object sender, System.EventArgs e)
        {
            Trace.Call(sender, e);

            try {
                string nameFilter = f_NameEntry.Text.Trim();
                if (String.IsNullOrEmpty(nameFilter)) {
                    Gtk.MessageDialog md = new Gtk.MessageDialog(
                        this,
                        Gtk.DialogFlags.Modal,
                        Gtk.MessageType.Warning,
                        Gtk.ButtonsType.YesNo,
                        _("Searching for group chats without a filter is not " +
                          "recommended.  This may take a while, or may not " +
                          "work at all.\n" +
                          "Do you wish to continue?")
                    );
                    int result = md.Run();
                    md.Destroy();
                    if (result != (int) Gtk.ResponseType.Yes) {
                        return;
                    }
                }

                f_ListStore.Clear();
                CancelFindThread();

                GroupChatModel filter =  new GroupChatModel(null, nameFilter, null);
                f_FindThread = new Thread(new ThreadStart(delegate {
                    try {
                        Gtk.Application.Invoke(delegate {
                            GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);
                        });

                        IList<GroupChatModel> chats = f_ProtocolManager.FindGroupChats(filter);

                        Gtk.Application.Invoke(delegate {
                            Gdk.Color bgColor = f_TreeView.Style.Background(Gtk.StateType.Normal);
                            foreach (GroupChatModel chat in chats) {
                                f_ListStore.AppendValues(
                                    chat,
                                    chat.PersonCount,
                                    chat.Name,
                                    PangoTools.ToMarkup(chat.Topic, bgColor)
                                );
                            }
                        });
                    } catch (ThreadAbortException ex) {
            #if LOG4NET
                        f_Logger.Debug("FindThread aborted");
            #endif
                        Thread.ResetAbort();
                    } catch (Exception ex) {
                        Frontend.ShowError(this, _("Error while fetching the list of group chats from the server."), ex);
                    } finally {
                        Gtk.Application.Invoke(delegate {
                            // if the dialog is gone the GdkWindow might be destroyed already
                            if (GdkWindow != null) {
                                GdkWindow.Cursor = null;
                            }
                        });
                    }
                }));
                f_FindThread.IsBackground = true;
                f_FindThread.Start();
            } catch (Exception ex) {
                Frontend.ShowException(ex);
            }
        }
Esempio n. 30
0
        public void UpdateTopicInGroupChat(GroupChatModel groupChat, MessageModel topic)
        {
            Trace.Call(groupChat, topic);

            try {
                var chatView = _ChatViewManager.GetChat(groupChat);
                if (chatView == null) {
            #if LOG4NET
                    _Logger.Fatal(String.Format("UpdateTopicInGroupChat(): _ChatViewManager.GetChat(groupChat) groupChat.Name: {0} returned null!", groupChat.Name));
            #endif
                    return;
                }

                if (!(chatView is GroupChatView)) {
            #if LOG4NET
                    _Logger.Fatal(String.Format("UpdateTopicInGroupChat(): _ChatViewManager.GetChat(groupChat) groupChat.Name: {0} returned something that isn't a group chat view!", groupChat.Name));
            #endif
                    return;
                }

                var groupChatView = (GroupChatView) chatView;

                groupChatView.Topic = topic;

                _ChatViewManager.UpdateTopic();
            } catch (Exception ex) {
            #if LOG4NET
                _Logger.Fatal(ex);
            #endif
            }
        }
Esempio n. 31
0
        protected override void OnResponse(Gtk.ResponseType responseType)
        {
            Trace.Call(responseType);

            switch (responseType) {
                case Gtk.ResponseType.Ok:
                    f_GroupChatModel = GetCurrentGroupChat();
                    break;
                case Gtk.ResponseType.Cancel:
                    CancelFindThread();
                    break;
            }

            base.OnResponse(responseType);
        }
Esempio n. 32
0
        public GroupChatView(GroupChatModel groupChat)
            : base(groupChat)
        {
            Trace.Call(groupChat);

            _GroupChatModel = groupChat;

            // person list
            Participants = new List<PersonModel>();
            _OutputHPaned = new Gtk.HPaned();

            Gtk.TreeView tv = new Gtk.TreeView();
            _PersonTreeView = tv;
            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            PersonScrolledWindow = sw;
            sw.ShadowType = Gtk.ShadowType.None;
            sw.HscrollbarPolicy = Gtk.PolicyType.Never;

            //tv.CanFocus = false;
            tv.BorderWidth = 0;
            tv.Selection.Mode = Gtk.SelectionMode.Multiple;
            sw.Add(tv);

            Gtk.TreeViewColumn column;
            var cellr = new Gtk.CellRendererText() {
                Ellipsize = Pango.EllipsizeMode.End
            };
            IdentityNameCellRenderer = cellr;
            column = new Gtk.TreeViewColumn(String.Empty, cellr);
            column.SortColumnId = 0;
            column.Spacing = 0;
            column.SortIndicator = false;
            column.Expand = true;
            column.Sizing = Gtk.TreeViewColumnSizing.Autosize;
            // FIXME: this callback leaks memory
            column.SetCellDataFunc(cellr, new Gtk.TreeCellDataFunc(RenderPersonIdentityName));
            tv.AppendColumn(column);
            _IdentityNameColumn = column;

            Gtk.ListStore liststore = new Gtk.ListStore(typeof(PersonModel));
            liststore.SetSortColumnId(0, Gtk.SortType.Ascending);
            liststore.SetSortFunc(0, new Gtk.TreeIterCompareFunc(SortPersonListStore));
            _PersonListStore = liststore;

            tv.Model = liststore;
            tv.SearchColumn = 0;
            tv.SearchEqualFunc = (model, col, key, iter) => {
                var person = (PersonModel) model.GetValue(iter, col);
                // Ladies and gentlemen welcome to C
                // 0 means it matched but 0 as bool is false. So if it matches
                // we have to return false. Still not clear? true is false and
                // false is true, weirdo! If you think this is retarded,
                // yes it is.
                return !person.IdentityName.StartsWith(key, StringComparison.InvariantCultureIgnoreCase);
            };
            tv.EnableSearch = true;
            tv.HeadersVisible = false;
            tv.RowActivated += new Gtk.RowActivatedHandler(OnPersonsRowActivated);
            tv.FocusOutEvent += OnPersonTreeViewFocusOutEvent;

            // popup menu
            _PersonMenu = new Gtk.Menu();
            // don't loose the focus else we lose the selection too!
            // see OnPersonTreeViewFocusOutEvent()
            _PersonMenu.TakeFocus = false;
            _PersonMenu.Shown += OnPersonMenuShown;

            _PersonTreeView.ButtonPressEvent += _OnPersonTreeViewButtonPressEvent;
            _PersonTreeView.KeyPressEvent += OnPersonTreeViewKeyPressEvent;
            // frame needed for events when selecting something in the treeview
            _PersonTreeViewFrame = new Gtk.Frame() {
                ShadowType = Gtk.ShadowType.In
            };
            _PersonTreeViewFrame.ButtonReleaseEvent += new Gtk.ButtonReleaseEventHandler(_OnUserListButtonReleaseEvent);
            _PersonTreeViewFrame.Add(sw);

            // topic
            // don't worry, ApplyConfig() will add us to the OutputVBox!
            _OutputVBox = new Gtk.VBox() {
                Spacing = 1
            };

            _TopicTextView = new MessageTextView();
            _TopicTextView.Editable = false;
            _TopicTextView.WrapMode = Gtk.WrapMode.WordChar;
            _TopicScrolledWindow = new Gtk.ScrolledWindow();
            _TopicScrolledWindow.ShadowType = Gtk.ShadowType.In;
            _TopicScrolledWindow.HscrollbarPolicy = Gtk.PolicyType.Never;
            _TopicScrolledWindow.Add(_TopicTextView);
            // make sure the topic is invisible and remains by default and
            // visible when a topic gets set
            _TopicScrolledWindow.ShowAll();
            _TopicScrolledWindow.Visible = false;
            _TopicScrolledWindow.NoShowAll = true;
            _TopicScrolledWindow.SizeRequested += delegate(object o, Gtk.SizeRequestedArgs args) {
                // predict and set useful topic heigth
                int lineWidth, lineHeight;
                using (var layout = _TopicTextView.CreatePangoLayout("Test Topic")) {
                    layout.GetPixelSize(out lineWidth, out lineHeight);
                }
                var lineSpacing = _TopicTextView.PixelsAboveLines +
                                  _TopicTextView.PixelsBelowLines;
                var it = _TopicTextView.Buffer.StartIter;
                int newLines = 1;
                // move to end of next visual line
                while (_TopicTextView.ForwardDisplayLineEnd(ref it)) {
                    newLines++;
                    // calling ForwardDisplayLineEnd repeatedly stays on the same position
                    // therefor we move one cursor position further
                    it.ForwardCursorPosition();
                }
                newLines = Math.Min(newLines, 3);
                var bestSize = new Gtk.Requisition() {
                    Height = ((lineHeight + lineSpacing) * newLines) + 4
                };
                args.Requisition = bestSize;
            };

            Add(_OutputHPaned);

            //ApplyConfig(Frontend.UserConfig);

            ShowAll();
        }
Esempio n. 33
0
 public void RemovePersonFromGroupChat(GroupChatModel cpage, PersonModel user)
 {
     Trace.Call(cpage, user);
 }
Esempio n. 34
0
        public override void Connect(FrontendManager fm, ServerModel server)
        {
            Trace.Call(fm, server);

            Network = server.Hostname.Substring(0, server.Hostname.IndexOf('.'));
            Host = server.Hostname;
            BaseUri = new Uri(String.Format("https://{0}", Host));

            NetworkChat = new ProtocolChatModel(Network, "Campfire " + Network, this);
            NetworkChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile);
            NetworkChat.ApplyConfig(Session.UserConfig);
            Session.AddChat(NetworkChat);
            Session.SyncChat(NetworkChat);
            var msg = _("Connecting to campfire... ");
            if (fm != null) {
                fm.SetStatus(msg);
            }
            var bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg);
            Session.AddMessageToChat(NetworkChat, bld.ToMessage());

            if (!server.ValidateServerCertificate) {
                var whitelist = Session.CertificateValidator.HostnameWhitelist;
                lock (whitelist) {
                    // needed for favicon
                    if (!whitelist.Contains("campfirenow.com")) {
                        whitelist.Add("campfirenow.com");
                    }
                    // needed for receiving messages
                    if (!whitelist.Contains("streaming.campfirenow.com")) {
                        whitelist.Add("streaming.campfirenow.com");
                    }
                    if (!whitelist.Contains(Host)) {
                        whitelist.Add(Host);
                    }
                }
            }

            Client = new JsonServiceClient(BaseUri.AbsoluteUri);
            var creds = new NetworkCredential(server.Username, server.Password);
            Client.Credentials = creds;

            try {
                var me = Client.Get<UserResponse>("/users/me.json").User;
                Key = me.Api_Auth_Token;
                Me = CreatePerson(me);
                // The blue color is hardcoded for now
                Me.IdentityNameColored.ForegroundColor = new TextColor(0x0000FF);
                Me.IdentityNameColored.BackgroundColor = TextColor.None;
                Me.IdentityNameColored.Bold = true;

            } catch (Exception e) {
                FailedToConnect("Failed to connect to Campfire", e);
                return;
            }

            Client.Credentials = new NetworkCredential(Key, "X");
            msg = _("Connected to campfire");
            if (fm != null) {
                fm.SetStatus(msg);
            }
            bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg);
            Session.AddMessageToChat(NetworkChat, bld.ToMessage());

            // Campfire lets us know what channels the user is currently in, so
            // connect to those rooms automatically
            Rooms = Client.Get<RoomsResponse>("/rooms.json").Rooms;
            RoomsUpdated = DateTime.Now;

            var myrooms = Client.Get<RoomsResponse>("/presence.json").Rooms;
            if (myrooms.Length > 0) {
                bld = CreateMessageBuilder().
                    AppendEventPrefix().
                    AppendText("Present in {0}",
                        String.Join(", ", myrooms.Select(r => r.Name).ToArray())
                    );
                Session.AddMessageToChat(NetworkChat, bld.ToMessage());
            }

            foreach (var room in myrooms) {
                var chat = new GroupChatModel(room.Id.ToString(), room.Name, null);
                OpenChat(fm, chat);
            }
        }
Esempio n. 35
0
 public void UpdatePersonInGroupChat(GroupChatModel cpage, PersonModel olduser, PersonModel newuser)
 {
     Trace.Call(cpage, olduser, newuser);
 }
Esempio n. 36
0
        void SendMessage(GroupChatModel chat, string text)
        {
            var message = new MessageSending { body = text, type = Campfire.MessageType.TextMessage};
            var wrapper = new MessageWrapper { message = message };
            Message res;
            try {
                res = Client.Post<MessageResponse>(String.Format("/room/{0}/speak.json", chat.ID), wrapper).Message;
            } catch (WebServiceException e) {
                var bld = CreateMessageBuilder();
                bld.AppendErrorText(_("Failed to post message: {0}"), e.Message);
                Session.AddMessageToChat(NetworkChat, bld.ToMessage());
                return;
            }

            ShowMessage(this, new MessageReceivedEventArgs(chat, res));
            LastSentId = res.Id;
        }
Esempio n. 37
0
        public void UpdateTopicInGroupChat(GroupChatModel cpage, string topic)
        {
            Trace.Call(cpage, topic);

            Console.WriteLine("Topic changed to: "+topic+ " on "+cpage.Name);
        }
Esempio n. 38
0
        public static bool TryOpenChatLink(Uri link)
        {
            Trace.Call(link);

            if (Session == null) {
                return false;
            }

            // supported:
            // smuxi://freenode/#smuxi
            // smuxi://freenode/#%23csharp (##csharp)
            // irc://#smuxi
            // irc://irc.oftc.net/
            // irc://irc.oftc.net/#smuxi
            // irc://irc.oftc.net:6667/#smuxi
            // not supported (yet):
            // smuxi:///meebey

            IProtocolManager manager = null;
            var linkPort = link.Port;
            if (linkPort == -1) {
                switch (link.Scheme) {
                    case "irc":
                        linkPort = 6667;
                        break;
                    case "ircs":
                        linkPort = 6697;
                        break;
                }
            }
            // decode #%23csharp to ##csharp
            var linkChat = HttpUtility.UrlDecode(link.Fragment);
            if (String.IsNullOrEmpty(linkChat) && link.AbsolutePath.Length > 0) {
                linkChat = link.AbsolutePath.Substring(1);
            }

            var linkProtocol = link.Scheme;
            var linkHost = link.Host;
            string linkNetwork = null;
            if (!linkHost.Contains(".")) {
                // this seems to be a network name
                linkNetwork = linkHost;
            }

            // find existing protocol chat
            foreach (var chatView in MainWindow.ChatViewManager.Chats) {
                if (!(chatView is ProtocolChatView)) {
                    continue;
                }
                var protocolChat = (ProtocolChatView) chatView;
                var host = protocolChat.Host;
                var port = protocolChat.Port;
                var network = protocolChat.NetworkID;
                // Check first by network name with fallback to host+port.
                // The network name has to be checked against the NetworkID and
                // also ChatModel.ID as the user might have entered a different
                // network name in settings than the server does
                if (!String.IsNullOrEmpty(network) &&
                    (String.Compare(network, linkNetwork, true) == 0 ||
                     String.Compare(chatView.ID, linkNetwork, true) == 0)) {
                    manager = protocolChat.ProtocolManager;
                    break;
                }
                if (String.Compare(host, linkHost, true) == 0 &&
                    port == linkPort) {
                    manager = protocolChat.ProtocolManager;
                    break;
                }
            }

            if (manager == null) {
                // only irc may autoconnect to a server
                switch (linkProtocol) {
                    case "irc":
                    case "ircs":
                    case "smuxi":
                        break;
                    default:
                        return false;
                }
                ServerModel server = null;
                if (!String.IsNullOrEmpty(linkNetwork)) {
                    // try to find a server with this network name and connect to it
                    var serverSettings = new ServerListController(UserConfig);
                    server = serverSettings.GetServerByNetwork(linkNetwork);
                    if (server == null) {
                        // in case someone tried an unknown network
                        return false;
                    }
                    // ignore OnConnectCommands
                    server.OnConnectCommands = null;
                } else if (!String.IsNullOrEmpty(linkHost)) {
                    server = new ServerModel() {
                        Protocol = linkProtocol,
                        Hostname = linkHost,
                        Port = linkPort
                    };
                }
                if (server != null) {
                    manager = Session.Connect(server, FrontendManager);
                }
            }

            if (String.IsNullOrEmpty(linkChat)) {
                return true;
            }

            // switch to existing chat
            foreach (var chatView in MainWindow.ChatViewManager.Chats) {
                if (manager != null && chatView.ProtocolManager != manager) {
                    continue;
                }
                if (String.Compare(chatView.ID, linkChat, true) == 0) {
                    MainWindow.ChatViewManager.CurrentChatView = chatView;
                    return true;
                }
            }

            // join chat
            if (manager != null) {
                var chat = new GroupChatModel(linkChat, linkChat, null);
                ThreadPool.QueueUserWorkItem(delegate {
                    try {
                        manager.OpenChat(FrontendManager, chat);
                    } catch (Exception ex) {
                        Frontend.ShowException(ex);
                    }
                });
            }
            return true;
        }
Esempio n. 39
0
        public override IList <GroupChatModel> FindGroupChats(GroupChatModel filter)
        {
            Trace.Call(filter);

            throw new NotImplementedException();
        }