[Glitch] Add fallback to Object intent for FEP-3b86 in remote interaction helper
Port 9916c786e67080e71b6f8fc36d11f5d8daa233d9 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
a76ee2e233
commit
0dddc44eb5
@ -39,26 +39,27 @@ const findLink = (rel: string, data: unknown): JRDLink | undefined => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const intentParams = (intent: string) => {
|
const intentParams = (intent: string): [string, string] | null => {
|
||||||
switch (intent) {
|
switch (intent) {
|
||||||
case 'follow':
|
case 'follow':
|
||||||
return ['https://w3id.org/fep/3b86/Follow', 'object'] as [string, string];
|
return ['https://w3id.org/fep/3b86/Follow', 'object'];
|
||||||
case 'reblog':
|
case 'reblog':
|
||||||
return ['https://w3id.org/fep/3b86/Announce', 'object'] as [
|
return ['https://w3id.org/fep/3b86/Announce', 'object'];
|
||||||
string,
|
|
||||||
string,
|
|
||||||
];
|
|
||||||
case 'favourite':
|
case 'favourite':
|
||||||
return ['https://w3id.org/fep/3b86/Like', 'object'] as [string, string];
|
return ['https://w3id.org/fep/3b86/Like', 'object'];
|
||||||
case 'vote':
|
case 'vote':
|
||||||
case 'reply':
|
case 'reply':
|
||||||
return ['https://w3id.org/fep/3b86/Object', 'object'] as [string, string];
|
return ['https://w3id.org/fep/3b86/Object', 'object'];
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const findTemplateLink = (data: unknown, intent: string) => {
|
const findTemplateLink = (
|
||||||
|
data: unknown,
|
||||||
|
intent: string,
|
||||||
|
): [string, string] | [null, null] => {
|
||||||
|
// Find the FEP-3b86 handler for the specific intent
|
||||||
const [needle, param] = intentParams(intent) ?? [
|
const [needle, param] = intentParams(intent) ?? [
|
||||||
'http://ostatus.org/schema/1.0/subscribe',
|
'http://ostatus.org/schema/1.0/subscribe',
|
||||||
'uri',
|
'uri',
|
||||||
@ -66,14 +67,21 @@ const findTemplateLink = (data: unknown, intent: string) => {
|
|||||||
|
|
||||||
const match = findLink(needle, data);
|
const match = findLink(needle, data);
|
||||||
|
|
||||||
if (match) {
|
if (match?.template) {
|
||||||
return [match.template, param] as [string, string];
|
return [match.template, param];
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallback = findLink('http://ostatus.org/schema/1.0/subscribe', data);
|
// If the specific intent wasn't found, try the FEP-3b86 handler for the `Object` intent
|
||||||
|
let fallback = findLink('https://w3id.org/fep/3b86/Object', data);
|
||||||
|
if (fallback?.template) {
|
||||||
|
return [fallback.template, 'object'];
|
||||||
|
}
|
||||||
|
|
||||||
if (fallback) {
|
// If it's still not found, try the legacy OStatus subscribe handler
|
||||||
return [fallback.template, 'uri'] as [string, string];
|
fallback = findLink('http://ostatus.org/schema/1.0/subscribe', data);
|
||||||
|
|
||||||
|
if (fallback?.template) {
|
||||||
|
return [fallback.template, 'uri'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [null, null];
|
return [null, null];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user