Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Add get_friend_list function
Browse files Browse the repository at this point in the history
  • Loading branch information
stdrc committed Oct 7, 2019
1 parent b9a9872 commit dac5421
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions api.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ namespace cq::api {
return utils::string_from_coolq(ret);
}

inline std::string get_friend_list_base64() noexcept(false) {
const auto ret = raw::CQ_getFriendList(app::auth_code, false);
__throw_if_needed(ret);
return utils::string_from_coolq(ret);
}

inline std::string get_group_list_base64() noexcept(false) {
const auto ret = raw::CQ_getGroupList(app::auth_code);
__throw_if_needed(ret);
Expand Down Expand Up @@ -275,6 +281,14 @@ namespace cq::api {
}
}

inline std::vector<Friend> get_friend_list() noexcept(false) {
try {
return ObjectHelper::multi_from_base64<std::vector<Friend>>(get_friend_list_base64());
} catch (exception::ParseError &) {
throw exception::ApiError(exception::ApiError::INVALID_DATA);
}
}

inline std::vector<Group> get_group_list() noexcept(false) {
try {
return ObjectHelper::multi_from_base64<std::vector<Group>>(get_group_list_base64());
Expand Down
1 change: 1 addition & 0 deletions api_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ FUNC(int32_t, setGroupAddRequestV2, int32_t auth_code, const char *response_flag
FUNC(int64_t, getLoginQQ, int32_t auth_code)
FUNC(const char *, getLoginNick, int32_t auth_code)
FUNC(const char *, getStrangerInfo, int32_t auth_code, int64_t qq, cq_bool_t no_cache)
FUNC(const char *, getFriendList, int32_t auth_code, cq_bool_t reserved)
FUNC(const char *, getGroupList, int32_t auth_code)
FUNC(const char *, getGroupMemberList, int32_t auth_code, int64_t group_id)
FUNC(const char *, getGroupMemberInfoV2, int32_t auth_code, int64_t group_id, int64_t qq, cq_bool_t no_cache)
Expand Down
25 changes: 24 additions & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,29 @@ namespace cq {
}
};

struct Friend : User {
const static size_t MIN_SIZE = 12;

// int64_t user_id; // from User
// std::string nickname; // from User
std::string remark;
// Sex sex; // from User, not using
// int32_t age; // from User, not using

static Friend from_bytes(const std::string &bytes) {
auto pack = utils::BinPack(bytes);
Friend frnd;
try {
frnd.user_id = pack.pop_int<int64_t>();
frnd.nickname = pack.pop_string();
frnd.remark = pack.pop_string();
} catch (exception::BytesNotEnough &) {
throw exception::ParseError("failed to parse from bytes to a Friend object");
}
return frnd;
}
};

struct Group {
const static size_t MIN_SIZE = 10;

Expand All @@ -91,7 +114,7 @@ namespace cq {
// int64_t user_id; // from User
// std::string nickname; // from User
std::string card;
// Sex sex = Sex::UNKNOWN; // from User
// Sex sex; // from User
// int32_t age; // from User
std::string area;
int32_t join_time = 0;
Expand Down

0 comments on commit dac5421

Please sign in to comment.