var Persist = {Servers: {}, Sources: {}, Identities: {},}; var Present = CopyObj(Persist); var Tasker = {}; var ApiCache = { __Store__(Data, Key, Where) { ApiCache[Where][Key] = Data; ApiCache[Where][Key].__Time__ = Date.now(); }, __UrlStore__(Data) { ApiCache.__Store__(Data, Data.Url, 'Urls'); }, Urls: {}, }; Assets._ = function _(Name) { if (Name in Assets) { if (Assets[Name].startsWith('data:')) { return Assets[Name]; } else { return `./Assets/${Assets[Name]}`; }; }; }; Strings._ = function _(Name) { // TODO: Handle arbitrary nestation if (Name in Strings) { if (Strings[Name]['en']) { // TODO{ Select this language from user config return Strings[Name]['en']; } else { return Strings[Name].en; }; }; }; function DoAsync(First, Then, Data) { var Job = RndId(); Tasker[Job] = { Remains: 0, Return(Data) { this.Remains -= 1; this.Result = Data; }, }; // Call all First functs ForceList(First).forEach(function(Fun){ var Task = RndId(); var Proc = [Job, Task]; Tasker[Job][Task] = {}; Tasker[Job].Remains += 1; //Fun(Proc, Data); Data ? Fun(Data, Proc) : Fun(Proc); }); // Continuosly check when First functs completed Tasker[Job].Interval = setInterval(function(Job, Then){ if (Tasker[Job].Remains <= 0) { clearInterval(Tasker[Job].Interval); // Call all Then functs ForceList(Then).forEach(function(Fun){ Fun(Tasker[Job].Result); }); delete Tasker[Job]; }; }, 50, Job, Then); return Job; }; function DisplayProfile(Profile) { var Window = MkWindow({className: "Profile"}); Window.innerHTML += `
${Profile.Name}
`; DoAsync(FetchNotes, FillTimeline, Profile); }; function DisplayMastodonTimeline(Data) { var Window = MkWindow(); Window.innerHTML += `
${Profile.Name}
`; DoAsync(FetchNotes, FillTimeline, Profile); }; function FetchNotes(Profile, Proc) { var Soft = Profile.__Software__; NetApiCall({Target: UrlBase(Profile.Url), Method: ApiEndpoints.FetchNotes['Mastodon'](Profile), CallFine: function(Res){ var Notes = ApiTransform(Res.responseJson, Soft, 'Note'); LogDebug(Notes, 'l'); Tasker[Res.Proc[0]].Return(Notes); }}, Proc); }; function FetchMastodon(Proc) { //if (UseFakeApi) { // ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); //} else { NetApiCall({Target: "Mastodon", Method: "GET timelines/public", CallFine: ResFetchMastodon}, Proc); //}; }; function ResFetchMastodon(Res) { var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note'); LogDebug(Notes, 'l'); Tasker[Res.Proc[0]].Return(Notes); }; function FillTimeline(Notes) { Notes.forEach(function(Note){ ApiCache.__UrlStore__(Note.Profile); Root.lastChild.innerHTML += `
${Note.Profile.Name} ${SanitizeHtml(Note.Content)} ${Note.Time}
`; }); }; function FetchFeatured(Proc) { //if (UseFakeApi) { var Featured = FakeApi.Friendiiverse.Featured; Object.values(Featured).forEach(function(Profiles){ Profiles.forEach(function(Profile){ ApiCache.Urls[Profile.Url] = Profile; }); }); Tasker[Proc[0]].Return(Featured); //} else { //}; }; function FillFeatured(Categories) { var Window = MkWindow({className: "Gallery"}); Object.values(Categories).forEach(function(Profiles){ Profiles.forEach(function(Profile){ Window.innerHTML += `
${Profile.Name}
`; }); }); }; /* PlazasView.innerHTML = `

Featured

`; */ function ComposeNote() { var Window = MkWindow(); Window.innerHTML += `

Compose

Posting in: [Channel]

`; }; function PostNote(Text) { Obj = ExtrimObj(ApiSchema.Note); Obj.Content = Text; // Find out current profile and destination channel to do a proper net request }; function ManageSettings() { MkWindow().innerHTML = `

Settings

Misc

Language: ${MkSelectMenu([{innerHTML: "en"}, {innerHTML: "it"},]).outerHTML}

Theme:

Identities

...

Sources

...

Data

`; }; DoAsync(FetchFeatured, FillFeatured); CoverView.remove();