Example #1
0
        public ListContact(string jid, MetroFramework.MetroColorStyle style)
        {
            this.Style = style;
            InitializeComponent();
            int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;

            this.Width    -= vertScrollWidth;
            this.BackColor = Helper.GetMetroThemeColor(style);
            this.contact   = ContactStore.GetContactByJid(jid);
            if (this.contact != null)
            {
                this.lblName.Text = this.contact.FullName;
                string imgpath = ChatWindow.getCacheImagePath(jid);
                if (File.Exists(imgpath))
                {
                    try
                    {
                        Image  i = Image.FromFile(imgpath);
                        Bitmap b = new Bitmap(i, new Size(48, 48));
                        this.pictureBox1.Image = b;
                        i.Dispose();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
Example #2
0
        void ProcessChat()
        {
            this.Text = ContactStore.GetContactByJid(this.target).FullName;
            WappSocket.Instance.SendQueryLastOnline(this.target);
            WappSocket.Instance.SendPresenceSubscriptionRequest(this.target);

            //load image
            string filepath = getCacheImagePath(this.target);

            if (File.Exists(filepath))
            {
                try
                {
                    Image img = Image.FromFile(filepath);
                    this.pictureBox1.Image = img;
                }
                catch (Exception)
                {
                    GetImageAsync(this.target, false);
                }
            }
            else
            {
                GetImageAsync(this.target, false);
            }
        }
Example #3
0
        public ChatWindow(string target, bool stealFocus, bool onTop)
        {
            this.stealFocus = stealFocus;
            this.onTop      = onTop;
            this.TopMost    = onTop;
            if (stealFocus)
            {
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.WindowState = FormWindowState.Minimized;
            }
            if (target.Contains("-"))
            {
                this.IsGroup = true;
            }
            this.target = target;
            InitializeComponent();

            try
            {
                string path = Directory.GetCurrentDirectory() + "\\notify.wav";
                path    = new System.IO.FileInfo(path).FullName;
                this.sp = new SoundPlayer(path);
                this.sp.Load();
            }
            catch (Exception)
            {
                this.sp = null;
            }

            Contact con = ContactStore.GetContactByJid(target);

            if (con == null)
            {
                con = new Contact(-1, target, "", "", "", "");
                ContactStore.AddContact(con);
            }

            this.lblNick.Text       = con.nickname;
            this.lblUserStatus.Text = con.status;
            this.SetUnavailable();

            if (this.IsGroup)
            {
                this.ProcessGroupChat();
            }
            else
            {
                this.ProcessChat();
            }

            WappMessage[] oldmessages = MessageStore.GetAllMessagesForContact(target);
            this.messages.AddRange(oldmessages);

            this.limitMessages();
            //this.redraw();
        }
Example #4
0
        private void updateNick(string jid, string nick)
        {
            Contact c = ContactStore.GetContactByJid(jid);

            if (c != null)
            {
                c.nickname = nick;
                ContactStore.UpdateNickname(c);
            }
        }
Example #5
0
        public ListChat(WappMessage msg, MetroFramework.MetroColorStyle style)
        {
            InitializeComponent();
            this.Style                = style;
            this.metroTile1.Style     = style;
            this.metroTile1.BackColor = Helper.GetMetroThemeColor(style);
            if (msg.from_me)
            {
                this.Padding = new Padding(50, this.Padding.Top, 4, this.Padding.Bottom);
            }
            if (!String.IsNullOrEmpty(msg.author))
            {
                Contact c = ContactStore.GetContactByJid(msg.author);
                if (c != null)
                {
                    msg.author = c.FullName;
                }
                msg.data = String.Format("{0}\r\n{1}", msg.author, msg.data);
            }
            if (msg.type == "image")
            {
                if (!string.IsNullOrEmpty(msg.preview))
                {
                    MemoryStream ms = new MemoryStream(Convert.FromBase64String(msg.preview));
                    Image        i  = Image.FromStream(ms);
                    this.Height += i.Height;
                    this.Controls.Remove(this.metroTile1);
                    PictureBox pb = new PictureBox();
                    pb.Width  = i.Width;
                    pb.Height = i.Height;
                    pb.Image  = i;
                    this.Controls.Add(pb);
                }
            }
            else
            {
                Font  f          = MetroFonts.Tile(this.metroTile1.TileTextFontSize, this.metroTile1.TileTextFontWeight);
                int   lineHeight = Int32.Parse(Math.Round((decimal)this.metroTile1.CreateGraphics().MeasureString("X", f).Height).ToString());
                SizeF sf         = new SizeF();
                sf = this.metroTile1.CreateGraphics().MeasureString(msg.data, f, this.metroTile1.Width);
                this.metroTile1.Text = msg.data;
                int newHeight = (int)Math.Round(decimal.Parse(sf.Height.ToString()));
                int lines     = newHeight / f.Height;
                //lines--;

                if (lines > 0)
                {
                    this.Height = (lines * this.Height);
                }
            }
        }
Example #6
0
        void Instance_OnGetPhotoPreview(string from, string id, byte[] data)
        {
            Contact c = ContactStore.GetContactByJid(from);

            if (c != null)
            {
                Image img = null;
                using (var ms = new MemoryStream(data))
                {
                    try
                    {
                        img = Image.FromStream(ms);
                        string targetdir = Directory.GetCurrentDirectory() + "\\data\\profilecache";
                        if (!Directory.Exists(targetdir))
                        {
                            Directory.CreateDirectory(targetdir);
                        }
                        img.Save(targetdir + "\\" + c.jid + ".jpg");
                        try
                        {
                            if (this.getChat(from, false, false) != null)
                            {
                                this.getChat(from, false, false).SetPicture(img);
                            }
                        }
                        catch (Exception e)
                        {
                            throw e;
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
            if (picturesToSync.Remove(from))
            {
                this.requestProfilePicture();
            }
        }
Example #7
0
        protected void _loadConversations()
        {
            if (this.InvokeRequired)
            {
                remoteDelegate r = new remoteDelegate(_loadConversations);
                this.Invoke(r);
            }
            else
            {
                this.flowLayoutPanel1.Controls.Clear();
                DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
                using (DbConnection cnn = fact.CreateConnection())
                {
                    cnn.ConnectionString = MessageStore.ConnectionString;
                    cnn.Open();
                    DbCommand cmd = cnn.CreateCommand();
                    cmd             = cnn.CreateCommand();
                    cmd.CommandText = "SELECT jid FROM Messages GROUP BY jid";
                    DbDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        string  jid     = reader["jid"].ToString();
                        Contact contact = ContactStore.GetContactByJid(jid);
                        if (contact != null)
                        {
                            this.contacts.Add(contact);

                            //add to richtextbox
                            ListContact c = new ListContact(contact.jid);
                            c.DoubleClick += this.contact_dblClick;
                            this.flowLayoutPanel1.Controls.Add(c);
                        }
                    }
                }

                //done
                this.label1.Hide();
            }
        }
Example #8
0
 public ListChat(WappMessage msg)
 {
     InitializeComponent();
     this.textBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;
     if (!msg.from_me)
     {
         this.textBox1.Location = new Point(3, this.textBox1.Location.Y);
     }
     if (!String.IsNullOrEmpty(msg.author))
     {
         Contact c = ContactStore.GetContactByJid(msg.author);
         if (c != null)
         {
             msg.author = c.FullName;
         }
         msg.data = String.Format("{0}\r\n{1}", msg.author, msg.data);
     }
     if (msg.type == "image")
     {
         if (!string.IsNullOrEmpty(msg.preview))
         {
             MemoryStream ms = new MemoryStream(Convert.FromBase64String(msg.preview));
             Image        i  = Image.FromStream(ms);
             this.Height += i.Height;
             this.Controls.Remove(this.textBox1);
             PictureBox pb = new PictureBox();
             pb.Width  = i.Width;
             pb.Height = i.Height;
             pb.Image  = i;
             this.Controls.Add(pb);
         }
     }
     else
     {
         this.textBox1.Text = msg.data;
         Size size = TextRenderer.MeasureText(this.textBox1.Text, this.textBox1.Font, new Size(this.textBox1.Width, int.MaxValue), TextFormatFlags.WordBreak);
         this.Height = size.Height + 15;
     }
 }
Example #9
0
 void ProcessGroupChat()
 {
     this.Text = "Group chat " + ContactStore.GetContactByJid(this.target).ToString();
     WappSocket.Instance.SendGetGroupInfo(this.target);
 }
Example #10
0
        protected void ProcessMessages(ProtocolTreeNode[] nodes)
        {
            foreach (ProtocolTreeNode node in nodes)
            {
                if (node.tag.Equals("message"))
                {
                    ProtocolTreeNode body         = node.GetChild("body");
                    ProtocolTreeNode media        = node.GetChild("media");
                    ProtocolTreeNode paused       = node.GetChild("paused");
                    ProtocolTreeNode composing    = node.GetChild("composing");
                    ProtocolTreeNode notification = node.GetChild("notification");
                    string           jid          = node.GetAttribute("from");

                    if (body != null || media != null)
                    {
                        //extract and save nickname
                        if (node.GetChild("notify") != null && node.GetChild("notify").GetAttribute("name") != null)
                        {
                            string  nick = node.GetChild("notify").GetAttribute("name");
                            Contact c    = ContactStore.GetContactByJid(jid);
                            if (c != null)
                            {
                                c.nickname = nick;
                                ContactStore.UpdateNickname(c);
                            }
                        }

                        try
                        {
                            this.getChat(jid, true, false).AddMessage(node);
                        }
                        catch (Exception)
                        { }

                        //refresh list
                        this._loadConversations();
                    }
                    if (paused != null)
                    {
                        try
                        {
                            if (this.getChat(jid, false, false) != null)
                            {
                                this.getChat(jid, false, false).SetOnline();
                            }
                        }
                        catch (Exception e)
                        {
                            //throw e;
                        }
                    }
                    if (composing != null)
                    {
                        try
                        {
                            if (this.getChat(jid, false, false) != null)
                            {
                                this.getChat(jid, false, false).SetTyping();
                            }
                        }
                        catch (Exception e)
                        {
                            //throw e;
                        }
                    }
                    if (notification != null)
                    {
                        if (notification.GetAttribute("type") == "picture")
                        {
                            ChatWindow.GetImageAsync(notification.GetChild("set").GetAttribute("jid"), false);
                        }
                    }
                }
                else if (node.tag.Equals("presence"))
                {
                    string jid = node.GetAttribute("from");
                    if (node.GetAttribute("type") != null && node.GetAttribute("type").Equals("available"))
                    {
                        try
                        {
                            if (this.getChat(jid, false, false) != null)
                            {
                                this.getChat(jid, false, false).SetOnline();
                            }
                        }
                        catch (Exception e)
                        {
                            //throw e;
                        }
                    }
                    if (node.GetAttribute("type") != null && node.GetAttribute("type").Equals("unavailable"))
                    {
                        try
                        {
                            if (this.getChat(jid, false, false) != null)
                            {
                                this.getChat(jid, false, false).SetUnavailable();
                            }
                        }
                        catch (Exception e)
                        {
                            //throw e;
                        }
                    }
                }
                else if (node.tag.Equals("iq"))
                {
                    string jid = node.GetAttribute("from");

                    if (node.children.First().tag.Equals("query"))
                    {
                        DateTime lastseen = DateTime.Now;
                        int      seconds  = Int32.Parse(node.GetChild("query").GetAttribute("seconds"));
                        lastseen = lastseen.Subtract(new TimeSpan(0, 0, seconds));
                        try
                        {
                            if (this.getChat(jid, false, false) != null)
                            {
                                getChat(jid, false, false).SetLastSeen(lastseen);
                            }
                        }
                        catch (Exception e)
                        {
                            //throw e;
                        }
                    }
                    else if (node.children.First().tag.Equals("group"))
                    {
                        string  subject = node.children.First().GetAttribute("subject");
                        Contact cont    = ContactStore.GetContactByJid(jid);
                        if (cont != null)
                        {
                            cont.nickname = subject;
                            ContactStore.UpdateNickname(cont);
                        }
                        else
                        {
                        }
                    }
                    else if (node.children.First().tag.Equals("picture"))
                    {
                        string  pjid       = node.GetAttribute("from");
                        string  id         = node.GetAttribute("id");
                        byte[]  rawpicture = node.GetChild("picture").GetData();
                        Contact c          = ContactStore.GetContactByJid(pjid);
                        if (c != null)
                        {
                            Image img = null;
                            using (var ms = new MemoryStream(rawpicture))
                            {
                                try
                                {
                                    img = Image.FromStream(ms);
                                    string targetdir = Directory.GetCurrentDirectory() + "\\data\\profilecache";
                                    if (!Directory.Exists(targetdir))
                                    {
                                        Directory.CreateDirectory(targetdir);
                                    }
                                    img.Save(targetdir + "\\" + c.jid + ".jpg");
                                    try
                                    {
                                        if (this.getChat(pjid, false, false) != null)
                                        {
                                            this.getChat(pjid, false, false).SetPicture(img);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        throw e;
                                    }
                                }
                                catch (Exception e)
                                {
                                    throw e;
                                }
                            }
                        }
                        if (picturesToSync.Remove(pjid))
                        {
                            this.requestProfilePicture();
                        }
                    }
                    else if (node.children.First().tag.Equals("error") && node.children.First().GetAttribute("code") == "404")
                    {
                        string pjid = node.GetAttribute("from");
                        picturesToSync.Remove(pjid);
                        this.requestProfilePicture();
                    }
                }
            }
        }