Mercurial > wow > squawk
comparison Squawk.lua @ 15:9e61a930b822
Modified the Model model for additional filters and subqueries
| author | wobin |
|---|---|
| date | Sat, 25 Apr 2009 21:42:27 +1000 |
| parents | 18c33a32ba31 |
| children | 6c28e55a00cf |
comparison
equal
deleted
inserted
replaced
| 14:18c33a32ba31 | 15:9e61a930b822 |
|---|---|
| 80 -- Guild open: you're not private, you broadcast to the guild your last X | 80 -- Guild open: you're not private, you broadcast to the guild your last X |
| 81 -- squawks on login | 81 -- squawks on login |
| 82 -- | 82 -- |
| 83 -- followers: | 83 -- followers: |
| 84 --]] | 84 --]] |
| 85 Model.Squawk = {} | 85 Model.Squawks = {} |
| 86 local Squawk = Model.Squawk | 86 local Squawks = Model.Squawks |
| 87 Squawks.Main = {} | |
| 88 Squawks.Owners = {} | |
| 89 | |
| 87 local function wrap(str, limit) | 90 local function wrap(str, limit) |
| 88 limit = limit or 72 | 91 limit = limit or 72 |
| 89 local here = 1 | 92 local here = 1 |
| 90 return str:gsub("(%s+)()(%S+)()", | 93 return str:gsub("(%s+)()(%S+)()", |
| 91 function(sp, st, word, fi) | 94 function(sp, st, word, fi) |
| 93 here = st | 96 here = st |
| 94 return "\n"..word | 97 return "\n"..word |
| 95 end | 98 end |
| 96 end) | 99 end) |
| 97 end | 100 end |
| 98 function Squawk:new(Message, Owner) | 101 |
| 102 function Squawks:new(Message, Owner) | |
| 99 local o = {} | 103 local o = {} |
| 100 o.Owner = Owner or UnitName("player") | 104 o.Owner = Owner or UnitName("player") |
| 101 o.Message = wrap(Message) | 105 o.Message = wrap(Message) |
| 102 o.Time = time() | 106 o.Time = time() |
| 103 local reply, to = strsplit("@", ((strsplit(" ", Message)))) | 107 local reply, to = strsplit("@", ((strsplit(" ", Message)))) |
| 110 for word in string.gmatch(Message, "@(%a+)") do | 114 for word in string.gmatch(Message, "@(%a+)") do |
| 111 if word ~= o.ReplyTo or "" then | 115 if word ~= o.ReplyTo or "" then |
| 112 table.insert(o.Related, word) | 116 table.insert(o.Related, word) |
| 113 end | 117 end |
| 114 end | 118 end |
| 119 | |
| 120 table.insert(self.Main, o) | |
| 121 | |
| 122 if not self.Owners[Owner] then | |
| 123 self.Owners[Owner] = {} | |
| 124 end | |
| 125 table.insert(self.Owners[Owner], o) | |
| 115 | 126 |
| 116 return o | 127 return o |
| 117 end | 128 end |
| 118 | 129 |
| 119 function Squawk:Sort(Squawks) | 130 function Squawks:Sort(Squawks) |
| 120 table.sort(Squawks, function(a,b) return a.Time > b.Time end) | 131 table.sort(Squawks or self.Main, function(a,b) return a.Time > b.Time end) |
| 121 return Squawks | 132 return Squawks or self.Main |
| 122 end | 133 end |
| 123 | 134 |
| 124 function Squawk:GetOwn(Squawks) | 135 function Squawks:GetOwn(Squawks) |
| 125 local mine = {} | 136 local mine = {} |
| 126 for _, squawk in ipairs(Squawks) do | 137 for _, squawk in ipairs(Squawks or self.Main) do |
| 127 if squawk.Owner == UnitName("player") then | 138 if squawk.Owner == UnitName("player") then |
| 128 table.insert(mine, squawk) | 139 table.insert(mine, squawk) |
| 129 end | 140 end |
| 130 end | 141 end |
| 131 return self:Sort(mine) | 142 return self:Sort(mine) |
| 132 end | 143 end |
| 133 | 144 |
| 134 function Squawk:GetLast10(Squawks) | 145 function Squawks:GetLast10(Squawks) |
| 135 local mine = {} | 146 local mine = {} |
| 147 Squawks = Squawks or self.Main | |
| 136 local limit = #Squawks < 10 and #Squawks or 10 | 148 local limit = #Squawks < 10 and #Squawks or 10 |
| 137 | 149 |
| 138 Squawks = Squawk:Sort(Squawks) | 150 Squawks = Squawk:Sort(Squawks) |
| 139 | 151 |
| 140 for i=1,limit do | 152 for i=1,limit do |
| 141 table.insert(mine, Squawks[i]) | 153 table.insert(mine, Squawks[i]) |
| 142 end | 154 end |
| 143 return mine | 155 return mine |
| 156 end | |
| 157 | |
| 158 -- initially called with no arguments to get the latest timestamp of | |
| 159 -- my squawks, or with a name to find the latest timestamp of all | |
| 160 -- squawks from that user | |
| 161 function Squawks:GetLatestTimestamp(Name, Squawks) | |
| 162 if Name then | |
| 163 if self.Owners[Name] then | |
| 164 return self:GetLatestTimestamp(nil, self.Owners[Name]) | |
| 165 else | |
| 166 return -1 -- No squawks exist for that name in our records | |
| 167 end | |
| 168 end | |
| 169 | |
| 170 Squawks = Squawks or self.Main or {} | |
| 171 local latest = self:Sort(Squawks) | |
| 172 return latest and #latest > 0 and latest[1].Time or -1 | |
| 173 end | |
| 174 | |
| 175 function Squawks:GetLatestSquawks(Timestamp) | |
| 176 local latest = {} | |
| 177 for i, squawk in ipairs(self:Sort()) do | |
| 178 if squawk.Time > Timestamp and i < 10 then | |
| 179 table.insert(latest, squawk) | |
| 180 else | |
| 181 return latest | |
| 182 end | |
| 183 end | |
| 144 end | 184 end |
| 145 | 185 |
| 146 function Settings:IsPrivate() | 186 function Settings:IsPrivate() |
| 147 return Settings.Private | 187 return Settings.Private |
| 148 end | 188 end |
| 352 function View:NotifyOfNewFollower(Name) | 392 function View:NotifyOfNewFollower(Name) |
| 353 self:Print(Name.." is now following you") | 393 self:Print(Name.." is now following you") |
| 354 end | 394 end |
| 355 | 395 |
| 356 function View:ShowMeMySquawks() | 396 function View:ShowMeMySquawks() |
| 357 for _,squawk in ipairs(Model.Squawks) do | 397 for _,squawk in ipairs(Model.Squawks.Main) do |
| 358 self:Print(squawk.Message) | 398 self:Print(squawk.Message) |
| 359 end | 399 end |
| 360 end | 400 end |
| 361 | 401 |
| 362 function View:ShowMeMyFollowers() | 402 function View:ShowMeMyFollowers() |
| 416 | 456 |
| 417 function LDBFeed:OnEnter() | 457 function LDBFeed:OnEnter() |
| 418 local tooltip = QTip:Acquire("Squawk",4, "LEFT", "LEFT", "LEFT", "RIGHT") | 458 local tooltip = QTip:Acquire("Squawk",4, "LEFT", "LEFT", "LEFT", "RIGHT") |
| 419 self.tooltip = tooltip | 459 self.tooltip = tooltip |
| 420 tooltip:AddHeader('Squawk') | 460 tooltip:AddHeader('Squawk') |
| 421 for i,squawk in ipairs(Squawk:GetLast10(Model.Squawks)) do | 461 for i,squawk in ipairs(Squawk:GetLast10()) do |
| 422 if #squawk.Message > 79 then | 462 if #squawk.Message > 79 then |
| 423 local head = true | 463 local head = true |
| 424 local message = {strsplit("\n",squawk.Message)} | 464 local message = {strsplit("\n",squawk.Message)} |
| 425 for _,line in ipairs(message) do | 465 for _,line in ipairs(message) do |
| 426 if head then | 466 if head then |
