Exemplo n.º 1
0
        void client_VCard(object sender, XmppVCartEventArgs e)
        {
            if (e == null || e.VCard == null)
            {
                return;
            }
            if (!string.IsNullOrWhiteSpace(e.VCard.PhotoBinVal))
            {
                string data = Base64Utils.Decode(e.VCard.PhotoBinVal, System.Text.Encoding.Default);
                string hash = Avatar.ComputeHash(data);
                if (!Avatar.Exist(hash))
                {
                    Avatar.Save(hash, data);
                    Dispatcher.BeginInvoke(new Action(() => {
                        RosterItem ri = RosterMgr.Get(e.VCard.Jid);
                        if (ri == null)
                        {
                            return;
                        }

                        ri.RefreshPresence();
                        Chat ci = ChatMgr.Get(e.VCard.Jid, null);
                        if (ci != null)
                        {
                            ci.RefreshPresence();
                        }
                    }), DispatcherPriority.Normal);
                }

                if (e.VCard.Jid != null)
                {
                    if (string.IsNullOrWhiteSpace(e.VCard.Jid.Bare) || e.VCard.Jid.Bare == client.Jid.Bare)
                    {
                        UpdateAvatar(hash);
                    }
                }
            }

            UpdateVCard(e.VCard);
        }
Exemplo n.º 2
0
        void client_Roster(object sender, XmppRosterEventArgs e)
        {
            if (e.Type != XmppIqType.Result)
            {
                return;
            }

            Log("roster received");
            bool flagRosterRecv = RosterMgr.Count() > 0;

            /*for (int i = 0; i < 1000; i++) {
             *      XmppRosterItem item = new XmppRosterItem(i.ToString() + "@test.com", "", "", "");
             *      e.Roster.Add(item);
             * }*/

            Parallel.ForEach(e.Roster, item => {
                Dispatcher.BeginInvoke(new Action(() => {
                    if ((item.Subscription == "none" || item.Subscription == "from") && item.Ask != "subscribe" && string.IsNullOrWhiteSpace(item.Name))
                    {
                        return;
                    }

                    RosterItem ri = new RosterItem(client, item, UserSetting.RosterVwrMode);
                    RosterMgr.Update(item.Jid, ri);
                }), DispatcherPriority.Normal);
            });

            Dispatcher.BeginInvoke(new Action(() => {
                lstRoster.ItemsSource = RosterMgr.UpdateRosterView();

                if (flagRosterRecv == false)
                {
                    this.FadeIn(panelRoster.Name, TimeSpan.FromMilliseconds(500));
                }

                panelConnect.Visibility = Visibility.Hidden;
                panelRoster.Visibility  = Visibility.Visible;
                Log(string.Format("roster now contain {0} contacts", RosterMgr.Count()));
            }), DispatcherPriority.Normal);
        }