diff --git a/server/imserver/asynctaskmgr.cc b/server/imserver/asynctaskmgr.cc index 68ad890..84e306d 100644 --- a/server/imserver/asynctaskmgr.cc +++ b/server/imserver/asynctaskmgr.cc @@ -57,7 +57,38 @@ struct RecommandFriendTask void Done() { if (context.IsValid()) { + std::set& exclude_account_ids = context.hum->GetExcludeAccountIds(); + std::set batch_account_ids; cs::SMRecommandFriend msg; + for (auto& pair : recommand_friends) { + if (msg.friend_list_size() < 4) { + *msg.add_friend_list() = pair.second; + exclude_account_ids.insert(pair.first); + batch_account_ids.insert(pair.first); + } + } + std::shuffle(DBHelper::Instance()->cache_users_list.begin(), + DBHelper::Instance()->cache_users_list.end(), + std::default_random_engine(rand())); + for (auto& user_info : DBHelper::Instance()->cache_users_list) { + if (msg.friend_list_size() >= 4) { + break; + } + if (exclude_account_ids.find(user_info->base_data().account_id()) == + exclude_account_ids.end()) { + *msg.add_friend_list() = *user_info; + exclude_account_ids.insert(user_info->base_data().account_id()); + batch_account_ids.insert(user_info->base_data().account_id()); + } + } + if (exclude_account_ids.size() > 50) { + std::vector deleted_account_ids; + for (auto& account_id : exclude_account_ids) { + if (batch_account_ids.find(account_id) == batch_account_ids.end()) { + deleted_account_ids.push_back(account_id); + } + } + } context.hum->SendMsg(msg); } }