public void RemovePresence(Presence p, PresenceManager handler)
            {
                JID    from = p.From;
                string res  = from.Resource;

                Debug.Assert(p.Type == PresenceType.unavailable);

                gen.LinkedListNode <Presence> n = Find(res);

                // unavail for a resource we haven't gotten presence from.
                if (n == null)
                {
                    return;
                }

                gen.LinkedListNode <Presence> last = m_all.Last;
                m_all.Remove(n);

                if (last == n)
                {
                    // current high-pri.
                    if ((m_all.Last != null) && (m_all.Last.Value.IntPriority >= 0))
                    {
                        Primary(m_all.Last.Value, handler);
                    }
                    else
                    {
                        // last non-negative presence went away
                        if (n.Value.IntPriority >= 0)
                        {
                            Primary(null, handler);
                        }
                    }
                }
            }
            public void AddPresence(Presence p, PresenceManager handler)
            {
                JID    from = p.From;
                string res  = from.Resource;

                Debug.Assert(p.Type == PresenceType.available);

                // If this is an update, remove the existing one.
                // we'll add the new one back in, in the correct place.
                gen.LinkedListNode <Presence> n = Find(res);
                if (n != null)
                {
                    m_all.Remove(n);
                }


                gen.LinkedListNode <Presence> inserted = new gen.LinkedListNode <Presence>(p);
                for (n = m_all.First; n != null; n = n.Next)
                {
                    if (p < n.Value)
                    {
                        m_all.AddBefore(n, inserted);
                        break;
                    }
                }

                // This is the highest one.
                if (inserted.List == null)
                {
                    m_all.AddLast(inserted);
                    if (p.IntPriority >= 0)
                    {
                        Primary(p, handler);
                    }
                }
            }
 private void Primary(Presence p, PresenceManager handler)
 {
     Debug.Assert((p == null) ? true : (p.IntPriority >= 0), "Primary presence is always positive priority");
     handler.FireOnPrimarySessionChange(m_jid);
 }