Use CHAT_MSG_CHANNEL_NOTICE instead of hooking join and leave slash functions for stored channels

This commit is contained in:
Andrew Tomaka 2011-06-01 14:25:42 -04:00
parent 0b51f257ed
commit aa65c554a3

View file

@ -13,14 +13,10 @@ function core:OnInitialize()
end end
function core:OnEnable() function core:OnEnable()
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
self:Hook('ToggleChatChannel','ToggleChatChannel',true); self:Hook('ToggleChatChannel','ToggleChatChannel',true);
self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels'); self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels');
if(core.firstrun) then self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','ProcessChannelChanges');
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','SetupChatSaver');
end
end end
function core:SlashCommand() function core:SlashCommand()
@ -28,6 +24,10 @@ function core:SlashCommand()
end end
function core:RejoinChannels(...) function core:RejoinChannels(...)
if(core.firstrun) then
core:SetupChatSaver();
end
local currentChannels = {}; local currentChannels = {};
for i = 1,select('#',GetChannelList()) do for i = 1,select('#',GetChannelList()) do
currentChannels[select(i,GetChannelList())] = true currentChannels[select(i,GetChannelList())] = true
@ -45,7 +45,7 @@ function core:RejoinChannels(...)
self:UnregisterEvent('CHANNEL_UI_UPDATE'); self:UnregisterEvent('CHANNEL_UI_UPDATE');
end end
function core:SetupChatSaver(...) function core:SetupChatSaver()
for frame = 1,NUM_CHAT_WINDOWS do for frame = 1,NUM_CHAT_WINDOWS do
local chatWindowChannels = { GetChatWindowChannels(frame) }; local chatWindowChannels = { GetChatWindowChannels(frame) };
for i = 1,#chatWindowChannels,2 do for i = 1,#chatWindowChannels,2 do
@ -62,32 +62,33 @@ function core:SetupChatSaver(...)
end end
end end
end end
self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
end end
function core:JoinChannel(msg) function core:ProcessChannelChanges(_,message,_,_,_,_,_,_,index,name,...)
self.hooks[SlashCmdList].JOIN(msg); 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(zone == 0) then
ChatSaverDB[name] = {};
if(strlen(name) > 0 and string.match(name,"%a+")) then ChatSaverDB[name]['frames'] = {};
ChatSaverDB[name] = {}; ChatSaverDB[name]['index'] = index;
ChatSaverDB[name]['frames'] = {}; ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true;
ChatSaverDB[name]['index'] = GetChannelName(name); end
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true; elseif(message == 'YOU_LEFT') then
ChatSaverDB[name] = nil;
end end
end end
function core:LeaveChannel(msg)
self.hooks[SlashCmdList].LEAVE(msg);
local number = gsub(msg, "%s*([^%s]+).*", "%1");
local _,name = GetChannelName(number);
ChatSaverDB[name] = nil;
end
function core:ToggleChatChannel(checked,channel) function core:ToggleChatChannel(checked,channel)
if(ChatSaverDB[channel] == nil) then if(ChatSaverDB[channel] == nil) then
return; return;