Skip to content

Commit

Permalink
Add feature to apply to groups continuously by automatically cancelli…
Browse files Browse the repository at this point in the history
…ng the oldest application (rolling applications) (see #163)
  • Loading branch information
0xbs committed Oct 13, 2024
1 parent 26ca56a commit f9de442
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Modules/OneClickSignUp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,72 @@
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-------------------------------------------------------------------------------

local PGF = select(2, ...)
local L = PGF.L
local C = PGF.C

function PGF.GetOldestApplicationResultID()
local oldestResultID = 0
local oldestAppDuration = 0
local apps = C_LFGList.GetApplications()
-- loop backwards through the results list so we can remove elements from the table
for i = #apps, 1, -1 do
local _, status, pendingStatus, appDuration = C_LFGList.GetApplicationInfo(apps[i])
-- we want to make sure not to cancel an invite or any pendingStatus
if status == "invited" and not pendingStatus then
table.remove(apps, i)
end
if appDuration > oldestAppDuration then
oldestResultID = apps[i]
oldestAppDuration = appDuration
end
end
return oldestResultID
end

PGF.clickAgainFrames = {}

hooksecurefunc("LFGListSearchEntry_OnClick", function (self, button)
if not PremadeGroupsFilterSettings.oneClickSignUp then return end

local panel = LFGListFrame.SearchPanel

local clickAgainFrame = PGF.clickAgainFrames[self]
if clickAgainFrame == nil then
local frame = CreateFrame("Frame", nil, self, nil)
frame:Hide()
frame:SetFrameStrata("HIGH")
frame:SetPoint("TOPLEFT", 3, -3)
frame:SetPoint("BOTTOMRIGHT", -3, -1)
frame.Background = frame:CreateTexture("$parentBackground", "BACKGROUND")
frame.Background:SetAllPoints()
frame.Background:SetColorTexture(0.1, 0.1, 0.1, 0.8)
frame.Title = frame:CreateFontString("$parentTitle", "ARTWORK", "GameFontHighlight")
frame.Title:SetPoint("CENTER")
frame.Title:SetPoint("TOP", 0, -6)
frame.Title:SetText("Click again to apply")
frame.Subtitle = frame:CreateFontString("$parentSubtitle", "ARTWORK", "GameFontNormalSmall")
frame.Subtitle:SetPoint("CENTER")
frame.Subtitle:SetPoint("BOTTOM", 0, 3)
frame.Subtitle:SetText("Your oldest application was canceled automatically")
PGF.clickAgainFrames[self] = frame
clickAgainFrame = frame
end
clickAgainFrame:Hide()

-- if we already have max applications pending, cancel oldest application before signing up
local numApplications, numActiveApplications = C_LFGList.GetNumApplications()
if numActiveApplications >= MAX_LFG_LIST_APPLICATIONS then
local oldestResultID = PGF.GetOldestApplicationResultID()
if oldestResultID > 0 then
PGF.Logger:Debug("Canceling application "..oldestResultID)
C_LFGList.CancelApplication(oldestResultID) -- required hardware event
LFGListSearchPanel_UpdateButtonStatus(panel)
clickAgainFrame:Show() -- tell player to click again
return -- we cannot apply right now because we already used our hardware event for cancelation
end
end

if button ~= "RightButton" and LFGListSearchPanelUtil_CanSelectResult(self.resultID) and panel.SignUpButton:IsEnabled() then
if panel.selectedResult ~= self.resultID then
LFGListSearchPanel_SelectResult(panel, self.resultID)
Expand Down

0 comments on commit f9de442

Please sign in to comment.