changeset 0:2c267c596711

First import Skeleton functionality, working on internals before anything
author wobin
date Thu, 16 Apr 2009 17:26:19 +1000
parents
children 188273d0efad
files .pkgmeta Squawk.lua Squawk.toc embeds.xml
diffstat 4 files changed, 217 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.pkgmeta	Thu Apr 16 17:26:19 2009 +1000
@@ -0,0 +1,10 @@
+package-as: Squawk
+
+externals:
+    Libs/LibStub: svn://svn.wowace.com/wow/ace3/mainline/trunk/LibStub
+    Libs/CallbackHandler-1.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/CallbackHandler-1.0
+    Libs/AceAddon-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0
+    Libs/AceConsole-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConsole-3.0
+    Libs/AceDB-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDB-3.0
+    Libs/AceEvent-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0
+    Libs/AceLocale-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceLocale-3.0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Squawk.lua	Thu Apr 16 17:26:19 2009 +1000
@@ -0,0 +1,181 @@
+-- A Twitter client of sorts for World of Warcraft
+-- Author: Wobin
+-- Email: wobster@gmail.com
+--
+Squawk = LibStub("AceAddon-3.0"):NewAddon("Squawk", "AceDB-3.0")
+
+Squawk.Model = {}
+Squawk.View = {}
+Squawk.Controller = {}
+
+local Model = Squawk.Model
+local View = Squawk.View
+local Controller = Squawk.Controller
+
+Model.UserSettings = {}
+local Settings = Model.UserSettings
+
+local defaults = {
+	profile = {
+		Squawks = {},
+		Follower = {},
+		Following = {},
+		Blocked = {},
+	}
+}
+
+function Squawk:OnInitialize()
+	Model.db = LibStub("AceDB-3.0"):New("SquawkDB", defaults)
+	Settings.Follower = Model.db.profile.Follower
+	Settings.Following = Model.db.profile.Following
+	Settings.Blocked = Model.db.profile.Blocked
+	Settings.Private = Model.db.profile.Private
+	
+	LibStub("AceComm-3.0"):Embed(Controller)
+	Controller:RegisterComm("Squawk", ReceiveMessage)
+end
+
+-- Model --
+--[[
+--Each Squawk will have the following information:
+-- * Owner (Name)
+-- * Time (Epoch)
+-- * Message (140 characters)
+-- * ReplyTo (Name)
+-- * Related (Names)
+--
+-- Each User will have the following lists:
+-- * Follower
+-- * Following
+-- * Blocked
+-- * Privacy State
+--]]
+Model.Squawk = {}
+local Squawk = Model.Squawk
+
+function Squawk:new(Message, Owner)
+	local o = {}
+	o.Owner = Owner or UnitName("player")
+	o.Message = Message
+	o.Time = os.time()
+	local reply, to = strsplit("@", ((strsplit(" ", Message))))
+	if reply == "" then
+		o.ReplyTo = to
+	end
+
+	o.Related = {}
+
+	for word in string.gmatch(Message, "@(%a+)") do
+		if word ~= o.ReplyTo or "" then
+			table.insert(o.Related, word)
+		end
+	end
+
+	return o
+end
+
+function Squawk:Sort(Squawks)
+	return table.sort(Squawks, function(a,b) return a.Time < b.Time end)
+end
+
+function Settings:IsPrivate()
+	return Settings.Private
+end
+
+function Settings:AddFollower(Name)
+	table.insert(Settings.Follower, Name)
+end
+
+function Settings:AddFollowing(Name)
+	table.insert(Settings.Following, Name)
+end
+
+function Settings:AddBlock(Name)
+	table.insert(Settings.Blocked, Name)
+end
+
+function Settings:RemoveFollower(Name)
+	for i,v in ipairs(Settings.Follower) do
+		if v == Name then
+			table.remove(Settings.Follower, i)
+			return
+		end
+	end
+end
+
+function Settings:RemoveFollowing(Name)
+	for i,v in ipairs(Settings.Following) do
+		if v == Name then
+			table.remove(Settings.Following, i)
+			return
+		end
+	end
+end
+
+function Settings:RemoveBlock(Name)
+	for i,v in ipairs(Settings.Blocked) do
+		if v == Name then
+			table.remove(Settings.Blocked, i)
+			return
+		end
+	end
+end
+
+--Controller--
+
+function Controller:TheyWantToFollowMe(Name)
+	if Settings:IsPrivate() then
+		self:PutForwardFollowRequest(Name)
+		self:SendMessageToTarget(Name, "#Pending|"..UnitName("player"))
+	else
+		Settings:AddFollower(Name)
+		View:NotifyOfNewFollower(Name)
+		self:SendMessageToTarget(Name, "#Follow|"..UnitName("player"))
+	end
+end
+
+function Controller:IWantToFollowThem(Name)
+
+end
+
+function Controller:IAmNowFollowingThem(Name)
+	Settings:AddFollowing(Name)
+	View:NotifyOfNewFollowing(Name)
+end
+
+function Controller:AddANewSquawk(Name, Message)
+	table.insert(Model.db.Squawks, Squawk:new(Message, Name))
+	View:UpdateSquawkList()
+end
+
+function Controller:SendMessageToTarget(Name, Message)
+	self:SendCommMessage("Squawk", Message, "WHISPER", Name, "BULK")
+end
+
+function Controller:SendMessageToGuild(Message)
+	self:SendCommMessage("Squawk", Message, "GUILD")
+end
+
+local Parse = { 
+		["#Pending"] = View:NotifyOfPending,
+		["#Follow"] = Controller:IAmNowFollowingThem,
+		["#Squawk"] = Controller:AddANewSquawk
+	}
+
+function Controller:ReceiveMessage(Prefix, Message, Distribution, Sender)
+	local command, name, info = strsplit("|",Message)
+	Parse[command](name, info)
+end
+-- View --
+
+function View:UpdateSquawkList()
+end
+
+function View:NotifyOfPending()
+end
+
+function View:NotifyOfNewFollowing(Name)
+end
+
+function View:NotifyOfNewFollower(Name)
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Squawk.toc	Thu Apr 16 17:26:19 2009 +1000
@@ -0,0 +1,15 @@
+## Interface: 30000
+## Title: Squawk
+## Author: Wobin
+## Notes: In no way related to a Twitter client... *shifty look*
+## Version: 8
+## X-Category: Chat & Communication
+## LoadOnDemand: 0
+## SavedVariables: SquawkDB
+## OptionalDeps: Ace3
+
+embeds.xml
+
+Locale\Localization.enUS.lua
+
+Squawk.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/embeds.xml	Thu Apr 16 17:26:19 2009 +1000
@@ -0,0 +1,11 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
+..\FrameXML\UI.xsd">
+	<Script file="Libs\Ace3\LibStub\LibStub.lua"/>
+	<Include file="Libs\Ace3\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
+	<Include file="Libs\Ace3\AceTimer-3.0\AceTimer-3.0.xml"/>
+	<Include file="Libs\Ace3\AceEvent-3.0\AceEvent-3.0.xml"/>
+	<Include file="Libs\Ace3\AceLocale-3.0\AceLocale-3.0.xml"/>
+	<Include file="Libs\Ace3\AceConsole-3.0\AceConsole-3.0.xml"/>
+	<Include file="Libs\Ace3\AceDB-3.0\AceDB-3.0.xml"/>
+	<Include file="Libs\Ace3\AceAddon-3.0\AceAddon-3.0.xml"/>
+</Ui>