comparison Controller.lua @ 18:a3328fffef5c

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