From f0176ecadc6a1a355e1ddffc5cb015970e531ea4 Mon Sep 17 00:00:00 2001 From: jordanschwab <37817031+jordanschwab@users.noreply.github.com> Date: Sun, 13 Mar 2022 11:03:52 +1300 Subject: [PATCH] Added /rfilter Enabled /rfilter Issues: 1. after clicking refresh, new entries will not contain leader information. Open/close to get filter working (hit 'i' twice) 2. You will only get 100 results back from API. Refresh often to find more groups for smaller regions (OCE) --- CHANGES.txt | 3 ++ RegionFilter.toc | 2 +- main.lua | 95 ++++++++++++++++++++++++++++++------------------ 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ae34417..e40a8f7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -56,3 +56,6 @@ Version 1.4.0 - Cleaned up some of the server listings - Reflect changes in the datacentre merges - New colour scheme (feedback wanted for this) + +Version 1.5.2 + - Slash command '/rfilter' to remove groups from outside your region. diff --git a/RegionFilter.toc b/RegionFilter.toc index 205f69b..7bd0d50 100644 --- a/RegionFilter.toc +++ b/RegionFilter.toc @@ -1,7 +1,7 @@ ## Interface: 90105 ## Title: Region Filter ## Notes: Tags groups in the native LFG search if they are from your server and data-centre -## Version: 1.5.0 +## Version: 1.5.2 utils.lua servers.lua diff --git a/main.lua b/main.lua index aacdd9b..17edcb0 100644 --- a/main.lua +++ b/main.lua @@ -1,7 +1,7 @@ local RF = select(2, ...) local servers = RF.servers local posts = RF.posts -RF.version = "1.5.0" +RF.version = "1.5.2" RF.togRemove = false local spaced_realm = string.gsub(GetRealmName(), "%s+", "") @@ -24,30 +24,53 @@ if RF.region == 'OC' then RF.postType = posts.oc_post end if RF.region == 'LA' then RF.postType = posts.la_post end if RF.region == 'BR' then RF.postType = posts.br_post end ---- Removing Enrties when togRemove is enabled --- function RF.removeEntries(results) --- if RF.togRemove then --- for i=1, #results do --- local resultID = results[i] --- local searchResults = C_LFGList.GetSearchResultInfo(resultID) +function RF.removeEntries(results) + local isLocal = {} + if RF.togRemove then + local localCount = 0 + local originalResultCount = #results + for i=originalResultCount, 1, -1 do + local resultID = results[i] + isLocal[resultID] = false + local searchResults = C_LFGList.GetSearchResultInfo(resultID) --- local leaderName = searchResults.leaderName + local leaderName = searchResults.leaderName --- if leaderName ~= nil then -- Filter out nil entries from LFG Pane --- local name, realm = RF:sanitiseName(leaderName) --- local info = servers[realm] --- if info ~= nil then --- local region = info[1] --- if RF.region ~= region then --- table.remove(results, i) --- end --- end --- end --- end --- end --- table.sort(results) --- LFGListFrame.SearchPanel.totalResults = #results --- return true --- end + if leaderName ~= nil then -- Filter out nil entries from LFG Pane + local name, realm = RF:sanitiseName(leaderName) + local info = servers[realm] + if info ~= nil then + local region = info[1] + if RF.region ~= region then + table.remove(results, i) + else + localCount = localCount + 1 + isLocal[resultID] = true + end + end + end + end + + local function sortCompFunc(searchResultID1, searchResultID2) + if (isLocal[searchResultID1]) then + if (not isLocal[searchResultID2]) then + return true + end + else + if (isLocal[searchResultID2]) then + return false + end + end + return searchResultID1>searchResultID2 + end + + table.sort(results, sortCompFunc) + else + table.sort(results) + end + LFGListFrame.SearchPanel.totalResults = #results + return true +end ---- Updating the text of entries function RF.updateEntries(results) @@ -81,17 +104,17 @@ function RF.updateEntries(results) end --- SLASH_RFILTER1 = "/rfilter" --- SlashCmdList["RFILTER"] = function(msg) --- if RF.togRemove then --- print('|cff00ffff[Region Filter]: |cffFF6EB4 Not filtering outside regions') --- else --- print('|cff00ffff[Region Filter]: |cffFF6EB4 Filtering outside regions') --- end --- RF.togRemove = not RF.togRemove --- LFGListSearchPanel_UpdateResultList (LFGListFrame.SearchPanel) --- LFGListSearchPanel_UpdateResults (LFGListFrame.SearchPanel) --- end +SLASH_RFILTER1 = "/rfilter" +SlashCmdList["RFILTER"] = function(msg) + if RF.togRemove then + print('|cff00ffff[Region Filter]: |cffFF6EB4 Not filtering outside regions') + else + print('|cff00ffff[Region Filter]: |cffFF6EB4 Filtering outside regions') + end + RF.togRemove = not RF.togRemove + LFGListSearchPanel_UpdateResultList (LFGListFrame.SearchPanel) + LFGListSearchPanel_UpdateResults (LFGListFrame.SearchPanel) +end ---- Print When Loaded ---- local welcomePrompt = CreateFrame("Frame") @@ -103,5 +126,5 @@ welcomePrompt:SetScript("OnEvent", function(_, event) end end) --- hooksecurefunc("LFGListUtil_SortSearchResults", RF.sortEntries) -hooksecurefunc("LFGListSearchEntry_Update", RF.updateEntries) \ No newline at end of file +hooksecurefunc("LFGListSearchEntry_Update", RF.updateEntries) +hooksecurefunc("LFGListUtil_SortSearchResults", RF.removeEntries)