Mercurial > wow > squawk
view Controller.lua @ 19:431f2fce08f2
Added in link stripping
Coloured class names
Reply to specific squawk
Related squawks fixed
new arrow to indicate reply
limit to 140 characters
author | wobin |
---|---|
date | Tue, 12 May 2009 00:57:59 +1000 |
parents | a3328fffef5c |
children |
line wrap: on
line source
local Controller = Squawk.Controller local Model = Squawk.Model local View = Squawk.View local Settings = Model.UserSettings local Squawks = Model.Squawks --Controller-- function Controller:TheyWantToFollowMe(Name) if Settings:IsPrivate() then Settings:AddPending(Name) self:PutForwardFollowRequest(Name) self:SendMessageToTarget(Name, "#Pending|"..self.Name) else Settings:AddFollower(Name) View:NotifyOfNewFollower(Name) self:SendMessageToTarget(Name, "#Follow|"..self.Name) end end function Controller:TheyWantToUnfollowMe(Name) Settings:RemoveFollower(Name) end function Controller:IWantToFollowThem(Name) self:SendMessageToTarget(Name, "#Request|"..self.Name) Settings:AddRequested(Name) end function Controller:IWantToUnfollowThem(Name) Settings:RemoveFollowing(Name) self:SendMessageToTarget(Name, "#Unfollow|"..self.Name) View:NotifyOfUnfollowing(Name) end function Controller:IAmNowFollowingThem(Name) Settings:AddFollowing(Name) View:NotifyOfNewFollowing(Name) end function Controller:AddANewSquawk(Name, Class, Message, Reply, Source) if not Settings.Blocked[Name] then if Source == "WHISPER" then if Settings.Requested[Name] then -- We've been approved offline! Settings:AddFollowing(Name) end if not Settings.Following[Name] then -- If we're no longer following this person self:SendMessageToTarget(Name, "#Unfollow|"..self.Name) return end end if Source == "GUILD" and Name == self.Name then return end table.insert(Model.Squawks, Squawks:new(Message, Name, Class, Reply)) --View:UpdateSquawkList() end end local trigger local function RepressFailure(frame, event, ...) if arg1:match(string.gsub(ERR_CHAT_PLAYER_NOT_FOUND_S, "%%s", "(.*)")) then if trigger then Controller:CancelTimer(trigger, true) end trigger = Controller:ScheduleTimer( function() ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure) end, 3) -- Give it three seconds and then remove the filter. return true else return false, unpack(...) end end function Controller:SendNewSquawk(Message, ReplyStamp) if not Settings:IsPrivate() then self:SendMessageToGuild("#Squawk|"..self.Name.."|"..self.Class.."|"..ReplyStamp or "".."|"..Message) end self:AddANewSquawk(self.Name, self.Class, Message, ReplyStamp) for name, _ in pairs(Settings.Following) do self:SendMessageToTarget(name, "#Squawk|"..self.Name.."|"..self.Class.."|"..ReplyStamp or "".."|"..Message) end end function Controller:ImPending(Name) View:NotifyOfPending(Name) end function Controller:PutForwardFollowRequest(Name) View:NotifyOfPendingRequest(Name) end function Controller:ApprovePendingRequest(Name) Settings:AddFollower(Name) View:NotifyOfNewFollower(Name) self:SendMessageToTarget(Name, "#Follow|"..self.Name) end function Controller:SendMessageToTarget(Name, Message) ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure) self:SendCommMessage("Squawk", Message, "WHISPER", Name) end function Controller:SendMessageToGuild(Message) self:SendCommMessage("Squawk", Message, "GUILD") end local Parse = { ["#Pending"] = Controller.ImPending, ["#Follow"] = Controller.IAmNowFollowingThem, ["#Unfollow"] = Controller.TheyWantToUnfollowMe, ["#Squawk"] = Controller.AddANewSquawk, ["#Request"] = Controller.TheyWantToFollowMe, } function Controller:ReceiveMessage(Message, Distribution, Sender) local command, name, class, reply, info = strsplit("|",Message) Parse[command](Controller, name, class, reply, info, Distribution) end