Ejemplo n.º 1
0
        private void LoginResult(object e)
        {
            SocketMessage msg   = new SocketMessage(e);
            object        error = msg.GetValue("Error");

            if (error != null)
            {
                return;
            }
            object id     = msg.GetValue("ID");
            int    userID = -1;

            if (id != null)
            {
                userID = int.Parse(id.ToString());
            }
            CurrentUser = new UserInfo(
                userID,
                msg.GetValue("UserName")?.ToString(),
                msg.GetValue("RealName")?.ToString(),
                msg.GetValue("Description")?.ToString(),
                msg.GetValue("UserImage")?.ToString()
                );
            ClientSocket.Send("friendslist", new SocketMessage(new object[] { "UserName", CurrentUser.UserName }));
        }
Ejemplo n.º 2
0
        private void ClientSocket_OnMessagereceived(SocketMessage e)
        {
            string dataString = e.GetValue("DataType") == null ? "" : e.GetValue("DataType").ToString();

            Reply.ContentType dataType = (Reply.ContentType)Enum.Parse(typeof(Reply.ContentType), dataString);

            string[] urls = null;

            if (e.Data.ContainsKey("Links"))
            {
                urls = JsonConvert.DeserializeObject <string[]>(JsonConvert.SerializeObject(e.Data["Links"]));
            }

            MessageBlock block;

            if (dataType == Reply.ContentType.Picture && urls != null)
            {
                block = new MessageBlock(urls, e.GetValue("Message").ToString());
            }
            else
            {
                block = new MessageBlock();
            }

            string timeStamp = e.GetValue("TimeStamp").ToString();

            timeStamp = DateTime.Parse(timeStamp).ToString("h:mm tt");

            block.Message     = e.GetValue("Message").ToString();
            block.Sender      = e.GetValue("Sender").ToString();
            block.Date        = timeStamp;
            block.MaximumSize = new Size(((InnerChatContainer.Width - 20) / 2) - 20, int.MaxValue);

            Invoke(new MethodInvoker(() =>
            {
                block.FormatSize();

                InnerChatContainer.Controls.Add(block);

                SelectedChat.LastMessage = e.GetValue("Message").ToString();
                SelectedChat.TimeStamp   = timeStamp;
            }));

            if ((DateTime.Now - lastNotification).TotalSeconds > 5 && block.Sender != CurrentUser.UserName && !Activated)
            {
                lastNotification = DateTime.Now;
                NotificationSound.Play();
            }

            ResizeChat();
        }
Ejemplo n.º 3
0
        private void ClientSocket_SocketEvent(Components.SocketEvent e)
        {
            switch (e.Name.ToLower())
            {
            case "connected":
                if ((bool)e.Data)
                {
                    ClientSocket.RegisterModule("messenger");
                }
                break;

            case "moduleregistered":
                Invoke(new MethodInvoker(() =>
                {
                    LoginButton.Enabled = true;
                    LoginStatus.Text    = "Connection Successful!";
                }));
                break;

            case "login":
                LoginResult(e.Data);
                break;

            case "friendslist":
                FriendsListResult(e.Data);
                break;

            case "conversations":
                ConversationsResult(e.Data);
                break;

            case "typing":
                SocketMessage msg = new SocketMessage(e.Data);
                if (RecipientUser != null)
                {
                    RecipientUser.UserTyping = bool.Parse(msg.GetValue("typing").ToString());
                }
                break;
            }
        }