Some general code cleanup
This commit is contained in:
@@ -123,11 +123,10 @@ std::shared_ptr<ViewEntry> ClientChannelView::find_channel(const std::shared_ptr
|
||||
return head ? static_pointer_cast<ViewEntry>(head->entry) : nullptr;
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared_ptr<TreeView::LinkedTreeEntry> head, bool test_permissions, bool first_only, std::shared_ptr<server::CalculateCache> cache) {
|
||||
std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared_ptr<TreeView::LinkedTreeEntry> head, bool test_permissions, bool first_only) {
|
||||
std::deque<std::shared_ptr<ViewEntry>> result;
|
||||
|
||||
if(!cache && test_permissions) cache = make_shared<CalculateCache>();
|
||||
bool has_perm = !test_permissions || permission::v2::permission_granted(1, owner->calculate_permission(permission::b_channel_ignore_view_power, 0, false, cache));
|
||||
bool has_perm = !test_permissions || permission::v2::permission_granted(1, owner->calculate_permission(permission::b_channel_ignore_view_power, 0, false));
|
||||
bool first = true;
|
||||
while(head) {
|
||||
if(!first && first_only) break;
|
||||
@@ -136,7 +135,7 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared
|
||||
auto channel = dynamic_pointer_cast<BasicChannel>(head->entry);
|
||||
if(this->channel_visible(channel)) {
|
||||
if(head->child_head) {
|
||||
for(const auto& sub : this->insert_channels(head->child_head, test_permissions, false, cache))
|
||||
for(const auto& sub : this->insert_channels(head->child_head, test_permissions, false))
|
||||
result.push_back(sub);
|
||||
}
|
||||
|
||||
@@ -183,7 +182,7 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared
|
||||
result.push_back(entry);
|
||||
|
||||
if(head->child_head) {
|
||||
for(const auto& sub : this->insert_channels(head->child_head, test_permissions, false, cache))
|
||||
for(const auto& sub : this->insert_channels(head->child_head, test_permissions, false))
|
||||
result.push_back(sub);
|
||||
}
|
||||
head = head->next;
|
||||
@@ -244,11 +243,9 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::show_channel(std::shar
|
||||
}
|
||||
|
||||
std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::test_channel(std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_old,
|
||||
std::shared_ptr<ts::TreeView::LinkedTreeEntry> channel_new, shared_ptr<CalculateCache> cache) {
|
||||
if(!cache) cache = make_shared<CalculateCache>();
|
||||
|
||||
std::shared_ptr<ts::TreeView::LinkedTreeEntry> channel_new) {
|
||||
std::deque<std::shared_ptr<ViewEntry>> result;
|
||||
bool has_perm = permission::v2::permission_granted(1, owner->calculate_permission(permission::b_channel_ignore_view_power, 0, false, cache));
|
||||
bool has_perm = permission::v2::permission_granted(1, owner->calculate_permission(permission::b_channel_ignore_view_power, 0, false));
|
||||
if(has_perm) return {};
|
||||
|
||||
deque<shared_ptr<TreeView::LinkedTreeEntry>> parents = {l_old};
|
||||
@@ -284,14 +281,13 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::test_channel(std::shar
|
||||
}
|
||||
|
||||
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> ClientChannelView::update_channel(
|
||||
std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_channel, std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_own, shared_ptr<CalculateCache> cache) {
|
||||
return update_channel_path(std::move(l_channel), std::move(l_own), std::move(cache), 1);
|
||||
std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_channel, std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_own) {
|
||||
return update_channel_path(std::move(l_channel), std::move(l_own), 1);
|
||||
}
|
||||
|
||||
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> ClientChannelView::update_channel_path(std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_channel, std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_own, shared_ptr<CalculateCache> cache, ssize_t length) {
|
||||
if(!cache) cache = make_shared<CalculateCache>();
|
||||
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> ClientChannelView::update_channel_path(std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_channel, std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_own, ssize_t length) {
|
||||
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> result;
|
||||
bool has_perm = permission::v2::permission_granted(1, owner->calculate_permission(permission::b_channel_ignore_view_power, 0, false, cache));
|
||||
bool has_perm = permission::v2::permission_granted(1, owner->calculate_permission(permission::b_channel_ignore_view_power, 0, false));
|
||||
|
||||
while(l_channel && length-- != 0) {
|
||||
auto b_channel = dynamic_pointer_cast<BasicChannel>(l_channel->entry);
|
||||
@@ -313,20 +309,20 @@ std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> ClientChannelView::updat
|
||||
if(visible) {
|
||||
for(const auto& entry : this->show_channel(l_channel, visible))
|
||||
result.emplace_back(true, entry);
|
||||
for(const auto& entry : this->insert_channels(l_channel->child_head, true, false, cache))
|
||||
for(const auto& entry : this->insert_channels(l_channel->child_head, true, false))
|
||||
result.emplace_back(true, entry);
|
||||
}
|
||||
|
||||
l_channel = l_channel->next;
|
||||
continue; /* all subchannels had been checked */
|
||||
} else if(visible && !has_perm) {
|
||||
for(const auto& entry : this->test_channel(l_channel, l_own, cache))
|
||||
for(const auto& entry : this->test_channel(l_channel, l_own))
|
||||
result.emplace_back(false, entry);
|
||||
}
|
||||
|
||||
//Root node is okey, test children
|
||||
if(l_channel->child_head) {
|
||||
auto entries = this->update_channel_path(l_channel->child_head, l_own, cache, -1);
|
||||
auto entries = this->update_channel_path(l_channel->child_head, l_own, -1);
|
||||
result.insert(result.end(), entries.begin(), entries.end());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user