Skip to content
Repos

DevPlaceApp

C++ 969 B31 lines Opens in site

Directory Raw Download

#include "screens/comments/MentionParticipants.hpp"

#include <set>

#include "spec/PostsSpec.hpp"
#include "store/AppState.hpp"

namespace dp {

namespace {
void collect(const Comment& c, std::vector<const User*>& out) {
  out.push_back(&c.author);
  for (const Comment& child : c.children) collect(child, out);
}
}  // namespace

std::vector<UserSearch::Result> MentionParticipants::from(const User& postAuthor, const std::vector<Comment>& comments) {
  std::vector<const User*> authors{&postAuthor};
  for (const Comment& c : comments) collect(c, authors);
  std::set<std::string> seen;
  std::vector<UserSearch::Result> out;
  for (const User* author : authors) {
    if (out.size() >= spec::PostsLimits::kMaxMentionParticipants) break;
    if (AppState::instance().isCurrentUser(author->id)) continue;
    if (!seen.insert(author->id).second) continue;
    out.push_back({author->id, author->username, author->avatarSeed});
  }
  return out;
}

}  // namespace dp
45.7ms