From f9de4425b834ddb820d3f2f51bb107d0d5564f2d Mon Sep 17 00:00:00 2001 From: Bernhard Saumweber Date: Sun, 13 Oct 2024 18:59:31 +0200 Subject: [PATCH] Add feature to apply to groups continuously by automatically cancelling the oldest application (rolling applications) (see #163) --- Modules/OneClickSignUp.lua | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Modules/OneClickSignUp.lua b/Modules/OneClickSignUp.lua index bc1ee0f..3cdae1c 100644 --- a/Modules/OneClickSignUp.lua +++ b/Modules/OneClickSignUp.lua @@ -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)