Skip to content

Commit

Permalink
Merge pull request #57 from stakwork/migrate-key
Browse files Browse the repository at this point in the history
Migrate key
  • Loading branch information
Evanfeenstra authored Jul 8, 2020
2 parents e0444fe + 076f235 commit 170a491
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
17 changes: 6 additions & 11 deletions api/controllers/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,19 @@ export const updateContact = async (req, res) => {
let attrs = extractAttrs(req.body)

const contact = await models.Contact.findOne({ where: { id: req.params.id }})
let shouldSendUpdatedSelf = (
contact.isOwner && (
(contact.contactKey == null && attrs["contact_key"] != null) || // CREATE CONTACT KEY!
attrs["contact_key"]==null // OR NO NEW CONTACT KEY
)
)


// update self
const owner = await contact.update(jsonUtils.jsonToContact(attrs))
success(res, jsonUtils.contactToJson(owner))

if (!shouldSendUpdatedSelf) return

// send updated owner info to others
if (!contact.isOwner) return
// else:
// send updated owner info to others!
const contactIds = await models.Contact.findAll({where:{deleted:false}})
.filter(c=> !c.fromGroup && c.id!==1 && c.publicKey).map(c=> c.id)
.filter(c=> c.id!==1 && c.publicKey).map(c=> c.id)
if (contactIds.length == 0) return

console.log("=> send contact_key to", contactIds)
helpers.sendContactKeys({
contactIds: contactIds,
sender: owner,
Expand Down
2 changes: 1 addition & 1 deletion api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const performKeysendMessage = async ({ destination_key, amount, msg, succ
// console.log("=> keysend to new contact")
if (success) success(r)
} catch (e) {
console.log("MESSAGE ERROR", e)
console.log("MESSAGE ERROR to", destination_key, e)
if (failure) failure(e)
}
}
Expand Down
11 changes: 5 additions & 6 deletions dist/api/controllers/contacts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/controllers/contacts.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/api/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/helpers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 170a491

Please sign in to comment.