-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.lua
More file actions
executable file
·200 lines (182 loc) · 6.82 KB
/
Copy pathconfig.lua
File metadata and controls
executable file
·200 lines (182 loc) · 6.82 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
local _, ns = ...
---------------------------------------------------------------------------
-- Config — Saved variable initialization, defaults, and storage switching
--
-- Manages two SavedVariables tables:
-- ICHAT_DATA (per-character) — default storage mode
-- ICHAT_ACCOUNT (account-wide) — optional shared mode
--
-- ns.db always points to whichever is active. SetSharedAccount() handles
-- live switching with data migration (merges conversations, notes, pins).
-- DeepMerge ensures new settings keys are added on updates without
-- overwriting existing user preferences.
---------------------------------------------------------------------------
local defaults = {
conversations = {},
pinnedConversations = {},
contactNotes = {},
mutedContacts = {},
playerInfoCache = {},
settings = {
scale = 1.0,
suppressDefault = true,
openOnWhisper = true,
maxHistory = 100,
font = "Fonts\\FRIZQT__.TTF",
fontSize = 11,
bgAlpha = 0.95,
quickReplies = {},
notifySound = "glass",
showTimestampOnHover = true,
showDateSeparators = true,
enableItemLinks = true,
showOnlineStatus = true,
classColoredNames = true,
autoReplyEnabled = false,
autoReplyMessage = "I'm currently away. I'll respond when I return!",
enableKeyboardShortcuts = true,
showMinimapButton = true,
hideInCombat = true,
buttonSize = 40,
sharedAccount = false,
settingsFontSize = 10,
showTypingIndicator = true,
showOnlineNotifications = true,
elvuiSkin = true,
showPortrait = true,
enableAutoFade = true,
fadeWhileMoving = false,
},
}
-- Deep copy a table (handles nested tables safely)
local function DeepCopy(src)
if type(src) ~= "table" then return src end
local copy = {}
for k, v in pairs(src) do
copy[k] = DeepCopy(v)
end
return copy
end
-- Deep merge: copy missing keys from src into dst (does not overwrite existing)
local function DeepMerge(dst, src)
for k, v in pairs(src) do
if dst[k] == nil then
dst[k] = DeepCopy(v)
elseif type(v) == "table" and type(dst[k]) == "table" then
DeepMerge(dst[k], v)
end
end
end
-- Migrate per-character data into account-wide storage
local function MigrateToAccount()
if not ICHAT_DATA or not ICHAT_ACCOUNT then return end
-- Merge conversations (don't overwrite existing account convos)
for name, convo in pairs(ICHAT_DATA.conversations or {}) do
if not ICHAT_ACCOUNT.conversations[name] then
ICHAT_ACCOUNT.conversations[name] = DeepCopy(convo)
else
-- Append any messages that are newer than the latest in account
local acctConvo = ICHAT_ACCOUNT.conversations[name]
local acctLast = acctConvo.lastActivity or 0
for _, msg in ipairs(convo.messages or {}) do
if msg.time and msg.time > acctLast then
table.insert(acctConvo.messages, DeepCopy(msg))
end
end
if convo.lastActivity and convo.lastActivity > acctLast then
acctConvo.lastActivity = convo.lastActivity
end
end
end
-- Merge contact notes and pinned (don't overwrite)
for name, note in pairs(ICHAT_DATA.contactNotes or {}) do
if not ICHAT_ACCOUNT.contactNotes[name] then
ICHAT_ACCOUNT.contactNotes[name] = note
end
end
for name, v in pairs(ICHAT_DATA.pinnedConversations or {}) do
if not ICHAT_ACCOUNT.pinnedConversations[name] then
ICHAT_ACCOUNT.pinnedConversations[name] = v
end
end
for name, v in pairs(ICHAT_DATA.mutedContacts or {}) do
if not ICHAT_ACCOUNT.mutedContacts[name] then
ICHAT_ACCOUNT.mutedContacts[name] = v
end
end
end
local function InitStorage(storage)
-- Merge top-level keys from defaults
for k, v in pairs(defaults) do
if storage[k] == nil then
storage[k] = DeepCopy(v)
end
end
-- Merge missing settings keys
for k, v in pairs(defaults.settings) do
if storage.settings[k] == nil then
storage.settings[k] = v
end
end
-- Ensure new top-level tables exist
if not storage.pinnedConversations then storage.pinnedConversations = {} end
if not storage.contactNotes then storage.contactNotes = {} end
if not storage.mutedContacts then storage.mutedContacts = {} end
end
function ns.InitDB()
-- Initialize both storage tables
if not ICHAT_DATA then ICHAT_DATA = {} end
if not ICHAT_ACCOUNT then ICHAT_ACCOUNT = {} end
InitStorage(ICHAT_DATA)
InitStorage(ICHAT_ACCOUNT)
-- Determine which storage to use
-- Check account-wide first (shared setting lives there when enabled)
local useShared = ICHAT_ACCOUNT.settings and ICHAT_ACCOUNT.settings.sharedAccount
if useShared then
ns.db = ICHAT_ACCOUNT
else
ns.db = ICHAT_DATA
end
-- Check if WIM is loaded — avoid double-suppression
local IsLoaded = C_AddOns and C_AddOns.IsAddOnLoaded or IsAddOnLoaded
if IsLoaded and IsLoaded("WIM") then
ns.db.settings.suppressDefault = false
end
end
-- Switch between per-character and account-wide storage
-- Called from settings panel when toggling shared mode
function ns.SetSharedAccount(enabled)
if enabled then
-- Migrate current character data into account storage
MigrateToAccount()
ICHAT_ACCOUNT.settings.sharedAccount = true
-- Copy current settings to account (except sharedAccount which we just set)
for k, v in pairs(ICHAT_DATA.settings) do
if k ~= "sharedAccount" and ICHAT_ACCOUNT.settings[k] == nil then
ICHAT_ACCOUNT.settings[k] = DeepCopy(v)
end
end
ns.db = ICHAT_ACCOUNT
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Switched to account-wide storage. Character data merged.")
else
ICHAT_ACCOUNT.settings.sharedAccount = false
ICHAT_DATA.settings.sharedAccount = false
ns.db = ICHAT_DATA
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Switched to per-character storage.")
end
-- Refresh UI with new data source
if ns.RefreshConversationList then ns.RefreshConversationList() end
if ns.activeConversation then
local convo = ns.db.conversations[ns.activeConversation]
if convo then
ns.RebuildBubbles(ns.activeConversation)
else
ns.activeConversation = nil
end
end
if ns.UpdateButtonBadge then ns.UpdateButtonBadge() end
end
-- Check if currently using shared account storage
function ns.IsSharedAccount()
return ICHAT_ACCOUNT and ICHAT_ACCOUNT.settings and ICHAT_ACCOUNT.settings.sharedAccount or false
end