-- vim: ft=terra
local pstr = lib.str.t

local obj = lib.tpl.mk [[{
	"\@context": "https://@+domain/s/litepub.jsonld",
	"type": "Note",
	"id": "https://@+domain/post/@^pid",
	"content": @$html,
	"source": @$raw,
	"attributedTo": "https://@+domain/user/@^uid",
	"published": "@pubtime"
	@extra
}]]

local wrap = lib.tpl.mk [[{
	"\@context": "https://@+domain/s/litepub.jsonld",
	"type": "@kind",
	"actor": "https://@+domain/user/@^uid",
	"published": "@$pubtime",
	"id": "https://@+domain/api/lp/act/@^aid",
	"object": @obj
}]]

local terra 
lp_tweet(co: &lib.srv.convo, p: &lib.store.post, act_wrap: bool)
	
	var tweet = (obj {
		domain = co.srv.cfg.domain, uid = p.author, pid = p.id;
		html = lib.smackdown.html(&co.srv.pool, p.body, false);
		raw = p.body, pubtime = '', extra = '';
	}):poolstr(&co.srv.pool)

	if act_wrap then
		return (wrap {
			domain = co.srv.cfg.domain;
			kind = lib.trn(p.rtdby == 0, 'Create', 'Announce');
			uid = lib.trn(p.rtdby == 0, p.author, p.rtdby);
			aid = lib.trn(p.rtdby == 0, p.id, p.rtact);
			pubtime = '', obj = tweet;
		}):poolstr(&co.srv.pool)
	else
		return tweet
	end
end

return lp_tweet
