annotate 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
rev   line source
wobin@18 1 local Controller = Squawk.Controller
wobin@18 2 local Model = Squawk.Model
wobin@18 3 local View = Squawk.View
wobin@18 4 local Settings = Model.UserSettings
wobin@18 5 local Squawks = Model.Squawks
wobin@18 6
wobin@18 7 --Controller--
wobin@18 8
wobin@18 9 function Controller:TheyWantToFollowMe(Name)
wobin@18 10 if Settings:IsPrivate() then
wobin@18 11 Settings:AddPending(Name)
wobin@18 12 self:PutForwardFollowRequest(Name)
wobin@19 13 self:SendMessageToTarget(Name, "#Pending|"..self.Name)
wobin@18 14 else
wobin@18 15 Settings:AddFollower(Name)
wobin@18 16 View:NotifyOfNewFollower(Name)
wobin@19 17 self:SendMessageToTarget(Name, "#Follow|"..self.Name)
wobin@18 18 end
wobin@18 19 end
wobin@18 20
wobin@18 21 function Controller:TheyWantToUnfollowMe(Name)
wobin@18 22 Settings:RemoveFollower(Name)
wobin@18 23 end
wobin@18 24
wobin@18 25 function Controller:IWantToFollowThem(Name)
wobin@19 26 self:SendMessageToTarget(Name, "#Request|"..self.Name)
wobin@18 27 Settings:AddRequested(Name)
wobin@18 28 end
wobin@18 29
wobin@18 30 function Controller:IWantToUnfollowThem(Name)
wobin@18 31 Settings:RemoveFollowing(Name)
wobin@19 32 self:SendMessageToTarget(Name, "#Unfollow|"..self.Name)
wobin@18 33 View:NotifyOfUnfollowing(Name)
wobin@18 34 end
wobin@18 35
wobin@18 36 function Controller:IAmNowFollowingThem(Name)
wobin@18 37 Settings:AddFollowing(Name)
wobin@18 38 View:NotifyOfNewFollowing(Name)
wobin@18 39 end
wobin@18 40
wobin@19 41 function Controller:AddANewSquawk(Name, Class, Message, Reply, Source)
wobin@18 42 if not Settings.Blocked[Name] then
wobin@18 43
wobin@18 44 if Source == "WHISPER" then
wobin@18 45 if Settings.Requested[Name] then -- We've been approved offline!
wobin@18 46 Settings:AddFollowing(Name)
wobin@18 47 end
wobin@18 48
wobin@18 49 if not Settings.Following[Name] then -- If we're no longer following this person
wobin@19 50 self:SendMessageToTarget(Name, "#Unfollow|"..self.Name)
wobin@18 51 return
wobin@18 52 end
wobin@18 53 end
wobin@18 54
wobin@19 55 if Source == "GUILD" and Name == self.Name then
wobin@18 56 return
wobin@18 57 end
wobin@18 58
wobin@19 59 table.insert(Model.Squawks, Squawks:new(Message, Name, Class, Reply))
wobin@19 60 --View:UpdateSquawkList()
wobin@18 61 end
wobin@18 62 end
wobin@18 63
wobin@18 64 local trigger
wobin@18 65 local function RepressFailure(frame, event, ...)
wobin@18 66 if arg1:match(string.gsub(ERR_CHAT_PLAYER_NOT_FOUND_S, "%%s", "(.*)")) then
wobin@18 67 if trigger then Controller:CancelTimer(trigger, true) end
wobin@18 68 trigger = Controller:ScheduleTimer(
wobin@18 69 function()
wobin@18 70 ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure)
wobin@18 71 end, 3) -- Give it three seconds and then remove the filter.
wobin@18 72 return true
wobin@18 73 else
wobin@18 74 return false, unpack(...)
wobin@18 75 end
wobin@18 76 end
wobin@18 77
wobin@19 78 function Controller:SendNewSquawk(Message, ReplyStamp)
wobin@18 79 if not Settings:IsPrivate() then
wobin@19 80 self:SendMessageToGuild("#Squawk|"..self.Name.."|"..self.Class.."|"..ReplyStamp or "".."|"..Message)
wobin@18 81 end
wobin@18 82
wobin@19 83 self:AddANewSquawk(self.Name, self.Class, Message, ReplyStamp)
wobin@18 84 for name, _ in pairs(Settings.Following) do
wobin@19 85 self:SendMessageToTarget(name, "#Squawk|"..self.Name.."|"..self.Class.."|"..ReplyStamp or "".."|"..Message)
wobin@18 86 end
wobin@18 87 end
wobin@18 88
wobin@18 89 function Controller:ImPending(Name)
wobin@18 90 View:NotifyOfPending(Name)
wobin@18 91 end
wobin@18 92
wobin@18 93 function Controller:PutForwardFollowRequest(Name)
wobin@18 94 View:NotifyOfPendingRequest(Name)
wobin@18 95 end
wobin@18 96
wobin@18 97 function Controller:ApprovePendingRequest(Name)
wobin@18 98 Settings:AddFollower(Name)
wobin@18 99 View:NotifyOfNewFollower(Name)
wobin@19 100 self:SendMessageToTarget(Name, "#Follow|"..self.Name)
wobin@18 101 end
wobin@18 102
wobin@18 103
wobin@18 104
wobin@18 105 function Controller:SendMessageToTarget(Name, Message)
wobin@18 106 ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", RepressFailure)
wobin@18 107 self:SendCommMessage("Squawk", Message, "WHISPER", Name)
wobin@18 108 end
wobin@18 109
wobin@18 110 function Controller:SendMessageToGuild(Message)
wobin@18 111 self:SendCommMessage("Squawk", Message, "GUILD")
wobin@18 112 end
wobin@18 113
wobin@18 114 local Parse = {
wobin@18 115 ["#Pending"] = Controller.ImPending,
wobin@18 116 ["#Follow"] = Controller.IAmNowFollowingThem,
wobin@18 117 ["#Unfollow"] = Controller.TheyWantToUnfollowMe,
wobin@18 118 ["#Squawk"] = Controller.AddANewSquawk,
wobin@18 119 ["#Request"] = Controller.TheyWantToFollowMe,
wobin@18 120 }
wobin@18 121
wobin@18 122 function Controller:ReceiveMessage(Message, Distribution, Sender)
wobin@19 123 local command, name, class, reply, info = strsplit("|",Message)
wobin@19 124 Parse[command](Controller, name, class, reply, info, Distribution)
wobin@18 125 end
wobin@18 126