示例#1
0
        /**
         * <p>
         * processDiscuzMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processDiscuzMsg(JSONObject pollData)
        {
            QQStore store = getContext().getStore();

            QQMsg msg     = new QQMsg();
            long  fromUin = pollData.getLong("send_uin");
            long  did     = pollData.getLong("did");

            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.DISCUZ_MSG);
            msg.setDiscuz(store.getDiscuzByDid(did));
            msg.setTo(getContext().getAccount());
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));

            if (msg.getDiscuz() != null)
            {
                msg.setFrom(msg.getDiscuz().getMemberByUin(fromUin));
            }

            if (msg.getFrom() == null)
            {
                QQDiscuzMember member = new QQDiscuzMember();
                member.setUin(fromUin);
                msg.setFrom(member);
                if (msg.getDiscuz() != null)
                {
                    msg.getDiscuz().getMembers().Add(member);
                }
            }
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
示例#2
0
        /**
         * <p>
         * processBuddyMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processBuddyMsg(JSONObject pollData)
        {
            QQStore store = getContext().getStore();

            long  fromUin = pollData.getLong("from_uin");
            QQMsg msg     = new QQMsg();

            msg.setId(pollData.getLong("msg_id"));
            msg.setId2(pollData.getLong("msg_id2"));
            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.BUDDY_MSG);
            msg.setTo(getContext().getAccount());
            msg.setFrom(store.getBuddyByUin(fromUin));
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));
            if (msg.getFrom() == null)
            {
                QQUser member = store.getStrangerByUin(fromUin);         // 搜索陌生人列表
                if (member == null)
                {
                    member = new QQHalfStranger();
                    member.setUin(fromUin);
                    store.addStranger((QQStranger)member);
                }
                msg.setFrom(member);
            }
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
示例#3
0
        /**
         * <p>
         * processSessionMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processSessionMsg(JSONObject pollData)
        {
            // {"retcode"in0,"result"in[{"poll_type"in"sess_message",
            // "value"in{"msg_id"in25144,"from_uin"in167017143,"to_uin"in1070772010,"msg_id2"in139233,"msg_type"in140,"reply_ip"in176752037,"time"in1365931836,"id"in2581801127,"ruin"in444674479,"service_type"in1,
            // "flags"in{"text"in1,"pic"in1,"file"in1,"audio"in1,"video"in1},"content"in[["font",{"size"in9,"color"in"000000","style"in[0,0,0],"name"in"Tahoma"}],"2\u8F7D3 ",["face",1]," "]}}]}
            QQStore store = getContext().getStore();

            QQMsg msg         = new QQMsg();
            long  fromUin     = pollData.getLong("from_uin");
            long  fromQQ      = pollData.getLong("ruin");        // 真实QQ
            int   serviceType = pollData.getInt("service_type"); // Groupin0,Discussin1
            long  typeId      = pollData.getLong("id");          // Group ID or Discuss ID

            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.SESSION_MSG);
            msg.setTo(getContext().getAccount());
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));

            QQUser user = store.getBuddyByUin(fromUin);     // 首先看看是不是自己的好友

            if (user != null)
            {
                msg.setType(QQMsg.Type.BUDDY_MSG);         // 是自己的好友
            }
            else
            {
                if (serviceType == 0)           // 是群成员
                {
                    QQGroup group = store.getGroupByCode(typeId);
                    foreach (QQUser u in group.getMembers())
                    {
                        if (u.getUin() == fromUin)
                        {
                            user = u;
                            break;
                        }
                    }
                }
                else if (serviceType == 1)             // 是讨论组成员
                {
                    QQDiscuz discuz = store.getDiscuzByDid(typeId);
                    foreach (QQUser u in discuz.getMembers())
                    {
                        if (u.getUin() == fromUin)
                        {
                            user = u;
                            break;
                        }
                    }
                }
                else
                {
                    user = store.getStrangerByUin(fromUin); // 看看陌生人列表中有木有
                }
                if (user == null)                           // 还没有就新建一个陌生人,原理来说不应该这样。后面我就不知道怎么回复这消息了,但是消息是不能丢失的
                {
                    user = new QQStranger();
                    user.setQQ(pollData.getLong("ruin"));
                    user.setUin(fromUin);
                    user.setNickname(pollData.getLong("ruin") + "");
                    store.addStranger((QQStranger)user);
                }
            }
            user.setQQ(fromQQ);     // 带上QQ号码
            msg.setFrom(user);
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
示例#4
0
        /**
         * <p>
         * processGroupMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processGroupMsg(JSONObject pollData)
        {
            // {"retcode"in0,"result"in[{"poll_type"in"group_message",
            // "value"in{"msg_id"in6175,"from_uin"in3924684389,"to_uin"in1070772010,"msg_id2"in992858,"msg_type"in43,"reply_ip"in176621921,
            // "group_code"in3439321257,"send_uin"in1843694270,"seq"in875,"time"in1365934781,"info_seq"in170125666,"content"in[["font",{"size"in10,"color"in"3b3b3b","style"in[0,0,0],"name"in"\u5FAE\u8F6F\u96C5\u9ED1"}],"eeeeeeeee "]}}]}
            QQStore store = getContext().getStore();
            QQMsg   msg   = new QQMsg();

            msg.setId(pollData.getLong("msg_id"));
            msg.setId2(pollData.getLong("msg_id2"));
            int     msgType   = pollData.getInt("msg_type");
            long    gin       = pollData.getLong("from_uin");
            long    fromUin   = pollData.getLong("send_uin");
            long    groupCode = pollData.getLong("group_code");
            QQGroup group     = store.getGroupByCode(groupCode);
            long    groupID   = -1;

            if (group == null)
            {
                group = new QQGroup();
                group.setGin(gin);
                group.setCode(groupCode);
                // put to store
                store.addGroup(group);
            }
            switch (msgType)
            {
            case 32: {
                // 魔法、超级、涂鸦表情
                groupID = pollData.getLong("t_gcode");         // 真实群号码
                break;
            }

            case 43:
                // 一般消息
                groupID = pollData.getLong("info_seq");         // 真实群号码


                msg.parseContentList(pollData.getJSONArray("content").ToString());
                msg.setType(QQMsg.Type.GROUP_MSG);
                msg.setDate(new DateTime(pollData.getLong("time") * 1000));
                break;

            default:
                break;
            }
            if (group.getGid() <= 0)
            {
                group.setGid(groupID);
            }
            msg.setGroup(group);
            if (group != null)
            {
                msg.setFrom(group.getMemberByUin(fromUin));
            }
            msg.setTo(getContext().getAccount());
            if (msg.getFrom() == null)
            {
                QQGroupMember member = new QQGroupMember();
                member.setUin(fromUin);
                msg.setFrom(member);
                if (group != null)
                {
                    group.getMembers().Add(member);
                }
            }

            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }