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) emit new signal reset-message #307

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 two use cases:

  • Handle message content before it is gone.
  • Make changes to the UI e.g. in case there is no message typing anymore.
<template>
    <chat-window
        @reset-message="resetMessage"
    >
</template>

<script>
export default {
  name: 'ChatContainer',

  components: {
    ChatWindow
  },
  methods: {
    resetMessage({message, roomId}) {
    /*
     * Do something here.
     */
    },
  }
}
</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:

  • All tests are passing

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)

This enables two use cases:
* Handle message content before it is gone.
* Make changes to the UI e.g. in case there is no message typing anymore.
@rr-it
Copy link
Contributor Author

rr-it commented May 3, 2022

More complex example in combination with PR #306

For special rooms: show the footer with send button only, if a reply message is already selected.

<template>
    <chat-window
        :show-footer="showFooter"
        @reset-message="resetMessage"
        @message-action-handler="messageActionHandler"
    >
</template>

<script>
export default {
  name: 'ChatContainer',

  components: {
    ChatWindow
  },
  data() {
    return {
      messageActions: [
        {
          name: 'replyMessageCustom',
          title: 'Reply'
        }
      ],
      showFooter: true,
    }
  },
  created() {
    this.regexSpecialRoomId = /^[0-9a-f]{32}$/
  },
  methods: {
    resetMessages() {
      this.showFooter = true
    },
    resetMessage({roomId}) {
      if (this.regexSpecialRoomId.test(roomId)) {
        this.showFooter = false
      }
    },
    messageActionHandler({ action, message, roomId, methodCallback }) {
      if (action.name === 'replyMessageCustom') {
        if (this.regexSpecialRoomId.test(roomId)) {
          this.showFooter = true
        }
        methodCallback({ action: {name: 'replyMessage'}, message })
      }
    }
  }
}
</script>

@antoine92190
Copy link
Collaborator

antoine92190 commented May 7, 2022

Could you please add this new event in the README 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.

2 participants