Skip to content

Commit

Permalink
Merge pull request #802 from stakwork/update/only_pubkey
Browse files Browse the repository at this point in the history
Update/only pubkey
  • Loading branch information
Evanfeenstra authored Feb 8, 2024
2 parents c8818b8 + ca66dbe commit 4e99a46
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 35 deletions.
33 changes: 21 additions & 12 deletions dist/src/controllers/botapi/broadcast.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/src/controllers/botapi/broadcast.js.map

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

36 changes: 26 additions & 10 deletions src/controllers/botapi/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,34 @@ export default async function broadcast(a: Action): Promise<void> {
const tenant: number = owner.id

if (only_user || only_pubkey) {
if (only_user) {
chat.contactIds = `[${only_user}]`
} else {
try {
const user = (await models.Contact.findOne({
where: { tenant, publicKey: only_pubkey! },
})) as ContactRecord
if (user) chat.contactIds = `[${user.id}]`
} catch (error) {
sphinxLogger.error(`=> ONLY_PUBKEY ERROR ${error}`, logging.Bots)
if (only_pubkey) {
const pubkeysArray = only_pubkey.split(',')
const userIds: number[] = []

for (let i = 0; i < pubkeysArray.length; i++) {
const publicKey = pubkeysArray[i]
try {
const user = (await models.Contact.findOne({
where: { tenant, publicKey },
})) as ContactRecord
if (user) userIds.push(user.id)
} catch (error) {
sphinxLogger.error(
`=> ERROR GETTING USER WITH THIS PUBKEY ${publicKey} ${error}`,
logging.Bots
)
}
}
if (userIds.length === 0) {
sphinxLogger.error(
`=> USERS WITH PUBKEYS PROVIDED DO NOT EXIST`,
logging.Bots
)
return
}
chat.contactIds = JSON.stringify([...userIds])
} else {
chat.contactIds = `[${only_user}]`
}
}

Expand Down
Loading

0 comments on commit 4e99a46

Please sign in to comment.