mirror of
https://github.com/dariusk/rss-to-activitypub.git
synced 2024-11-22 17:29:19 +02:00
Deliver messages to Pleroma inboxes correctly
This commit is contained in:
parent
e0dbc536dc
commit
753872d31d
|
@ -173,7 +173,7 @@ function signAndSend(message, name, domain, req, res, targetDomain, inbox) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMessage(text, name, domain, item) {
|
function createMessage(text, name, domain, item, follower) {
|
||||||
const guid = crypto.randomBytes(16).toString('hex');
|
const guid = crypto.randomBytes(16).toString('hex');
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
|
|
||||||
|
@ -184,6 +184,8 @@ function createMessage(text, name, domain, item) {
|
||||||
'type': 'Create',
|
'type': 'Create',
|
||||||
'actor': `https://${domain}/u/${name}`,
|
'actor': `https://${domain}/u/${name}`,
|
||||||
|
|
||||||
|
'to': [ follower ],
|
||||||
|
|
||||||
'object': {
|
'object': {
|
||||||
'id': `https://${domain}/${guid}`,
|
'id': `https://${domain}/${guid}`,
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
|
@ -196,8 +198,8 @@ function createMessage(text, name, domain, item) {
|
||||||
|
|
||||||
// add image attachment
|
// add image attachment
|
||||||
let attachment;
|
let attachment;
|
||||||
|
console.log('NUM IMAGES',item.urls.length);
|
||||||
if (item.urls.length > 0) {
|
if (item.urls.length > 0) {
|
||||||
//console.log('appending');
|
|
||||||
attachment = {
|
attachment = {
|
||||||
'type': 'Document',
|
'type': 'Document',
|
||||||
'mediaType': 'image/png', // TODO: update the mediaType to match jpeg,gif,etc
|
'mediaType': 'image/png', // TODO: update the mediaType to match jpeg,gif,etc
|
||||||
|
@ -206,12 +208,24 @@ function createMessage(text, name, domain, item) {
|
||||||
};
|
};
|
||||||
out.object.attachment = attachment;
|
out.object.attachment = attachment;
|
||||||
}
|
}
|
||||||
|
else if (item.urls.length > 1) {
|
||||||
|
attachment = [];
|
||||||
|
let lengthFourMax = Math.min(item.urls.length, 4);
|
||||||
|
for (var i=0; i<lengthFourMax; i++) {
|
||||||
|
attachment.push({
|
||||||
|
'type': 'Document',
|
||||||
|
'mediaType': 'image/png', // TODO: update the mediaType to match jpeg,gif,etc
|
||||||
|
'url': item.urls[i],
|
||||||
|
'name': null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
out.object.attachment = attachment;
|
||||||
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCreateMessage(text, name, domain, req, res, item) {
|
function sendCreateMessage(text, name, domain, req, res, item) {
|
||||||
let message = createMessage(text, name, domain, item);
|
|
||||||
// console.log(`${name}@${domain}`);
|
// console.log(`${name}@${domain}`);
|
||||||
let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`);
|
let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`);
|
||||||
let followers = JSON.parse(result.followers);
|
let followers = JSON.parse(result.followers);
|
||||||
|
@ -223,6 +237,7 @@ function sendCreateMessage(text, name, domain, req, res, item) {
|
||||||
let inbox = follower+'/inbox';
|
let inbox = follower+'/inbox';
|
||||||
let myURL = new URL(follower);
|
let myURL = new URL(follower);
|
||||||
let targetDomain = myURL.hostname;
|
let targetDomain = myURL.hostname;
|
||||||
|
let message = createMessage(text, name, domain, item, follower);
|
||||||
signAndSend(message, name, domain, req, res, targetDomain, inbox);
|
signAndSend(message, name, domain, req, res, targetDomain, inbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue