Use CHAT_MSG_CHANNEL_NOTICE instead of hooking join and leave slash functions for stored channels
This commit is contained in:
parent
0b51f257ed
commit
aa65c554a3
1 changed files with 27 additions and 26 deletions
|
@ -13,14 +13,10 @@ function core:OnInitialize()
|
|||
end
|
||||
|
||||
function core:OnEnable()
|
||||
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
|
||||
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
|
||||
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
|
||||
|
||||
self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels');
|
||||
if(core.firstrun) then
|
||||
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','SetupChatSaver');
|
||||
end
|
||||
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','ProcessChannelChanges');
|
||||
end
|
||||
|
||||
function core:SlashCommand()
|
||||
|
@ -28,6 +24,10 @@ function core:SlashCommand()
|
|||
end
|
||||
|
||||
function core:RejoinChannels(...)
|
||||
if(core.firstrun) then
|
||||
core:SetupChatSaver();
|
||||
end
|
||||
|
||||
local currentChannels = {};
|
||||
for i = 1,select('#',GetChannelList()) do
|
||||
currentChannels[select(i,GetChannelList())] = true
|
||||
|
@ -45,7 +45,7 @@ function core:RejoinChannels(...)
|
|||
self:UnregisterEvent('CHANNEL_UI_UPDATE');
|
||||
end
|
||||
|
||||
function core:SetupChatSaver(...)
|
||||
function core:SetupChatSaver()
|
||||
for frame = 1,NUM_CHAT_WINDOWS do
|
||||
local chatWindowChannels = { GetChatWindowChannels(frame) };
|
||||
for i = 1,#chatWindowChannels,2 do
|
||||
|
@ -62,31 +62,32 @@ function core:SetupChatSaver(...)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
|
||||
end
|
||||
|
||||
function core:JoinChannel(msg)
|
||||
self.hooks[SlashCmdList].JOIN(msg);
|
||||
function core:ProcessChannelChanges(_,message,_,_,_,_,_,_,index,name,...)
|
||||
if(message == 'YOU_JOINED') then
|
||||
local zone = 1;
|
||||
for frame = 1,NUM_CHAT_WINDOWS do
|
||||
local chatWindowChannels = { GetChatWindowChannels(frame) };
|
||||
for i = 1,#chatWindowChannels,2 do
|
||||
if(chatWindowChannels[i] == name) then
|
||||
print(chatWindowChannels[i],chatWindowChannels[i + 1]);
|
||||
zone = chatWindowChannels[i + 1];
|
||||
break;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local name = gsub(msg, "%s*([^%s]+).*", "%1");
|
||||
|
||||
if(strlen(name) > 0 and string.match(name,"%a+")) then
|
||||
if(zone == 0) then
|
||||
ChatSaverDB[name] = {};
|
||||
ChatSaverDB[name]['frames'] = {};
|
||||
ChatSaverDB[name]['index'] = GetChannelName(name);
|
||||
ChatSaverDB[name]['index'] = index;
|
||||
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true;
|
||||
end
|
||||
end
|
||||
|
||||
function core:LeaveChannel(msg)
|
||||
self.hooks[SlashCmdList].LEAVE(msg);
|
||||
|
||||
local number = gsub(msg, "%s*([^%s]+).*", "%1");
|
||||
local _,name = GetChannelName(number);
|
||||
|
||||
elseif(message == 'YOU_LEFT') then
|
||||
ChatSaverDB[name] = nil;
|
||||
end
|
||||
end
|
||||
|
||||
function core:ToggleChatChannel(checked,channel)
|
||||
if(ChatSaverDB[channel] == nil) then
|
||||
|
|
Loading…
Reference in a new issue