Premade Groups Filter

Premade Groups Filter

9M Downloads

add an option to disable sorting (or maybe an option for other addons to interact with sorting)

Jodsderechte opened this issue · 10 comments

commented

Is your feature request related to a problem? Please describe.

So i've been recently working on another Addon that provides some group finder R.io functionality specifically displaying m+/raid progress of characters and mains. It also allows for sorting of applicants and groups. However something i realised in my personal testing as i'm using premade group filter myself the sorting that happens at the end of PGF.DoFilterSearchResults() (line 352) creates a race conditions since both addons are hooking into "LFGListSearchPanel_UpdateResults" and therefore one or the other addon is always quicker in resorting therefore messing up the sort results.

Describe the solution you'd like

In a perfect world I could use premadegroupfilter to filter the entries and then apply additional filter/sorting with other addons either by disabling sorting in pgf or preferably even registering callbacks for pgf to call.

Describe alternatives you've considered

I've looked into other LFGList events further down the line to overwrite search results but nothing is realy a clean solution.

Additional context

I could spend time and PR this myself if you'd approve it

commented

I was always wondering in which order hooks are executed. I assumed it's in the order of hooking, but from your experience it looks like it's just random on each call.

Hooking LFGListSearchPanel_UpdateResults is the best option, I also looked for about better alternative and found none.

I don't really know a way to make the order of hooks consistent. So I think the easiest way would be that I make my sorting function public so it is possible to hook (or overwrite) it.

As the loading order of addons is random, this means that you would have to listen to the addon loaded events and wait for PGF to be loaded as the hook can only be applied after PGF is loaded.

What do you think?

commented

The load order of addons is technically not Random. If i add PGF as an optional dependency the addon will always load after PGF but both would be fine either if you expose it globally or if you add ways to register Sorting functions either by using sth like https://www.curseforge.com/wow/addons/callbackhandler or your own method whatever you prefer. Hooks seem to also not be entirely random i added loging to both functions and pgf sorting always happened before my addons sorting so i have actually 0 idea why it actually interfers.

commented

I created a branch with the CallbackHandler: master...feature/events

I could successfully subscribe via:

local addon = select(2, ...)
PremadeGroupsFilter.RegisterCallback(addon, "SortSearchResults", function(results)
    print("SortSearchResults called! #results=="..#results)
end)

Would that be sufficient for you? Or do you need a pre-sorting event?

Not yet sure how I feel about having a lib dependency now, but let's see what you say.

commented

Ok i did some more testing on this with that branch. Since the Callback handler is async that doesn't seem to work (that was something i completly forgot when suggesting this sorry). It seems like it's even failing to work if i simply add my sort function to the end of the sortSearchResults of PGF. I have no idea what exactly with that search function is interfering but for some reason it only works if i uncomment PGF.SortSearchResults(results) in line 352 of pgf main.lua and replace that with my sort function. Even just sorting in the line before or after PGF.SortSearchResult didn't work. So i guess making the function global so it can be overridden would be the only thing that works

commented

I've been getting a bunch of a reports from users about this. Any chance we can get something going? I can do a pr for it if you would want / it would make your life easier.

commented

I will try to add code so that you can override the function. I’m busy until next weekend, so don’t expect any changes until then.

commented

Thats all i can hope for thank you!

commented

Latest master (not yet released) now has two public functions to overwrite and restore the sorting function. I could successfully test with the following minimal addon code:

local addonName, addon = ...

local customSortingFunction = function(results)
    table.sort(results, function(resultID1, resultID2)
        local info1 = C_LFGList.GetSearchResultInfo(resultID1)
        local info2 = C_LFGList.GetSearchResultInfo(resultID2)
        return info1.age > info2.age -- by age oldest to newest
    end)
end

local frame = CreateFrame("Frame", addonName .. "EventFrame")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, ...)
    if event == "ADDON_LOADED" and select(1, ...) == addonName then
        print("Overwriting sorting function of PremadeGroupsFilter")
        PremadeGroupsFilter.OverwriteSortSearchResults(addonName, customSortingFunction)
        --PremadeGroupsFilter.RestoreSortSearchResults(addonName)
    end
end)

Please have a try if that works for you.

commented

There is now also a wiki page with all information: https://github.com/0xbs/premade-groups-filter/wiki/Public-API

commented

Thank you!