Пример #1
0
 public void AddMessage(Message m)
 {
     if (messages.ContainsKey(m.GetChannel()))
     {
         messages[m.GetChannel()].Add(m);
     }
 }
Пример #2
0
        public DataRow MessageToDataRow(Message m)
        {
            DataRow dr = dtMessages.NewRow();

            dr["cbid"]    = m.GetID();
            dr["sender"]  = m.GetSender().GetUid();
            dr["message"] = m.GetMessage();
            dr["private"] = m.IsPrivate();
            dr["heure"]   = (m.GetTimestamp() / 1000);
            dr["channel"] = m.GetChannel();

            if (m.GetRecipient() != null)
            {
                dr["recipient"] = m.GetRecipient().GetUid();
            }

            return(dr);
        }
Пример #3
0
        public void LoadChatbox(bool initListeners = true)
        {
            RefreshInterface = true;
            socket           = IO.Socket(cb_address);

            socket.On(Socket.EVENT_CONNECT_ERROR, (oError) =>
            {
                Console.WriteLine("On : {0} {1}", "EVENT_CONNECT_ERROR", oError.ToString());
            });

            socket.On(Socket.EVENT_CONNECT_TIMEOUT, (oError) =>
            {
                Console.WriteLine("On : {0} {1}", "EVENT_CONNECT_TIMEOUT", oError.ToString());
            });

            socket.On(Socket.EVENT_ERROR, (oError) =>
            {
                Console.WriteLine("On : {0} : {1}", "EVENT_ERROR", oError.ToString());
            });

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                Console.WriteLine("On : {0}", "CONNECT");
                Console.WriteLine("Connected");

                if (SocketConnectionStateChanged != null)
                {
                    EventHandler <SocketConnectionEvent> handler = SocketConnectionStateChanged;
                    handler(this, new SocketConnectionEvent(true));
                }

                Console.WriteLine("Emit : {0} {1} {2}", "create", int.Parse(id), token);
                socket.Emit("create", new AckImpl((oReturn) =>
                {
                    Console.WriteLine("Recieved ack from creation");
                    socket.Emit("login");
                    JoinChannel("general");

                    Console.WriteLine(oReturn);
                }), int.Parse(id), token);
            });

            socket.On(Socket.EVENT_DISCONNECT, () =>
            {
                Console.WriteLine("On : {0}", "DISCONNECT");
                if (SocketConnectionStateChanged != null)
                {
                    EventHandler <SocketConnectionEvent> handler = SocketConnectionStateChanged;
                    handler(this, new SocketConnectionEvent(false));
                }
                Console.WriteLine("Disconnected");
            });

            if (initListeners)
            {
                socket.On("login", () =>
                {
                    Console.WriteLine("On : {0}", "login");
                    Console.WriteLine("Logged in");
                });

                socket.On("already-logged", () =>
                {
                    Console.WriteLine("On : {0}", "already-logged");
                    Console.WriteLine("Already logged in");
                });

                socket.On("login-success", () =>
                {
                    Console.WriteLine("On : {0}", "login-success");
                    Console.WriteLine("Logged in successfully");
                });

                socket.On("join-channel", (oChannel) =>
                {
                    Console.WriteLine("On : {0}", "join-channel");

                    Channel c = new Channel(oChannel);
                    this.channels.Add(c);

                    Console.WriteLine("Channel " + c.GetLabel() + " joined");

                    if (ChannelJoined != null)
                    {
                        EventHandler <ChannelJoinedEvent> handler = ChannelJoined;
                        handler(this, new ChannelJoinedEvent(c));
                    }


                    if (!messages.Keys.Contains(c.GetName()))
                    {
                        messages.Add(c.GetName(), new List <Message>());
                    }
                });

                socket.On("new-message", (oMessage) =>
                {
                    Console.WriteLine("On : {0}", "new-message");
                    Console.WriteLine("Message recieved");
                    Message m = new Message(oMessage);
                    AddMessage(m);

                    if (RefreshInterface)
                    {
                        if (MessageRecieved != null)
                        {
                            EventHandler <Message> handler = MessageRecieved;
                            handler(this, m);
                        }


                        if (parentForm != null)
                        {
                            object[] p = new object[] { m.GetChannel() };
                            callbackMessageInsert.Invoke(parentForm, p);
                        }
                    }
                });

                socket.On("channel-messages", (data) =>
                {
                    Console.WriteLine("On : {0}", "channel-messages");
                    //Console.WriteLine("Messages :");
                    //Console.WriteLine(data);
                });

                socket.On("refresh-new-channels", (aChannels) =>
                {
                    Console.WriteLine("On : {0}", "refresh-new-channels");
                    LoadChannelList(aChannels);
                });

                var myIListenerImplUsers = new ChannelMessageAckListener((iChannel, aUsers) =>
                {
                    Console.WriteLine("Recieved " + ((dynamic)aUsers).Count + " users from " + (string)iChannel);
                    //System.IO.File.WriteAllText(@"D:\report.txt", aUsers.ToString());
                });

                socket.On("refresh-channel-users", myIListenerImplUsers);

                var myIListenerImpl = new ChannelMessageAckListener((iChannel, aMessages) =>
                {
                    Console.WriteLine("Recieved " + ((dynamic)aMessages).Count + " older messages from " + (string)iChannel);
                    LoadMessages(aMessages, (string)iChannel);
                });

                socket.On("get-older-message", myIListenerImpl);
            }
        }