Skip to content

Commit 01c1629

Browse files
committed
Refactor Notify event
1 parent 7c25302 commit 01c1629

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

src/botPage/bot/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const interpreter = createInterpreter()
5050

5151
globalObserver.register('Error', e => log(e))
5252

53-
globalObserver.register('Notify', e => log(e))
53+
globalObserver.register('Notify', e => log(`${e[0].toUpperCase()}: ${e[1]}`))
5454

5555
lineReader
5656
.on('line', line => (code += `${line}\n`))

src/botPage/bot/tools.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ export const registerStream = (observer, name, cb) => {
5757

5858
const maxRetries = 10
5959

60-
const notifyRetry = (msg, error, delay) => globalObserver.emit('Notify', [
61-
`${msg}: ${error.error.msg_type}, ${translate('retrying in')} ${delay}s`,
62-
'error',
63-
'right',
64-
])
60+
const notifyRetry = (msg, error, delay) => globalObserver.emit('Notify', ['warn',
61+
`${msg}: ${error.error.msg_type}, ${translate('retrying in')} ${delay}s`, 'right'])
6562

6663
const getBackoffDelay = (error, delayIndex) => {
6764
const offset = 0.5 // 500ms

src/botPage/view/blockly/blocks/tools/notify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Blockly.Blocks.notify = {
1818
Blockly.JavaScript.notify = (block) => {
1919
const notificationType = block.getFieldValue('NOTIFICATION_TYPE')
2020
const message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', Blockly.JavaScript.ORDER_ATOMIC)
21-
const code = `Bot.notify(${message}, '${notificationType}');
21+
const code = `Bot.notify('${notificationType}', ${message});
2222
`
2323
return code
2424
}

src/botPage/view/logger.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const isNew = msg => {
2727
return true
2828
}
2929

30-
const notifyUniq = (msg, ...args) => isNew(msg) && $.notify(msg, ...args)
31-
32-
const notify = (msg, className, position = 'left') => {
30+
const notify = (className, msg, position = 'left') => {
3331
log(className, msg)
34-
notifyUniq(msg, { position: `bottom ${position}`, className })
32+
if (isNew(msg)) {
33+
$.notify(msg, { position: `bottom ${position}`, className })
34+
}
3535
}
3636

3737
const notifyError = error => {
@@ -63,7 +63,7 @@ const notifyError = error => {
6363
trackJs.track(errorWithCode)
6464
}
6565

66-
notify(message, 'error', 'right')
66+
notify('error', message, 'right')
6767
}
6868

6969
const waitForNotifications = () => {
@@ -90,7 +90,7 @@ const waitForNotifications = () => {
9090

9191
notifList.forEach(className =>
9292
globalObserver.register(`ui.log.${className}`, message =>
93-
notify(message, className, 'right')))
93+
notify(className, message, 'right')))
9494

9595
amplitudeList.forEach(event =>
9696
globalObserver.register(event, (d) => amplitude.getInstance().logEvent(event, d)))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy