diff --git a/src/balance.d.ts b/src/balance.d.ts index a13f861..cf0915f 100644 --- a/src/balance.d.ts +++ b/src/balance.d.ts @@ -2,16 +2,19 @@ import { FG_Plugin } from '@flaschengeist/types'; export interface SendFromNotification { receiver_id: string; - author_id: string; } export interface SendToNotification { sender_id: string; } +export interface TransactionNotification { + author_id: string; +} + export interface BalanceNotification extends FG_Plugin.Notification { data: { type: number; amount: number; - } & (SendFromNotification | SendToNotification); + } & (SendFromNotification | SendToNotification | TransactionNotification); } diff --git a/src/index.ts b/src/index.ts index af53601..d7c138c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,14 @@ import { FG_Plugin } from '@flaschengeist/types'; import { defineAsyncComponent } from 'vue'; import routes from './routes'; -import { BalanceNotification, SendFromNotification, SendToNotification } from 'app/balance'; +import { BalanceNotification, SendFromNotification, SendToNotification, TransactionNotification } from 'app/balance'; import { useUserStore } from '@flaschengeist/api'; const BalanceTypes = { send_to: 0x01, send_from: 0x02, + add_from: 0x03, + sub_from: 0x04, }; function transpile(msg: FG_Plugin.Notification) { @@ -21,16 +23,20 @@ function transpile(msg: FG_Plugin.Notification) { message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${ receiver.display_name } überwiesen.`; - } else { + } else if (message.data.type === BalanceTypes.send_to) { const sender = store.findUser((message.data).sender_id); console.log(sender); message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`; + } else { + const author = store.findUser((message.data).author_id); + const abgebucht = message.data.type === BalanceTypes.add_from ? 'aufgeladen' : 'abgebucht'; + message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ dir ${abgebucht}.`; } return message; } const plugin: FG_Plugin.Plugin = { - id: 'dev.flaschengeist.balance', + id: 'balance', name: 'Balance', innerRoutes: routes, requiredModules: [['balance']],