Package iqq.im.core

Examples of iqq.im.core.QQStore


  @Override
  protected void onHttpStatusOK(QQHttpResponse response) throws QQException,
      JSONException {
    JSONObject json = new JSONObject(response.getResponseString());
    List<Object> recents = new ArrayList<Object>();
    QQStore store = getContext().getStore();
        if (json.getInt("retcode") == 0) {
            JSONArray result = json.getJSONArray("result");
            for(int i=0; i<result.length(); i++){
               JSONObject rejson = result.getJSONObject(i);
               switch(rejson.getInt("type")){
               case 0://好友
                 QQBuddy buddy = store.getBuddyByUin(rejson.getLong("uin"));
                 if(buddy != null){
                   recents.add(buddy);
                 }
               } break;
              
               case 1: //群
                 QQGroup group = store.getGroupByCode(rejson.getLong("uin"));
                 if(group != null){
                   recents.add(group);
                 }
               } break;
              
               case 2: //讨论组
                 QQDiscuz discuz = store.getDiscuzByDid(rejson.getLong("uin"));
                 if(discuz != null){
                   recents.add(discuz);
                 }
               }
               }
View Full Code Here


  /** {@inheritDoc} */
  @Override
  protected void onHttpStatusOK(QQHttpResponse response) throws QQException,
      JSONException {
    JSONObject json = new JSONObject(response.getResponseString());
    QQStore store = getContext().getStore();
    if (json.getInt("retcode") == 0) {
      JSONArray result = json.getJSONArray("result");
      for (int i = 0; i < result.length(); i++) {
        JSONObject obj = result.getJSONObject(i);
        long uin = obj.getLong("uin");
        String status = obj.getString("status");
        int clientType = obj.getInt("client_type");
       
        QQBuddy buddy = store.getBuddyByUin(uin);
        buddy.setStatus(QQStatus.valueOfRaw(status));
        buddy.setClientType(QQClientType.valueOfRaw(clientType));
      }
     
    }

    notifyActionEvent(QQActionEvent.Type.EVT_OK, store.getOnlineBuddyList());
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  protected void onHttpStatusOK(QQHttpResponse response) throws QQException,
      JSONException {
    QQStore store = getContext().getStore();
    List<QQNotifyEvent> notifyEvents = new ArrayList<QQNotifyEvent>();
    JSONObject json = new JSONObject(response.getResponseString());
    int retcode = json.getInt("retcode");
    if (retcode == 0) {
      //有可能为  {"retcode":0,"result":"ok"}
      if ( !json.isNull("result") && json.get("result") instanceof JSONArray) {
        JSONArray results = json.getJSONArray("result");
        // 消息下载来的列表中是倒过来的,那我直接倒过来取,编位回来
        for (int i = results.length() - 1; i >= 0; i--) {
          JSONObject poll = results.getJSONObject(i);
          String pollType = poll.getString("poll_type");
          JSONObject pollData = poll.getJSONObject("value");
          if (pollType.equals("input_notify")) {
            long fromUin = pollData.getLong("from_uin");
            QQBuddy buddy = store.getBuddyByUin(fromUin);
            notifyEvents.add(new QQNotifyEvent(
                QQNotifyEvent.Type.BUDDY_INPUT, buddy));
          } else if (pollType.equals("message")) {
            // 好友消息
            notifyEvents.add(processBuddyMsg(pollData));
View Full Code Here

   * @throws iqq.im.QQException if any.
   * @return a {@link iqq.im.event.QQNotifyEvent} object.
   */
  public QQNotifyEvent processBuddyMsg(JSONObject pollData)
      throws JSONException, QQException {
    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 Date(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);
View Full Code Here

      throws JSONException, QQException {
    // {"retcode":0,"result":[{"poll_type":"group_message",
    // "value":{"msg_id":6175,"from_uin":3924684389,"to_uin":1070772010,"msg_id2":992858,"msg_type":43,"reply_ip":176621921,
    // "group_code":3439321257,"send_uin":1843694270,"seq":875,"time":1365934781,"info_seq":170125666,"content":[["font",{"size":10,"color":"3b3b3b","style":[0,0,0],"name":"\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"));
    long fromUin = pollData.getLong("send_uin");
    long groupCode = pollData.getLong("group_code");
    long groupID = pollData.getLong("info_seq"); // 真实群号码
    QQGroup group = store.getGroupByCode(groupCode);
    if (group.getGid() <= 0) {
      group.setGid(groupID);
    }
    msg.parseContentList(pollData.getJSONArray("content").toString());
    msg.setType(QQMsg.Type.GROUP_MSG);
View Full Code Here

   * @throws iqq.im.QQException if any.
   * @return a {@link iqq.im.event.QQNotifyEvent} object.
   */
  public QQNotifyEvent processDiscuzMsg(JSONObject pollData)
      throws JSONException, QQException {
    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 Date(pollData.getLong("time") * 1000));

    if (msg.getDiscuz() != null) {
      msg.setFrom(msg.getDiscuz().getMemberByUin(fromUin));
View Full Code Here

  public QQNotifyEvent processSessionMsg(JSONObject pollData)
      throws JSONException, QQException {
    // {"retcode":0,"result":[{"poll_type":"sess_message",
    // "value":{"msg_id":25144,"from_uin":167017143,"to_uin":1070772010,"msg_id2":139233,"msg_type":140,"reply_ip":176752037,"time":1365931836,"id":2581801127,"ruin":444674479,"service_type":1,
    // "flags":{"text":1,"pic":1,"file":1,"audio":1,"video":1},"content":[["font",{"size":9,"color":"000000","style":[0,0,0],"name":"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"); // Group:0,Discuss:1
    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 Date(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);
        for (QQUser u : group.getMembers()) {
          if (u.getUin() == fromUin) {
            user = u;
            break;
          }
        }
      } else if (serviceType == 1) { // 是讨论组成员
        QQDiscuz discuz = store.getDiscuzByDid(typeId);
        for (QQUser u : 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);
View Full Code Here

  @Override
  protected void onHttpStatusOK(QQHttpResponse response) throws QQException,
      JSONException {
    JSONObject json = new JSONObject(response.getResponseString());
    int retcode = json.getInt("retcode");
    QQStore store = getContext().getStore();
    if (retcode == 0) {
      // 处理好友列表
      JSONObject results = json.getJSONObject("result");
      // 获取JSON列表信息
      JSONArray jsonCategories = results.getJSONArray("categories");
      // 获取JSON好友基本信息列表 flag/uin/categories
      JSONArray jsonFriends = results.getJSONArray("friends");
      // face/flag/nick/uin
      JSONArray jsonInfo = results.getJSONArray("info");
      // uin/markname/
      JSONArray jsonMarknames = results.getJSONArray("marknames");
      // vip_level/u/is_vip
      JSONArray jsonVipinfo = results.getJSONArray("vipinfo");

      // 默认好友列表
      QQCategory c = new QQCategory();
      c.setIndex(0);
      c.setName("我的好友");
      c.setSort(0);
      store.addCategory(c);
      // 初始化好友列表
      for (int i = 0; i < jsonCategories.length(); i++) {
        JSONObject jsonCategory = jsonCategories.getJSONObject(i);
        QQCategory qqc = new QQCategory();
        qqc.setIndex(jsonCategory.getInt("index"));
        qqc.setName(jsonCategory.getString("name"));
        qqc.setSort(jsonCategory.getInt("sort"));
        store.addCategory(qqc);
      }
      // 处理好友基本信息列表 flag/uin/categories
      for (int i = 0; i < jsonFriends.length(); i++) {
        QQBuddy buddy = new QQBuddy();
        JSONObject jsonFriend = jsonFriends.getJSONObject(i);
        long uin = jsonFriend.getLong("uin");
        buddy.setUin(uin);
        buddy.setStatus(QQStatus.OFFLINE);
        buddy.setClientType(QQClientType.UNKNOWN);
        // 添加到列表中
        int category = jsonFriend.getInt("categories");
        QQCategory qqCategory = store.getCategoryByIndex(category);
        buddy.setCategory(qqCategory);
        qqCategory.getBuddyList().add(buddy);

        // 记录引用
        store.addBuddy(buddy);
      }
      // face/flag/nick/uin
      for (int i = 0; i < jsonInfo.length(); i++) {
        JSONObject info = jsonInfo.getJSONObject(i);
        long uin = info.getLong("uin");
        QQBuddy buddy = store.getBuddyByUin(uin);
        buddy.setNickname(info.getString("nick"));
      }
      // uin/markname
      for (int i = 0; i < jsonMarknames.length(); i++) {
        JSONObject jsonMarkname = jsonMarknames.getJSONObject(i);
        long uin = jsonMarkname.getLong("uin");
        QQBuddy buddy = store.getBuddyByUin(uin);
        if(buddy != null){
          buddy.setMarkname(jsonMarkname.getString("markname"));
        }
      }
      // vip_level/u/is_vip
      for (int i = 0; i < jsonVipinfo.length(); i++) {
        JSONObject vipInfo = jsonVipinfo.getJSONObject(i);
        long uin = vipInfo.getLong("u");
        QQBuddy buddy = store.getBuddyByUin(uin);
        buddy.setVipLevel(vipInfo.getInt("vip_level"));
        int isVip = vipInfo.getInt("is_vip");
        if(isVip != 0) {
          buddy.setVip(true);
        } else {
          buddy.setVip(false);
        }
      }

      notifyActionEvent(QQActionEvent.Type.EVT_OK, store.getCategoryList());

    } else {
      LOG.warn("unknown retcode: " + retcode);
      notifyActionEvent(QQActionEvent.Type.EVT_ERROR, null);
    }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  protected void onHttpStatusOK(QQHttpResponse response) throws QQException,
      JSONException {
    JSONObject json = new JSONObject(response.getResponseString());
    QQStore store = getContext().getStore();
        if (json.getInt("retcode") == 0) {
            JSONObject result = json.getJSONObject("result");
           
            //result/info
            JSONObject info = result.getJSONObject("info");
            discuz.setName(info.getString("discu_name"));
            discuz.setOwner(info.getLong("discu_owner"));
           
            //result/mem_list
            JSONArray memlist = result.getJSONArray("mem_info");
            for(int i=0; i<memlist.length(); i++){
              JSONObject memjson = memlist.getJSONObject(i);
              QQDiscuzMember member = discuz.getMemberByUin(memjson.getLong("uin"));
              if(member == null) {
                member = new QQDiscuzMember();
                discuz.addMemeber(member);
              }
              member.setUin(memjson.getLong("uin"));
              member.setQQ(memjson.getLong("uin"))//这里有用户真实的QQ号
              member.setNickname(memjson.getString("nick"));
              member.setDiscuz(discuz);
            }
           
            // 消除所有成员状态,如果不在线的,webqq是不会返回的。
          discuz.clearStatus();
            //result/mem_status
            JSONArray statlist = result.getJSONArray("mem_status");
            for(int i=0; i<statlist.length(); i++){
        // 下面重新设置最新状态
              JSONObject statjson = statlist.getJSONObject(i);
              QQUser member = discuz.getMemberByUin(statjson.getLong("uin"));
              if(statjson.has("client_type") && member != null) {
                  member.setClientType(QQClientType.valueOfRaw(statjson.getInt("client_type")));
            member.setStatus(QQStatus.valueOfRaw(statjson.getString("status")));
              }
            }
           
            //result/mem_info
            JSONArray infolist = result.getJSONArray("mem_info");
            for(int i=0; i<infolist.length(); i++){
              JSONObject infojson = infolist.getJSONObject(i);
              QQUser member = discuz.getMemberByUin(infojson.getLong("uin"));
              member.setNickname(infojson.getString("nick"));
            }
           
            notifyActionEvent(QQActionEvent.Type.EVT_OK, store.getDiscuzList());
        }else{
          notifyActionEvent(QQActionEvent.Type.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE));
        }
  }
View Full Code Here

  protected void onHttpStatusOK(QQHttpResponse response) throws QQException, JSONException {
    //{"retcode":0,"result":{"dnamelist":[{"did":3536443553,"name":"\u8FD9\u662F\u6807\u9898"},
    //{"did":625885728,"name":""}],"dmasklist":[{"did":1000,"mask":0}]}}
   
    JSONObject json = new JSONObject(response.getResponseString());
    QQStore store = getContext().getStore();
        if (json.getInt("retcode") == 0) {
            JSONObject result = json.getJSONObject("result");
            JSONArray  dizlist = result.getJSONArray("dnamelist");
            for(int i=0; i<dizlist.length(); i++){
               QQDiscuz discuz = new QQDiscuz();
               JSONObject dizjson = dizlist.getJSONObject(i);
               discuz.setDid(dizjson.getLong("did"));
               discuz.setName(dizjson.getString("name"));
               store.addDiscuz(discuz);
            }
            notifyActionEvent(QQActionEvent.Type.EVT_OK, store.getDiscuzList());
        }else{
          notifyActionEvent(QQActionEvent.Type.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE));
        }
  }
View Full Code Here

TOP

Related Classes of iqq.im.core.QQStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.