Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature) add method-callback to signal 'message-action-handler' #306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rr-it
Copy link
Contributor

@rr-it rr-it commented May 3, 2022

This enables custom action handlers to make a callback to the default action-handler.

<template>
    <chat-window
        @message-action-handler="messageActionHandler"
    >
</template>

<script>
export default {
  name: 'ChatContainer',
  components: {
    ChatWindow
  },
  data() {
    return {
      messageActions: [
        {
          name: 'replyMessageCustom',
          title: 'Reply'
        }
      ],
  },
  methods: {
    messageActionHandler({ action, message, roomId, methodCallback }) {
      if (action.name === 'replyMessageCustom') {
        /*
         * Do something here.
         */
        methodCallback({ action: {name: 'replyMessage'}, message })
      }
    }
  }
}
</script>

What kind of change does this PR introduce? (check at least one)

  • Feature

Does this PR introduce a breaking change? (check one)

  • No

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • All tests are passing (The one and only test 'RoomsList.spec.js' passed.)

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Additional information:
The idea to feed-back a function inside the emitter is based on this approach:
https://stackoverflow.com/questions/55316490/vue-best-practice-for-calling-a-method-in-a-child-component/70723343#70723343

This enables custom action handlers to make a callback to the default action-handler.

```
<template>
    <chat-window
        @message-action-handler="messageActionHandler"
    >
</template>

<script>
export default {
  name: 'ChatContainer',
  components: {
    ChatWindow
  },
  methods: {
    messageActionHandler({ action, message, roomId, methodCallback }) {
      if (action.name === 'replyMessageCustom') {
        /*
         * Do something here.
         */
        methodCallback({ action: {name: 'replyMessage'}, message })
      }
    }
  }
}
</script>
```
@antoine92190
Copy link
Collaborator

Thanks for the PR! Could you also add the new callback in the README? (in the Events API section)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants