Commit 1c5538a2 authored by Chris Babcock's avatar Chris Babcock

Started base behaviors for AS Vocab

parent 6ae25cb2
......@@ -173,8 +173,10 @@ function as.date(o, t1)
return o
end
-- AS Core Object definitions
-- https://www.w3.org/TR/activitystreams-core/#model
-- AS Object definitions
-- Used in generating summaries
local who, what, didWhat, fromWhat, toWhat
as.Object = as:new()
as.Object.isObject = true
......@@ -184,13 +186,53 @@ as.Link.isLink = true
as.Activity = as.Object:new()
as.Activity.isActivity = true
as.Activity.action = "performed an activity"
function as.Activity.new(self, o, jsonIn)
o = as:new(o, jsonIn)
o = o[o.type]:buildSummary()
return o
end
function as.Activity.buildSummary(self)
if o.summary = nil then
if o.Actor and o.actor.name then
who = o.actor.name or o:getID("actor")
end
if o.object then
toWhat = o.object.name or o.object.summary or o:getID("object")
end
didWhat = self.action
end
if who and toWhat then
o.summary = string.format( "%s %s on %s", who, didWhat, toWhat )
end
who = nil
didWhat = nil
toWhat = nil
return o
end
as.IntransitiveActivity = as.Activity:new()
as.IntransitiveActivity.isIntransitiveActivity = true
function as.IntransitiveActivity.new(self, o, jsonIn)
o = as:new(o, jsonIn)
if o.summary = nil and o.actor then
who = o.actor.name or as.getID()
didWhat = self.action
if who and didWhat then
o.summary = string.format( "%s %s", who, didWhat )
end
who = nil
didWhat = nil
end
end
as.Collection = as.Object:new()
as.Collection.isCollection = true
as.Collection.items = {}
as.Collection.addTo = "items"
as.Collection.totalItems = 0
as.Collection.first = 0
as.Collection.last = 0
......@@ -200,23 +242,24 @@ function as.Collection:add(o)
-- Check that addition is well formed
if o.type then
local tmp = as[o.type]:new(o)
if tmp then
if tmp then
o = tmp
else
assert(o = as.Object:new(o))
o = as.Object:new(o)
else
assert(o = as.Object:new(o))
o = as.Object:new(o)
end
-- Increment totalItems
self.totalItems = self.totalItems + 1
-- Make new item last in list
self.last = as.getID(o) or o
-- Insert item at end of list
self.items[self.totalItems] = o
self[self.addTo][self.totalItems] = o
end
as.OrderedCollection = as.Collection:new()
as.OrderedCollection.isOrderedCollection = true
as.OrderedCollection.addTo = "orderedItems"
as.CollectionPage = as.Collection:new()
as.CollectionPage.isCollectionPage = true
......@@ -227,35 +270,93 @@ as.OrderedCollectionPage.isOrderedCollectionPage = true
as.Actor = as.Object:new()
as.Actor.isActor = true
function as.Actor.new(self, o, jsonIn)
o = as:new(o, jsonIn)
end
as.Accept = as.Activity:new()
as.Accept.action = "accepted"
as.Add = as.Activity:new()
as.Add.action = "added"
as.Announce = as.Activity:new()
as.Arrive = as.Activity:new()
as.Announce.action = "announced"
as.Arrive = as.IntransitiveActivity:new()
as.Arrive.action = "arrived"
as.Block = as.Activity:new()
as.Block.action = "blocked"
as.Create = as.Activity:new()
as.Create.action = "created"
as.Delete = as.Activity:new()
as.Delete.action = "deleted"
as.Dislike = as.Activity:new()
as.Dislike.action = "disliked"
as.Flag = as.Activity:new()
as.Flag.action = "flagged"
as.Follow = as.Activity:new()
as.Follow.action = "followed"
as.Ignore = as.Activity:new()
as.Invite = as.Activity:new()
as.Ignore.action = "ignored"
as.Invite = as.Offer:new()
as.Invite.action = "invited"
as.Join = as.Activity:new()
as.Join.action = "joined"
as.Leave = as.Activity:new()
as.Leave.action = "left"
as.Like = as.Activity:new()
as.Like.action = "liked"
as.Listen = as.Activity:new()
as.Listen.action = "listened"
as.Move = as.Activity:new()
as.Move.action = "moved"
as.Offer = as.Activity:new()
as.Offer.action = "offered"
as.Question = as.Activity:new()
as.Question.action = "asked"
as.Reject = as.Activity:new()
as.Reject.action = "rejected"
as.Read = as.Activity:new()
as.Read.action = "read"
as.Remove = as.Activity:new()
as.TentativeAccept = as.Activity:new()
as.TentativeReject = as.Activity:new()
as.Remove.action = "removed"
as.TentativeAccept = as.Accept:new()
as.TentativeAccept.action = "tentatively accepted"
as.TentativeReject = as.Reject:new()
as.TentativeReject.action = "tentatively rejected"
as.Travel = as.Activity:new()
as.Travel.action = "traveled"
as.Undo = as.Activity:new()
as.Undo.action = "undid"
as.Update = as.Activity:new()
as.Update.action = "updated"
as.View = as.Activity:new()
as.View.action = "viewed"
as.Application = as.Actor:new()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment