parsav  Diff

Differences From Artifact [9997258dca]:

To Artifact [91a054f52e]:


     1      1   -- vim: ft=terra
     2         -local modes = lib.enum {'follow','mutual','srvlocal','fediglobal','circle'}
            2  +local pstr = lib.str.t
            3  +local modes = lib.enum [[follow mutual local fedi circle]]
            4  +local terra 
            5  +requires_login(m: modes.t): bool
            6  +	return m == modes.follow
            7  +	    or m == modes.mutual
            8  +	    or m == modes.circle
            9  +end
           10  +
     3     11   local terra 
     4     12   render_timeline(co: &lib.srv.convo, modestr: lib.mem.ref(int8))
     5         -	var mode = modes.srvlocal
           13  +	var mode = modes.follow
     6     14   	var circle: uint64 = 0
     7         -	-- if     modestr:cmpl('local') then mode = modes.srvlocal
     8         -	-- elseif modestr:cmpl('mutual') then mode = modes.mutual
     9         -	-- elseif modestr:cmpl('global') then mode = modes.fediglobal
    10         -	-- elseif modestr:cmpl('circle') then mode = modes.circle
    11         -	-- end
           15  +	if     modestr:cmp('local') then mode = [modes['local']]
           16  +	elseif modestr:cmp('mutual') then mode = modes.mutual
           17  +	elseif modestr:cmp('fedi') then mode = modes.fedi
           18  +	elseif modestr:cmp('circle') then mode = modes.circle
           19  +	end
           20  +	if requires_login(mode) and co.aid == 0 then mode = [modes['local']] end
           21  +
    12     22   
    13     23   	var stoptime = lib.osclock.time(nil)
    14     24   
    15     25   	var posts = [lib.mem.vec(lib.mem.ptr(lib.store.post))] { 
    16     26   		sz = 0, run = 0
    17     27   	}
    18         -	if mode == modes.follow then
    19         -	elseif mode == modes.srvlocal then
    20         -		posts = co.srv:timeline_instance_fetch(lib.store.range {
    21         -			mode = 1; -- T->I
    22         -			from_time = stoptime;
    23         -			to_idx = 64;
    24         -		})
    25         -	elseif mode == modes.fediglobal then
           28  +	var fetchmode = lib.store.range {
           29  +		mode = 1; -- T->I
           30  +		from_time = stoptime;
           31  +		to_idx = 64;
           32  +	}
           33  +	if mode == modes.follow or mode == modes.mutual then
           34  +		posts = co.srv:timeline_actor_fetch_uid(co.who.id,fetchmode)
           35  +	elseif mode == [modes['local']] then
           36  +		posts = co.srv:timeline_instance_fetch(fetchmode)
           37  +	elseif mode == modes.fedi then
    26     38   	elseif mode == modes.circle then
    27     39   	end
    28     40   
    29     41   	var acc = co:stra(1024)
           42  +	var modelabels = arrayof(pstr, 'followed', 'mutuals', 'local instance', 'fediverse', 'circle')
           43  +	var modelinks = arrayof(pstr, [modes.members])
           44  +	acc:lpush('<div style="text-align: right"><em>showing ')
           45  +	for i=0, [modelabels.type.N] do
           46  +		if co.aid ~= 0 or not requires_login(i) then
           47  +			if i > 0 then acc:lpush(' ยท ') end
           48  +			if i == mode then
           49  +				acc:lpush('<strong>'):ppush(modelabels[i]):lpush('</strong>')
           50  +			else
           51  +				acc:lpush('<a href="/tl/'):ppush(modelinks[i]):lpush('">'):ppush(modelabels[i]):lpush('</a>')
           52  +			end
           53  +		end
           54  +	end
           55  +	acc:lpush('</em></div>')
    30     56   	acc:lpush('<div id="tl" data-live="10">')
    31     57   	var newest: lib.store.timepoint = 0
    32     58   	for i = 0, posts.sz do
           59  +		if mode == modes.mutual and posts(i).ptr.author ~= co.who.id then
           60  +			var author = co:uid2actor(posts(i).ptr.author)
           61  +			if not author.relationship.recip.follow() then goto skip end
           62  +		end
    33     63   		lib.render.tweet(co, posts(i).ptr, &acc)
    34     64   		var t = lib.math.biggest(lib.math.biggest(posts(i).ptr.posted, posts(i).ptr.discovered),posts(i).ptr.edited)
    35     65   		if t > newest then newest = t end
    36         -		posts(i):free()
           66  +		::skip:: posts(i):free()
    37     67   	end
    38         -	posts:free()
           68  +	if posts.run > 0 then posts:free() end
    39     69   	acc:lpush('</div>')
    40     70   
    41     71   	var doc = [lib.srv.convo.page] {
    42     72   		title = 'timeline';
    43     73   		body = acc:finalize();
    44     74   		class = 'timeline';
    45     75   		cache = false;
    46     76   	}
    47     77   	co:livepage(doc,newest)
    48     78   	--doc.body:free()
    49     79   end
    50     80   return render_timeline