can get some of the statusses
This commit is contained in:
parent
1fc5890ec6
commit
167126da9a
|
@ -55,7 +55,7 @@ const hour = 3600000;
|
|||
|
||||
// note: rejects on HTTP 4xx or 5xx
|
||||
async function apGet(url,ttl) {
|
||||
|
||||
console.log("apGet: ", url);
|
||||
return new Promise(function(resolve,reject){
|
||||
|
||||
// fail early
|
||||
|
@ -98,19 +98,22 @@ async function promiseSome(proms){
|
|||
}
|
||||
|
||||
module.exports = async function (opts) {
|
||||
console.log("opts:", opts);
|
||||
var opts = opts;
|
||||
|
||||
var feedUrl = opts.feedUrl;
|
||||
var userUrl = opts.userUrl;
|
||||
var isIndex = false;
|
||||
var isUser = new URL(userUrl).pathname.startsWith("/users/");
|
||||
opts.isUser = isUser;
|
||||
|
||||
console.log("opts:", opts);
|
||||
|
||||
if (!userUrl) {
|
||||
throw new Error('need user URL');
|
||||
}
|
||||
|
||||
var user, feed;
|
||||
|
||||
if (isUser) {
|
||||
// get user and feed in parallel if I have both URLs.
|
||||
// can cache feed aggressively since it is a specific start and end.
|
||||
if (userUrl && feedUrl){
|
||||
|
@ -128,17 +131,21 @@ module.exports = async function (opts) {
|
|||
} else {
|
||||
feed = await apGet(outbox.first, hour/6);// 10 mins. Because the base feed URL can get new toots quickly.
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
feed = await apGet(userUrl, hour/6);
|
||||
}
|
||||
|
||||
var templateData = {
|
||||
opts: opts,// from the request
|
||||
meta: metaForUser(user),
|
||||
meta: isUser ? metaForUser(user) : null,
|
||||
items: await itemsForFeed(opts,user,feed),
|
||||
nextPageLink: getNextPage(opts,user,feed),
|
||||
isIndex: isIndex
|
||||
};
|
||||
|
||||
console.log("templateData", templateData);
|
||||
|
||||
return template(templateData);
|
||||
}
|
||||
|
||||
|
@ -153,6 +160,35 @@ function metaForUser(user) {
|
|||
}
|
||||
|
||||
async function itemsForFeed(opts,user,feed) {
|
||||
if (feed.totalItems > 0 && typeof feed.orderedItems[0] != 'object') {
|
||||
// we only have urls
|
||||
feed.orderedItems = await promiseSome(
|
||||
feed.orderedItems.map(function(url){
|
||||
// we are getting objects of type note
|
||||
return apGet(url, hour).then(
|
||||
note => apGet(note.attributedTo).then(
|
||||
userdata => ({
|
||||
// build an announce object so we are compatible
|
||||
// this is likely to be a case for refatoring
|
||||
_userdata: userdata,
|
||||
type: "Announce",
|
||||
object: note,
|
||||
actor: note.attributedTo,
|
||||
to: note.to,
|
||||
cc: note.cc,
|
||||
published: note.published,
|
||||
id: note.id
|
||||
})
|
||||
));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
console.log("feed", feed);
|
||||
console.log("feed object", feed.orderedItems[0].object);
|
||||
console.log("feed context", feed.orderedItems[0]["@context"]);
|
||||
console.log("feed _userdata", feed.orderedItems[0]._userdata);
|
||||
|
||||
var items = feed.orderedItems;
|
||||
|
||||
if (opts.boosts){
|
||||
|
@ -196,7 +232,7 @@ async function itemsForFeed(opts,user,feed) {
|
|||
console.warn("warning: couldn't match boost to item: ",boostToot)
|
||||
return;
|
||||
}
|
||||
|
||||
boostToot._isBoost = true;
|
||||
boostToot.object = boostToot;// this lets the later stage parser access object without errors :)
|
||||
items[i] = boostToot;
|
||||
})
|
||||
|
@ -220,8 +256,8 @@ async function itemsForFeed(opts,user,feed) {
|
|||
var op = item._userdata?item._userdata:user;
|
||||
|
||||
return {
|
||||
isBoost:!!item._userdata,
|
||||
title:item._userdata?user.preferredUsername+' shared a status by '+op.preferredUsername:'',
|
||||
isBoost:item._isBoost,
|
||||
title:item._userdata && user?user.preferredUsername+' shared a status by '+op.preferredUsername:'',
|
||||
isReply:!!(item.object && item.object.inReplyTo),
|
||||
hasCw:item.object.sensitive||false,
|
||||
cw:item.object.summary,
|
||||
|
|
Loading…
Reference in New Issue