mirror of
https://github.com/dariusk/rss-to-activitypub.git
synced 2024-11-25 02:39:18 +02:00
Provide route to dereferenced messages and fix duplicate messages
This commit mostly fixes the duplicate messages issue. What was happening was I was creating multiple Note objects if I was sending a Note to multiple people. Instead I create one Note object and reference that in multiple Create events.
This commit is contained in:
parent
753872d31d
commit
45e1362aa2
3
index.js
3
index.js
|
@ -29,6 +29,8 @@ try {
|
|||
db.prepare('CREATE TABLE IF NOT EXISTS accounts (name TEXT PRIMARY KEY, privkey TEXT, pubkey TEXT, webfinger TEXT, actor TEXT, apikey TEXT, followers TEXT, messages TEXT)').run();
|
||||
// if there is no `feeds` table in the DB, create an empty table
|
||||
db.prepare('CREATE TABLE IF NOT EXISTS feeds (feed TEXT PRIMARY KEY, username TEXT, content TEXT)').run();
|
||||
// if there is no `messages` table in the DB, create an empty table
|
||||
db.prepare('CREATE TABLE IF NOT EXISTS messages (guid TEXT PRIMARY KEY, message TEXT)').run();
|
||||
|
||||
app.set('db', db);
|
||||
app.set('domain', DOMAIN);
|
||||
|
@ -48,6 +50,7 @@ app.use('/admin', express.static('public/admin'));
|
|||
app.use('/convert', express.static('public/convert'));
|
||||
app.use('/.well-known/webfinger', cors(), routes.webfinger);
|
||||
app.use('/u', cors(), routes.user);
|
||||
app.use('/m', cors(), routes.message);
|
||||
app.use('/api/inbox', cors(), routes.inbox);
|
||||
|
||||
http.createServer(app).listen(app.get('port'), function(){
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
module.exports = {
|
||||
api: require('./api'),
|
||||
user: require('./user'),
|
||||
inbox: require('./inbox'),
|
||||
message: require('./message'),
|
||||
user: require('./user'),
|
||||
webfinger: require('./webfinger'),
|
||||
};
|
||||
|
|
|
@ -173,25 +173,26 @@ function signAndSend(message, name, domain, req, res, targetDomain, inbox) {
|
|||
}
|
||||
}
|
||||
|
||||
function createMessage(text, name, domain, item, follower) {
|
||||
const guid = crypto.randomBytes(16).toString('hex');
|
||||
function createMessage(text, name, domain, item, follower, guidNote) {
|
||||
const guidCreate = crypto.randomBytes(16).toString('hex');
|
||||
let d = new Date();
|
||||
|
||||
let out = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
|
||||
'id': `https://${domain}/${guid}`,
|
||||
'id': `https://${domain}/m/${guidCreate}`,
|
||||
'type': 'Create',
|
||||
'actor': `https://${domain}/u/${name}`,
|
||||
|
||||
'to': [ follower ],
|
||||
|
||||
'object': {
|
||||
'id': `https://${domain}/${guid}`,
|
||||
'id': `https://${domain}/m/${guidNote}`,
|
||||
'type': 'Note',
|
||||
'published': d.toISOString(),
|
||||
'attributedTo': `https://${domain}/u/${name}`,
|
||||
'content': text,
|
||||
'link': item.link,
|
||||
'cc': 'https://www.w3.org/ns/activitystreams#Public'
|
||||
}
|
||||
};
|
||||
|
@ -222,6 +223,10 @@ function createMessage(text, name, domain, item, follower) {
|
|||
out.object.attachment = attachment;
|
||||
}
|
||||
|
||||
console.log(guidCreate, guidNote);
|
||||
db.prepare('insert or replace into messages(guid, message) values(?, ?)').run( guidCreate, JSON.stringify(out));
|
||||
db.prepare('insert or replace into messages(guid, message) values(?, ?)').run( guidNote, JSON.stringify(out.object));
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -237,7 +242,8 @@ function sendCreateMessage(text, name, domain, req, res, item) {
|
|||
let inbox = follower+'/inbox';
|
||||
let myURL = new URL(follower);
|
||||
let targetDomain = myURL.hostname;
|
||||
let message = createMessage(text, name, domain, item, follower);
|
||||
const guidNote = crypto.randomBytes(16).toString('hex');
|
||||
let message = createMessage(text, name, domain, item, follower, guidNote);
|
||||
signAndSend(message, name, domain, req, res, targetDomain, inbox);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue