4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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 opdate = lib.conv.datetime(&co.srv.pool, p.posted)
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 = opdate, extra = '';
}):poolstr(&co.srv.pool)
if act_wrap then
return (wrap {
domain = co.srv.cfg.domain, obj = tweet;
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 = lib.trn(p.rtdby == 0, opdate,
lib.conv.datetime(&co.srv.pool,p.rtdat));
}):poolstr(&co.srv.pool)
else
return tweet
end
end
return lp_tweet
|
>
|
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
|
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
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",
"actor": "https://@+domain/user/@^uid",
"published": "@pubtime",
"sensitive": false,
"directMessage": false,
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"summary": @$subj
@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",
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"object": @obj
}]]
local terra
lp_tweet(co: &lib.srv.convo, p: &lib.store.post, act_wrap: bool): pstr
var opdate = lib.munge.datetime(&co.srv.pool, p.posted)
var extra: lib.str.acc extra:pool(&co.srv.pool,256)
if p.parent ~= 0 then
extra:lpush ',"inReplyTo":"'
var par = co.srv:post_fetch(p.parent)
if not par then
lib.warn('database integrity violation: broken parent reference')
else defer par:free()
if par().localpost then -- gen uri for parent
extra:lpush'https://':qpush(co.srv.cfg.domain):lpush'/post/':shpush(p.parent)
else extra:push(par().uri,0) end
end
extra:lpush'"'
end
extra:lpush ',"conversation":"'
if p.convoheaduri ~= nil then
extra:qpush(p.convoheaduri)
else
var cid: uint64 = 0
if p.parent ~= 0 then
var top = co.srv:thread_top_find(p.parent)
var tp = co.srv:post_fetch(top)
if not tp then
lib.warn('database integrity violation: missing thread parent')
cid = p.id
else
if tp().convoheaduri ~= nil then
extra:push(tp().convoheaduri,0)
elseif tp().localpost == false then
extra:push(tp().uri,0)
else cid = top end
end
else
cid = p.id
end
if cid ~= 0 then
extra:lpush'https://':qpush(co.srv.cfg.domain)
:lpush'/post/':shpush(cid):lpush'/tree'
end
end
extra:lpush'"'
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 = opdate, extra = extra:finalize();
subj = lib.trn(p.subject ~= nil, pstr(p.subject), pstr'');
}):poolstr(&co.srv.pool)
if act_wrap then
return (wrap {
domain = co.srv.cfg.domain, obj = tweet;
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 = lib.trn(p.rtdby == 0, opdate,
lib.munge.datetime(&co.srv.pool,p.rtdat));
}):poolstr(&co.srv.pool)
else
return tweet
end
end
return lp_tweet
|