mirror of
https://github.com/AMNatty/Mastodon-Circles.git
synced 2025-01-10 18:00:53 -07:00
Added Fedibird support
This commit is contained in:
parent
73bb66a3f1
commit
3e8d268d52
2 changed files with 67 additions and 2 deletions
|
@ -115,6 +115,12 @@ class ApiClient {
|
||||||
let { software } = apiResponse;
|
let { software } = apiResponse;
|
||||||
software.name = software.name.toLowerCase();
|
software.name = software.name.toLowerCase();
|
||||||
|
|
||||||
|
if (software.name.includes("fedibird")) {
|
||||||
|
const client = new FedibirdApiClient(instance, true);
|
||||||
|
instanceTypeCache.set(instance, client);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
if (software.name.includes("misskey") ||
|
if (software.name.includes("misskey") ||
|
||||||
software.name.includes("calckey") ||
|
software.name.includes("calckey") ||
|
||||||
software.name.includes("foundkey") ||
|
software.name.includes("foundkey") ||
|
||||||
|
@ -219,7 +225,7 @@ class MastodonApiClient extends ApiClient {
|
||||||
renotes: note["reblogs_count"] || 0,
|
renotes: note["reblogs_count"] || 0,
|
||||||
favorites: note["favourites_count"],
|
favorites: note["favourites_count"],
|
||||||
// Actually a Pleroma/Akkoma thing
|
// Actually a Pleroma/Akkoma thing
|
||||||
extra_reacts: note?.["pleroma"]?.["emoji_reactions"]?.length > 0,
|
extra_reacts: note?.["emoji_reactions"]?.length > 0 || note?.["pleroma"]?.["emoji_reactions"]?.length > 0,
|
||||||
instance: this._instance,
|
instance: this._instance,
|
||||||
author: user
|
author: user
|
||||||
}));
|
}));
|
||||||
|
@ -259,7 +265,7 @@ class MastodonApiClient extends ApiClient {
|
||||||
renotes: note["reblogs_count"] || 0,
|
renotes: note["reblogs_count"] || 0,
|
||||||
favorites: note["favourites_count"],
|
favorites: note["favourites_count"],
|
||||||
// Actually a Pleroma/Akkoma thing
|
// Actually a Pleroma/Akkoma thing
|
||||||
extra_reacts: note?.["pleroma"]?.["emoji_reactions"]?.length > 0,
|
extra_reacts: note?.["emoji_reactions"]?.length > 0 || note?.["pleroma"]?.["emoji_reactions"]?.length > 0,
|
||||||
instance: handle.instance,
|
instance: handle.instance,
|
||||||
author: {
|
author: {
|
||||||
id: note["account"]["id"],
|
id: note["account"]["id"],
|
||||||
|
@ -349,6 +355,60 @@ class PleromaApiClient extends MastodonApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FedibirdApiClient extends MastodonApiClient {
|
||||||
|
/**
|
||||||
|
* @param {string} instance
|
||||||
|
* @param {boolean} emoji_reacts
|
||||||
|
*/
|
||||||
|
constructor(instance, emoji_reacts) {
|
||||||
|
super(instance);
|
||||||
|
this._emoji_reacts = emoji_reacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFavs(note, extra_reacts) {
|
||||||
|
// Frdibird supports both favs and emoji reacts
|
||||||
|
// with several emoji reacts per users being possible.
|
||||||
|
// Coalesce them and count every user only once
|
||||||
|
let favs = await super.getFavs(note);
|
||||||
|
|
||||||
|
if (!this._emoji_reacts || !extra_reacts)
|
||||||
|
return favs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Map<string, FediUser>}
|
||||||
|
*/
|
||||||
|
let users = new Map();
|
||||||
|
if (favs !== null) {
|
||||||
|
favs.forEach(u => {
|
||||||
|
users.set(u.id, u);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `https://${this._instance}/api/v1/statuses/${note.id}/emoji_reactioned_by`;
|
||||||
|
const response = await apiRequest(url) ?? [];
|
||||||
|
|
||||||
|
for (const reaction of response) {
|
||||||
|
let account = reaction["account"];
|
||||||
|
let u = {
|
||||||
|
id: account["id"],
|
||||||
|
avatar: account["avatar"],
|
||||||
|
bot: account["bot"],
|
||||||
|
name: account["display_name"],
|
||||||
|
handle: parseHandle(account["acct"], note.instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!users.has(u.id))
|
||||||
|
users.set(u.id, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(users.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
getClientName() {
|
||||||
|
return "fedibird";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MisskeyApiClient extends ApiClient {
|
class MisskeyApiClient extends ApiClient {
|
||||||
/**
|
/**
|
||||||
* @param {string} instance
|
* @param {string} instance
|
||||||
|
@ -585,6 +645,9 @@ async function circleMain() {
|
||||||
case "misskey":
|
case "misskey":
|
||||||
client = new MisskeyApiClient(selfUser.instance);
|
client = new MisskeyApiClient(selfUser.instance);
|
||||||
break;
|
break;
|
||||||
|
case "fedibird":
|
||||||
|
client = new FedibirdApiClient(selfUser.instance, true);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
progress.innerText = "Detecting instance...";
|
progress.innerText = "Detecting instance...";
|
||||||
client = await ApiClient.getClient(selfUser.instance);
|
client = await ApiClient.getClient(selfUser.instance);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
<label><input type="radio" name="backend" value="mastodon" autocomplete="off"> Mastodon API</label>
|
<label><input type="radio" name="backend" value="mastodon" autocomplete="off"> Mastodon API</label>
|
||||||
<label><input type="radio" name="backend" value="misskey" autocomplete="off"> Misskey API</label>
|
<label><input type="radio" name="backend" value="misskey" autocomplete="off"> Misskey API</label>
|
||||||
<label><input type="radio" name="backend" value="pleroma" autocomplete="off"> Pleroma API</label>
|
<label><input type="radio" name="backend" value="pleroma" autocomplete="off"> Pleroma API</label>
|
||||||
|
<label><input type="radio" name="backend" value="fedibird" autocomplete="off"> Fedibird API</label>
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
<button type="submit" id="generateButton">Generate circle</button>
|
<button type="submit" id="generateButton">Generate circle</button>
|
||||||
|
@ -41,6 +42,7 @@
|
||||||
</div>
|
</div>
|
||||||
<br><br><br>
|
<br><br><br>
|
||||||
<div id="credits" style="width: 100%;">
|
<div id="credits" style="width: 100%;">
|
||||||
|
<p>Added Fedibird support by <a href="https://github.com/noellabo/Mastodon-Circles">noellabo</a> </p>
|
||||||
<p>Contribute on <a href="https://github.com/AMNatty/Mastodon-Circles">Github</a> </p>
|
<p>Contribute on <a href="https://github.com/AMNatty/Mastodon-Circles">Github</a> </p>
|
||||||
<p>Thanks to <a href="https://twitter.com/duiker101">Duiker101</a> for creating chirpty for Twitter</p>
|
<p>Thanks to <a href="https://twitter.com/duiker101">Duiker101</a> for creating chirpty for Twitter</p>
|
||||||
<p>Original on <a href="https://github.com/andigandhi/Mastodon-Circles">Github</a> </p>
|
<p>Original on <a href="https://github.com/andigandhi/Mastodon-Circles">Github</a> </p>
|
||||||
|
|
Loading…
Reference in a new issue