diff --git a/App/ApiTransform.js b/App/ApiTransform.js index a7dc94a..3e9c5b4 100644 --- a/App/ApiTransform.js +++ b/App/ApiTransform.js @@ -23,9 +23,11 @@ var TransSchemas = { var ApiSchema = { __All__: { - ServerSoftware: { //TODO: Handle this in JsonTransform - //Mastodon: {__Set__: "Mastodon"}, - //Misskey: {__Set__: "Misskey"}, + //ServerId: { + // __All__: "id", + //}, + // NOTE: objects that embed cross-server data (e.g. a renote), might get this value assigned wrong for our needs (???) + ServerSoftware: { __All__: {__EvalSet__: "TypeOld"}, }, }, @@ -70,6 +72,9 @@ var ApiSchema = { Mastodon: {__OldOr__: ["display_name", "title"]}, Misskey: "name", }, + //ServerUsername: { + // __All__: "username", + //}, Type: { // user, bot, group, channel:[normal, server] Mastodon: {__EvalSet__: ` if (TreeOld.bot) 'Bot'; @@ -90,12 +95,13 @@ var ApiSchema = { var ApiEndpoints = { FetchNotes: { Mastodon(Profile) { - return `GET api/v1/accounts/${Profile.Id}/statuses`; + // Must actually get the id by calling GET api/v1/accounts/lookup?acct=USERNAME, the provided one is glitchy + return `GET api/v1/accounts/${Profile.__TreeOld__.id}/statuses`; }, Misskey(Profile) { return { - Method: "POST api/users/show", - Data: {"username": Profile.Id}, + Method: "POST api/users/notes", + Data: {"userId": Profile.Id}, }; }, }, @@ -112,12 +118,36 @@ var ApiEndpoints = { }, }; +var WebEndpoints = { + Note: { + Misskey(Note) { + //return `SERVER_URL/notes/${Note.ServerId}`; + return `SERVER_URL/notes/${Note.__TreeOld__.id}`; + }, + }, + Profile: { + Misskey(Profile) { + var Host = Profile.__TreeOld__.host; + //return `SERVER_URL/@${Profile.ServerUsername}`; + return `SERVER_URL/@${Profile.__TreeOld__.username}`; + }, + }, +}; + function ApiTransform(Data, FromSource, DestType) { var DataFinal = JsonTransformB(Data, ApiSchema, ApiSchema[DestType], FromSource); LogDebug([Data, DestType, FromSource, DataFinal]); return DataFinal; }; +function GetWebUrl(Data, Type) { + return (TryStr(Data.Url) + ? Data.Url + : WebEndpoints[Type][Data.ServerSoftware](Data) + ); + //return Data.Url || WebEndpoints[Type][Data.ServerSoftware](Data); +}; + /* var TransParsers = { Mastodon: { diff --git a/App/Main.js b/App/Main.js index 84551eb..f4e2a87 100644 --- a/App/Main.js +++ b/App/Main.js @@ -13,8 +13,8 @@ Present.__Set__ = function __Set__() { }; var ApiCache = { - __Store__(Data, Path/*Key, Where*/) { - eval(`ApiCache.${Path} = Data;`); + __Store__(Data, Path) { + eval(`ApiCache${JPath(Path)} = Data;`); }, __UrlStore__(Data) { ApiCache.__Store__(Data, `Urls['${Data.Url}']`); @@ -92,7 +92,7 @@ function HtmlAssignPropper(El, Data) { var Val = eval(`Data.${Toks[1]}`); if (Val !== undefined) { if (Key === 'src') { - Val = MkUrl(Val); + Val = MkReqUrl(Val); }; El[Key] = Val; }; @@ -115,12 +115,11 @@ function TransNetCall(Data, FromSource, DestType, Proc) { function DisplayProfile(Profile) { Profile = UrlObj(Profile, DisplayProfile); - //if (Profile) { + if (Profile) { var Window = MkWindow({className: "Profile"}); Window.innerHTML += Templating.ViewProfile(Profile); - // TODO: Handle fetching notes of non-standard profiles like servers timelines DoAsync(FetchNotes, FillTimeline, Profile); - //}; + }; }; function FetchNotes(Profile, Proc) { @@ -158,7 +157,8 @@ function FillTimeline(Notes) { }; function DisplayThread(Note) { - + var Window = MkWindow({className: "Thread"}); + //Window.innerHTML += Templating.ViewNote(Note); }; function FillHome() { @@ -171,13 +171,7 @@ function FillHome() { ApiCache.Urls[Profile.Url] = Profile; var Rnd = RndHtmlId(); Window.querySelector('ul').innerHTML += `
  • - - -
    - - ${Profile.Url} -
    -
    + ${Templating.ViewProfile(Profile, {Name: Profile.Url})}
  • `; var Endp = ApiEndpoints.ServerInfo[Profile.ServerSoftware]; var Method = Endp.Method || Endp; diff --git a/App/Net.js b/App/Net.js index 91e5415..adb3da6 100644 --- a/App/Net.js +++ b/App/Net.js @@ -30,7 +30,7 @@ function NetCall(Data, Proc) { // Req.open(Method, `${FriendicaUrl}/api/${Endpoint}.json`, true); // Req.setRequestHeader('Authorization', `Basic ${btoa(FriendicaCredentials)}`); //}; - Req.open(Method, MkUrl(`${Data.Target}/${Endpoint}`), true); + Req.open(Method, MkReqUrl(`${Data.Target}/${Endpoint}`), true); Req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); _.forOwn(_.merge({"Content-Type": "application/json"}, Data.Headers), function(Val, Key) { Req.setRequestHeader(Key, Val); @@ -52,7 +52,7 @@ function IsHttpCodeGood(Code) { }; }; -function MkUrl(Url) { +function MkReqUrl(Url) { if (Url && !Url.toLowerCase().startsWith(HttpProxy)) { Url = HttpProxy + Url; }; diff --git a/App/Style.css b/App/Style.css index 93bb720..4c56cbf 100644 --- a/App/Style.css +++ b/App/Style.css @@ -63,6 +63,10 @@ img, video { margin: 12px; } +.View.Profile { + display: inline-block; +} + .Profile.Banner { width: 384px; } diff --git a/App/Templating.js b/App/Templating.js index 3c098e0..85dc910 100644 --- a/App/Templating.js +++ b/App/Templating.js @@ -1,24 +1,40 @@ var Templating = { - ViewNote(Note) { + ViewNote(Note, Override) { + Override = Override || {}; + //var Url = TryStr(Note.Url) || Note.ServerId; + var Url = Override.Url || GetWebUrl(Note, 'Note'); + //var ProfileUrl = TryStr(Note.Profile.Url) || Note.Profile.ServerUsername; + var ProfileUrl = Override.ProfileUrl || GetWebUrl(Note.Profile, 'Profile'); + //if (Note.Quoting) { + // //Note.Quoting.Profile.Url = TryStr(Note.Quoting.Profile.Url) || Note.Quoting.Profile.ServerUsername; + //}; return `
    - - + + ${Note.Profile.Name}
    ${Note.Content ? Note.Content : 'renoted:'} ${Note.Quoting ? Templating.ViewNote(Note.Quoting) : ''}
    - ${Note.Time} + + ${Note.Time} +
    `; }, - ViewProfile(Profile) { - return `
    - - + ViewProfile(Profile, Override) { + Override = Override || {}; + //var Url = TryStr(Profile.Url) || Profile.ServerUsername; + var Url = Override.Url || GetWebUrl(Profile, 'Profile'); + var Name = Override.Name || Profile.Name; + return `
    + +
    - - ${Profile.Name} + + + ${Name} +
    `; diff --git a/App/Utils.js b/App/Utils.js index d4fb273..7d9f7e9 100644 --- a/App/Utils.js +++ b/App/Utils.js @@ -42,8 +42,16 @@ function LogDebug(Data, Status) { }; }; -function IsObj(Item) { - return typeof(Item) === 'object'; +function TryStr(Val) { + if (typeof(Val) === 'string') { + return Val; + } else { + return false; + }; +}; + +function IsObj(Val) { + return typeof(Val) === 'object'; }; function ExtrimObj(Obj) { @@ -74,6 +82,14 @@ function UnB64Obj(Obj) { return JSON.parse(atob(Obj)); }; +function JPath(Path) { + Path = Path.trim(); + if (!(Path.startsWith('[') || Path.startsWith('.'))) { + Path = `.${Path}`; + }; + return Path; +}; + // https://stackoverflow.com/a/7616484 String.prototype.hashCode = function() { var hash = 0, i, chr;