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

feat(conversation): quoted reply #13065

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
'system' : isSystemMessage,
'combined-system': isCombinedSystemMessage}"
class="message-body">
<MessageBody :rich-parameters="richParameters"
<MessageBody ref="messageBodyInstance"
:rich-parameters="richParameters"
:is-deleting="isDeleting"
:has-call="conversation.hasCall"
:message="message"
Expand Down Expand Up @@ -381,6 +382,21 @@
token: this.message.token,
id: this.message.id,
})

// Reply to selection
const selection = this.$refs.messageBodyInstance.getSelection()
if (selection) {
console.log('selection', { selection })

Check failure on line 389 in src/components/MessagesList/MessagesGroup/Message/Message.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
const quotedSelection = selection
.trim()
.split('\n')
.map(line => '> ' + line).join('\n')
console.log('quotedSelection', { quotedSelection })

Check failure on line 394 in src/components/MessagesList/MessagesGroup/Message/Message.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
if (quotedSelection) {
EventBus.emit('append-chat-input', quotedSelection)
}
}

EventBus.emit('focus-chat-input')
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
<Quote v-if="message.parent" :message="message.parent" />

<!-- Message content / text -->
<NcRichText :text="renderedMessage"
<NcRichText ref="richTextInstance"
:text="renderedMessage"
:arguments="richParameters"
:class="{'single-emoji': isSingleEmoji}"
autolink
Expand Down Expand Up @@ -442,6 +443,29 @@ export default {
}
EventBus.emit('message-height-changed', { heightDiff: height - oldHeight })
},

/**
* @public
*/
getSelection() {
const selection = window.getSelection()

// Nothing selected
if (selection.rangeCount === 0) {
return ''
}

const range = selection.getRangeAt(0)
const target = range.commonAncestorContainer
const richTextElement = this.$refs.richTextInstance.$el

// Selection is outside of this message
if (richTextElement !== target && !richTextElement.contains(target)) {
return ''
}

return selection.toString()
}
},
}
</script>
Expand Down
14 changes: 14 additions & 0 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@

mounted() {
EventBus.on('focus-chat-input', this.focusInput)
EventBus.on('append-chat-input', this.handleAppendChatInput)
EventBus.on('upload-start', this.handleUploadSideEffects)
EventBus.on('upload-discard', this.handleUploadSideEffects)
EventBus.on('retry-message', this.handleRetryMessage)
Expand All @@ -551,6 +552,7 @@

beforeDestroy() {
EventBus.off('focus-chat-input', this.focusInput)
EventBus.off('append-chat-input', this.handleAppendChatInput)
EventBus.off('upload-start', this.handleUploadSideEffects)
EventBus.off('upload-discard', this.handleUploadSideEffects)
EventBus.off('retry-message', this.handleRetryMessage)
Expand Down Expand Up @@ -770,6 +772,18 @@
this.$refs.richContenteditable.showTribute('/')
},

handleAppendChatInput(newTextLine) {
let textToAppend = ''
if (this.text) {
textToAppend += '\n\n'
}
textToAppend += newTextLine
textToAppend += '\n\n'

console.log('textToAppend', { textToAppend })

Check failure on line 783 in src/components/NewMessage/NewMessage.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected console statement
this.text += textToAppend
},

/**
* Clicks the hidden file input when clicking the correspondent NcActionButton,
* thus opening the file-picker
Expand Down
Loading