Пример #1
0
    //获取好友消息
    void GetMessage()
    {
        string to_id = Request["to_id"];

        if (string.IsNullOrEmpty(to_id))
        {
            return;
        }

        CMessageMgr     MessageMgr = Global.GetCtx(Session["TopCompany"].ToString()).MessageMgr;
        List <CMessage> lst        = MessageMgr.Find(new Guid(to_id), m_User.Id);

        lst.Sort();
        string sData = "";

        for (int i = lst.Count - 1; i >= 0; i--)
        {
            CMessage msg = lst[i];
            if (!msg.IsNew)
            {
                break;
            }
            sData = msg.Content + "<br>" + sData;
            //更新消息状态
            msg.IsNew = false;
            MessageMgr.Update(msg);
        }
        Response.Write(sData);

        MessageMgr.Save(true);
    }
Пример #2
0
    //获取好友状态及消息数
    public void GetFriendState()
    {
        CMessageMgr        MessageMgr = Global.GetCtx(Session["TopCompany"].ToString()).MessageMgr;
        string             sData      = "";
        List <CBaseObject> lstObj     = m_User.FriendMgr.GetList();
        bool bHasNewMsg = false;

        foreach (CBaseObject obj in lstObj)
        {
            CFriend Friend = (CFriend)obj;

            string sRow = "";
            sRow += string.Format("\"id\":\"{0}\",", Friend.Id);
            sRow += string.Format("\"Friend_id\":\"{0}\",", Friend.Friend_id);
            CUser UF = (CUser)Global.GetCtx(Session["TopCompany"].ToString()).UserMgr.Find(Friend.Friend_id);
            if (UF == null)
            {
                continue;
            }
            string sIcon  = string.Format("<img src='../images/{0}' width='16' height='16'/>&nbsp;&nbsp;", UF.IsOnline()?"on.png":"off.png");
            string sCount = "";
            int    iCount = MessageMgr.GetNewCount(UF.Id, m_User.Id);
            if (iCount > 0)
            {
                bHasNewMsg = true;
                sCount     = string.Format("({0})", iCount);
            }
            sRow += string.Format("\"Friend\":\"{0}{1}{2}\",", sIcon, UF.Name, sCount);
            sRow += string.Format("\"group\":\"{0}\",", Friend.IsStrange?"陌生人":"我的好友");

            sRow   = "{" + sRow + "},";
            sData += sRow;
        }
        sData = sData.TrimEnd(",".ToCharArray());
        sData = "[" + sData + "]";
        string sJson = string.Format("{{\"Rows\":{0},\"Total\":\"{1}\",\"HasNewMsg\":\"{2}\"}}"
                                     , sData, lstObj.Count, bHasNewMsg?"1":"0");

        Response.Write(sJson);
    }
Пример #3
0
    //发送消息
    void Send()
    {
        string sMsg = Request["msg"];

        if (string.IsNullOrEmpty(sMsg))
        {
            return;
        }
        //消息处理
        sMsg = sMsg.Replace("\n", "<br>");
        string sHead = "<span style='color:Blue'>" + m_User.Name + " " + DateTime.Now.ToString() + "</span><br>";

        sMsg = sHead + sMsg;

        CMessage msg = new CMessage();

        msg.Ctx      = Global.GetCtx(Session["TopCompany"].ToString());
        msg.Content  = sMsg;
        msg.Sender   = m_User.Id;
        msg.Receiver = m_FriendUser.Id;

        CMessageMgr MessageMgr = Global.GetCtx(Session["TopCompany"].ToString()).MessageMgr;

        if (!MessageMgr.AddNew(msg, true))
        {
        }
        //如果发送者不在接收者的好友里,则添加到接收者的陌生人里
        if (m_FriendUser.FriendMgr.FindByFriendId(m_User.Id) == null)
        {
            CFriend Friend = new CFriend();
            Friend.Ctx       = Global.GetCtx(Session["TopCompany"].ToString());
            Friend.B_User_id = m_FriendUser.Id;
            Friend.Friend_id = m_User.Id;
            Friend.IsStrange = true;

            m_FriendUser.FriendMgr.AddNew(Friend, true);
        }
    }