0xbs / premade-groups-filter

A World of Warcraft addon for powerful filtering of premade group listings.
GNU General Public License v2.0
73 stars 37 forks source link

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

Open Jodsderechte opened 1 month ago

Jodsderechte commented 1 month ago

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

0xbs commented 1 month ago

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?

Jodsderechte commented 1 month ago

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.

0xbs commented 1 month ago

I created a branch with the CallbackHandler: https://github.com/0xbs/premade-groups-filter/compare/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.

Jodsderechte commented 1 month ago

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