refactor: use initializeFeed() inside create()

This commit is contained in:
Andre Staltz 2023-04-28 11:27:15 +03:00
parent 9dd5f92ce8
commit d39ee6b017
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 45 additions and 51 deletions

View File

@ -237,16 +237,9 @@ exports.init = function initDB(peer, config) {
if (!opts.content) return cb(new Error('create() requires a `content`'))
if (!opts.type) return cb(new Error('create() requires a `type`'))
const feedRootHash = getFeedRoot(FeedV1.stripAuthor(keys.id), opts.type)
if (!feedRootHash) {
const feedRoot = FeedV1.createRoot(keys, opts.type)
add(feedRoot, FeedV1.getMsgHash(feedRoot), (err) => {
initializeFeed(opts, (err, feedRootHash) => {
// prettier-ignore
if (err) return cb(new Error('create() failed to create root', {cause: err}));
create(opts, cb)
})
return
}
if (err) return cb(new Error('create() failed to initialize feed', { cause: err }));
// Fill-in tangle opts:
const tangleTemplates = opts.tangles ?? []
@ -290,6 +283,7 @@ exports.init = function initDB(peer, config) {
onRecordAdded.set(rec)
cb(null, rec)
})
})
}
function getFeedRoot(authorId, findType) {