-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportFlow.lua
More file actions
123 lines (98 loc) · 2.98 KB
/
Copy pathReportFlow.lua
File metadata and controls
123 lines (98 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
local _, NS = ...
local ReportFlow = {}
local targetsByEntryID = {}
local function DevLog(message)
if NS.DB and NS.DB.DevLog then
NS.DB.DevLog(message)
end
end
local function QueueTarget(historyEntryID, target)
if historyEntryID == nil or type(target) ~= "table" or type(target.kind) ~= "string" then
return false
end
targetsByEntryID[historyEntryID] = target
return targetsByEntryID[historyEntryID] ~= nil
end
local function ClearTarget(historyEntryID)
targetsByEntryID[historyEntryID] = nil
end
local function GetTarget(historyEntryID, expectedKind)
local target = targetsByEntryID[historyEntryID]
if not target then
return nil
end
if expectedKind and target.kind ~= expectedKind then
return nil
end
return target
end
local function CanReportChat()
return not (NS.Compat and NS.Compat.hasChatReportDialog == false)
end
function ReportFlow.QueueChatReport(historyEntryID, lineID, senderName)
if lineID == nil or not CanReportChat() then
return false
end
return QueueTarget(historyEntryID, {
kind = "chat",
lineID = lineID,
senderName = senderName,
})
end
function ReportFlow.HasReport(historyEntryID)
local target = targetsByEntryID[historyEntryID]
return target ~= nil
end
function ReportFlow.GetReportKind(historyEntryID)
local target = targetsByEntryID[historyEntryID]
return target and target.kind or nil
end
function ReportFlow.CanReportChat()
return CanReportChat()
end
function ReportFlow.ReportChatNow(historyEntryID)
local target = GetTarget(historyEntryID, "chat")
if not target then
return false
end
if not ReportFlow.CanReportChat() then
DevLog("chat report dialog unavailable in this client.")
return false
end
if not PlayerLocation or type(PlayerLocation.CreateFromChatLineID) ~= "function" then
DevLog("chat report location API unavailable.")
return false
end
if not C_ReportSystem or type(C_ReportSystem.OpenReportPlayerDialog) ~= "function" then
DevLog("chat report dialog API unavailable.")
return false
end
if PLAYER_REPORT_TYPE_SPAM == nil then
DevLog("chat report type unavailable.")
return false
end
local locationOk, location = pcall(PlayerLocation.CreateFromChatLineID, PlayerLocation, target.lineID)
if not locationOk or not location then
DevLog("chat report location unavailable.")
return false
end
if type(C_ReportSystem.CanReportPlayer) == "function" then
local canCheck, canReport = pcall(C_ReportSystem.CanReportPlayer, PLAYER_REPORT_TYPE_SPAM, location)
if canCheck and canReport == false then
DevLog("chat report target is not reportable.")
return false
end
end
local ok = pcall(C_ReportSystem.OpenReportPlayerDialog, PLAYER_REPORT_TYPE_SPAM, location, target.senderName)
if ok then
ClearTarget(historyEntryID)
return true
end
DevLog("chat report dialog failed.")
return false
end
function ReportFlow.Clear(historyEntryID)
ClearTarget(historyEntryID)
end
NS.ReportFlow = ReportFlow
return ReportFlow