mirror of
https://github.com/AMNatty/Mastodon-Circles.git
synced 2024-11-24 12:07:25 -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;
|
||||
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") ||
|
||||
software.name.includes("calckey") ||
|
||||
software.name.includes("foundkey") ||
|
||||
|
@ -219,7 +225,7 @@ class MastodonApiClient extends ApiClient {
|
|||
renotes: note["reblogs_count"] || 0,
|
||||
favorites: note["favourites_count"],
|
||||
// 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,
|
||||
author: user
|
||||
}));
|
||||
|
@ -259,7 +265,7 @@ class MastodonApiClient extends ApiClient {
|
|||
renotes: note["reblogs_count"] || 0,
|
||||
favorites: note["favourites_count"],
|
||||
// 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,
|
||||
author: {
|
||||
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 {
|
||||
/**
|
||||
* @param {string} instance
|
||||
|
@ -585,6 +645,9 @@ async function circleMain() {
|
|||
case "misskey":
|
||||
client = new MisskeyApiClient(selfUser.instance);
|
||||
break;
|
||||
case "fedibird":
|
||||
client = new FedibirdApiClient(selfUser.instance, true);
|
||||
break;
|
||||
default:
|
||||
progress.innerText = "Detecting 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="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="fedibird" autocomplete="off"> Fedibird API</label>
|
||||
</span>
|
||||
<br>
|
||||
<button type="submit" id="generateButton">Generate circle</button>
|
||||
|
@ -41,6 +42,7 @@
|
|||
</div>
|
||||
<br><br><br>
|
||||
<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>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>
|
||||
|
|
Loading…
Reference in a new issue