Friendiiverse/App/Main.js

190 lines
4.4 KiB
JavaScript
Raw Normal View History

2023-04-23 19:46:01 +02:00
var Persist = {Servers: {}, Sources: {}, Identities: {},};
var Present = CopyObj(Persist);
2023-04-22 17:09:59 +02:00
var Tasker = {};
2023-04-23 19:46:01 +02:00
var ApiCache = {Urls: {},};
2023-04-19 00:16:35 +02:00
2023-04-24 15:03:51 +02:00
Assets._ = function _(Name) {
if (Name in Assets) {
if (Assets[Name].startsWith('data:')) {
return Assets[Name];
} else {
return `./Assets/${Assets[Name]}`;
};
};
};
function DoAsync(First, Then, Data) {
var Job = RndId();
2023-04-22 17:09:59 +02:00
Tasker[Job] = {
Remains: 0,
Return(Data) {
this.Remains -= 1;
this.Result = Data;
},
2023-04-19 00:16:35 +02:00
};
// Call all First functs
2023-04-19 12:18:14 +02:00
ForceList(First).forEach(function(Fun, Data){
var Task = RndId();
var Proc = [Job, Task];
2023-04-22 17:09:59 +02:00
Tasker[Job][Task] = {};
Tasker[Job].Remains += 1;
//Fun(Proc, Data);
Data ? Fun(Data, Proc) : Fun(Proc);
2023-04-19 12:18:14 +02:00
});
// Continuosly check when First functs completed
2023-04-22 17:09:59 +02:00
Tasker[Job].Interval = setInterval(function(Job, Then){
if (Tasker[Job].Remains <= 0) {
clearInterval(Tasker[Job].Interval);
// Call all Then functs
2023-04-19 12:18:14 +02:00
ForceList(Then).forEach(function(Fun){
2023-04-22 17:09:59 +02:00
Fun(Tasker[Job].Result);
2023-04-19 12:18:14 +02:00
});
2023-04-22 17:09:59 +02:00
delete Tasker[Job];
2023-04-19 12:18:14 +02:00
};
}, 50, Job, Then);
return Job;
2023-04-19 12:18:14 +02:00
};
2023-04-22 17:09:59 +02:00
function DisplayProfile(Profile) {
var Window = MakeWindow({className: "Profile"});
2023-04-22 10:06:31 +02:00
Window.innerHTML += `<div class="" style="display: inline-block;">
2023-04-22 17:09:59 +02:00
<a href="${Profile.Url}">
2023-04-22 10:06:31 +02:00
<div>
2023-04-22 17:09:59 +02:00
<img class="" src="${Profile.Banner}"/>
2023-04-22 10:06:31 +02:00
</div>
<div>
2023-04-22 17:09:59 +02:00
<img class="" src="${Profile.Icon}"/>
${Profile.Name}
2023-04-22 10:06:31 +02:00
</div>
</a>
</div>`;
2023-04-23 19:46:01 +02:00
DoAsync(FetchMastodon, FillTimeline, Profile);
};
function FetchNotes(Profile, Proc) {
2023-04-20 22:08:38 +02:00
};
2023-04-19 00:16:35 +02:00
2023-04-19 12:18:14 +02:00
function FetchMastodon(Proc) {
2023-04-20 15:17:00 +02:00
if (UseFakeApi) {
ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc});
} else {
ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: ResFetchMastodon}, Proc);
};
2023-04-19 00:16:35 +02:00
};
2023-04-20 18:13:47 +02:00
function ResFetchMastodon(Res) {
2023-04-23 00:48:14 +02:00
var Notes = ApiTransform(Res.responseJson, 'Mastodon', 'Note');
2023-04-20 18:13:47 +02:00
LogDebug(Notes, 'l');
2023-04-22 17:09:59 +02:00
Tasker[Res.Proc[0]].Return(Notes);
2023-04-20 18:13:47 +02:00
};
2023-04-19 00:16:35 +02:00
function FillTimeline(Notes) {
Notes.forEach(function(Note){
2023-04-22 17:09:59 +02:00
Root.lastChild.innerHTML += `<div class="View Note">
2023-04-23 19:46:01 +02:00
<a href="${Note.Profile.Url}" onclick="DisplayProfile(ApiCache.Urls['${Note.Profile.Url}']); return false;">
2023-04-22 17:09:59 +02:00
<img class="Profile Icon" src="${Note.Profile.Icon}"/>
${Note.Profile.Name}
2023-04-20 00:19:19 +02:00
</a>
2023-04-19 00:16:35 +02:00
${Note.Content}
2023-04-20 15:17:00 +02:00
<a href="${Note.Url}">${Note.Time}</a>
2023-04-19 00:16:35 +02:00
</div>`;
});
};
2023-04-20 18:13:47 +02:00
function FetchFeatured(Proc) {
//if (UseFakeApi) {
2023-04-22 17:09:59 +02:00
var Featured = FakeApi.Friendiiverse.Featured;
Object.values(Featured).forEach(function(Profiles){
Profiles.forEach(function(Profile){
2023-04-23 19:46:01 +02:00
ApiCache.Urls[Profile.Url] = Profile;
2023-04-22 17:09:59 +02:00
});
});
Tasker[Proc[0]].Return(Featured);
2023-04-20 18:13:47 +02:00
//} else {
//};
};
function FillFeatured(Categories) {
2023-04-20 22:08:38 +02:00
var Window = MakeWindow({className: "Gallery"});
2023-04-22 17:09:59 +02:00
Object.values(Categories).forEach(function(Profiles){
Profiles.forEach(function(Profile){
Window.innerHTML += `<div>
2023-04-23 19:46:01 +02:00
<a href="${Profile.Url}" onclick="DisplayProfile(ApiCache.Urls['${Profile.Url}']); return false;">
2023-04-20 22:08:38 +02:00
<div>
2023-04-22 17:09:59 +02:00
<img src="${Profile.Banner}"/>
2023-04-20 22:08:38 +02:00
</div>
<div>
2023-04-22 17:09:59 +02:00
<img src="${Profile.Icon}"/>
${Profile.Name}
2023-04-20 22:08:38 +02:00
</div>
2023-04-20 18:13:47 +02:00
</a>
</div>`;
});
});
};
2023-04-20 22:08:38 +02:00
/*
2023-04-19 00:16:35 +02:00
PlazasView.innerHTML = `
<div>
<h3>Featured</h3>
<ul>
<li onclick="DisplayFriendicaTimeline('statuses/networkpublic_timeline');">Federation</li>
<li onclick="DisplayFriendicaTimeline('statuses/public_timeline');">${FriendicaUrl}</li>
<li onclick="DoAsync(FetchMastodon, FillTimeline);">
<img src=""/>
${MastodonUrl}
</li>
2023-04-19 00:16:35 +02:00
</ul>
</div>
`;
2023-04-20 22:08:38 +02:00
*/
2023-04-20 18:13:47 +02:00
2023-04-23 00:48:14 +02:00
function ComposeNote() {
var Window = MakeWindow();
Window.innerHTML += `
<h2>Compose</h2>
2023-04-23 19:46:01 +02:00
<p>Posting in: [Channel]</p>
2023-04-23 00:48:14 +02:00
<textarea style="width: 100%; height: 20em;"></textarea>
<p>
<button onclick="PostNote(this.parentNode.parentNode.querySelector('textarea').value);">Note!</button>
</p>
`;
};
function PostNote(Text) {
Obj = ExtrimObj(ApiSchema.Note);
2023-04-23 19:46:01 +02:00
Obj.Content = Text;
// Find out current profile and destination channel to do a proper net request
};
function ManageSettings() {
MakeWindow().innerHTML = `
2023-04-24 15:03:51 +02:00
<h2>Settings</h2>
<h3>Misc</h3>
<p>
Language: ${Dropdown()}
</p>
<p>
Theme:
</p>
<p>
<label>Wait <input type="number"/> seconds after clicking send for a note to be sent</label>
</p>
<h3>Identities</h3>
...
<h3>Sources</h3>
...
<h3>Data</h3>
<p>
<button>Import User Data</button>
<button>Export User Data</button>
</p>
<p>
<label><input type="checkbox"/> Persist cache on app reload</label>
</p>
2023-04-23 19:46:01 +02:00
`;
2023-04-23 00:48:14 +02:00
};
2023-04-20 18:13:47 +02:00
DoAsync(FetchFeatured, FillFeatured);
2023-04-22 10:06:31 +02:00
CoverView.remove();