Exemplo n.º 1
0
  /** 删除单个用户名为username成员 */
  public static void deleteMember(String username) {
    AVObject person = new AVObject();
    AVQuery<AVObject> query1 = new AVQuery<AVObject>("UserInfo");
    try {
      person = query1.get(id(username));
      String singlesharedstr = person.getString("singlesharedidsstr");
      List<String> singleids = Utils.strParse(singlesharedstr);
      singleids.remove(LoginUtil.userinfo.getObjectId());

      // 从被动好友一方删除登陆用户
      if (singleids != null && singleids.size() != 0) {
        person.put("singlesharedidsstr", Utils.strCombine(singleids));
      } else {
        person.put("singlesharedidsstr", "");
      }
      person.save();
      // 从登陆用户列表中删除
      singleShareid.remove(person.getObjectId());
      if (singleShareid != null && singleShareid.size() != 0) {
        LoginUtil.userinfo.put("singlesharedidsstr", Utils.strCombine(singleShareid));
      } else {
        LoginUtil.userinfo.put("singlesharedidsstr", "");
      }
      LoginUtil.userinfo.save();

    } catch (AVException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  /**
   * 将用户名为username的用户从群中删除,同时在用户列表中删除群的信息
   *
   * @param username
   */
  public static void deleteMemberFromGroup(String username) {
    AVQuery<AVObject> query = new AVQuery<AVObject>("Group");
    try {
      sharegroup = query.get(groupid(username));
      // 获取群的id,并从用户列表中删除所在群的id,表明脱离群关系
      String objectid = sharegroup.getObjectId();
      groupShareid.remove(objectid);
      if (groupShareid != null && groupShareid.size() != 0) {
        LoginUtil.userinfo.put("groupsharedidsstr", Utils.strCombine(groupShareid));
      } else {
        LoginUtil.userinfo.put("groupsharedidsstr", "");
      }
      LoginUtil.userinfo.save();

      // 从群中删除用户的信息,如果群为空,则删除群
      String memberidsstr = sharegroup.getString("memberids"); // �获取所有群成员的id
      List<String> memberids = Utils.strParse(memberidsstr);
      for (String id : memberids) {
        if (id.equals(LoginUtil.userinfo.getObjectId())) {
          memberids.remove(id);
          break;
        }
      }
      if (memberids != null && memberids.size() != 0) {
        sharegroup.put("memberids", Utils.strCombine(memberids));
        sharegroup.save();
      } else {
        sharegroup.delete();
      }
    } catch (AVException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }