Users can only edit & delete their own messages (except for admin users)
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
a771710094
commit
0cab21f344
|
@ -235,9 +235,18 @@ function redrawMessages() {
|
||||||
fetchMoreButton.classList.remove('d-none')
|
fetchMoreButton.classList.remove('d-none')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeAllPopovers() {
|
||||||
|
for (let popover of document.querySelectorAll('*[aria-describedby*="popover"]')) {
|
||||||
|
let instance = bootstrap.Popover.getInstance(popover)
|
||||||
|
if (instance)
|
||||||
|
instance.dispose()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function registerSendPrivateMessageContextMenu(message, element) {
|
function registerSendPrivateMessageContextMenu(message, element) {
|
||||||
element.addEventListener('contextmenu', (menu_event) => {
|
element.addEventListener('contextmenu', (menu_event) => {
|
||||||
menu_event.preventDefault()
|
menu_event.preventDefault()
|
||||||
|
removeAllPopovers()
|
||||||
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
||||||
'title': message['author'],
|
'title': message['author'],
|
||||||
'content': `<a id="send-private-message-link-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`,
|
'content': `<a id="send-private-message-link-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`,
|
||||||
|
@ -247,7 +256,7 @@ function registerSendPrivateMessageContextMenu(message, element) {
|
||||||
|
|
||||||
document.getElementById('send-private-message-link-' + message['id']).addEventListener('click', event => {
|
document.getElementById('send-private-message-link-' + message['id']).addEventListener('click', event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
popover.hide()
|
popover.dispose()
|
||||||
socket.send(JSON.stringify({
|
socket.send(JSON.stringify({
|
||||||
'type': 'start_private_chat',
|
'type': 'start_private_chat',
|
||||||
'user_id': message['author_id'],
|
'user_id': message['author_id'],
|
||||||
|
@ -259,10 +268,13 @@ function registerSendPrivateMessageContextMenu(message, element) {
|
||||||
function registerMessageContextMenu(message, element) {
|
function registerMessageContextMenu(message, element) {
|
||||||
element.addEventListener('contextmenu', (menu_event) => {
|
element.addEventListener('contextmenu', (menu_event) => {
|
||||||
menu_event.preventDefault()
|
menu_event.preventDefault()
|
||||||
|
removeAllPopovers()
|
||||||
let content = `<a id="send-private-message-link-msg-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`
|
let content = `<a id="send-private-message-link-msg-${message['id']}" class="nav-link" href="#" tabindex="0">Envoyer un message privé</a>`
|
||||||
content += `<hr class="my-1">`
|
if (message['author_id'] === USER_ID || IS_ADMIN) {
|
||||||
content += `<a class="nav-link" href="#" tabindex="0">Modifier</a>`
|
content += `<hr class="my-1">`
|
||||||
content += `<a class="nav-link" href="#" tabindex="0">Supprimer</a>`
|
content += `<a class="nav-link" href="#" tabindex="0">Modifier</a>`
|
||||||
|
content += `<a class="nav-link" href="#" tabindex="0">Supprimer</a>`
|
||||||
|
}
|
||||||
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
const popover = bootstrap.Popover.getOrCreateInstance(element, {
|
||||||
'content': content,
|
'content': content,
|
||||||
'html': true,
|
'html': true,
|
||||||
|
@ -272,7 +284,7 @@ function registerMessageContextMenu(message, element) {
|
||||||
|
|
||||||
document.getElementById('send-private-message-link-msg-' + message['id']).addEventListener('click', event => {
|
document.getElementById('send-private-message-link-msg-' + message['id']).addEventListener('click', event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
popover.hide()
|
popover.dispose()
|
||||||
socket.send(JSON.stringify({
|
socket.send(JSON.stringify({
|
||||||
'type': 'start_private_chat',
|
'type': 'start_private_chat',
|
||||||
'user_id': message['author_id'],
|
'user_id': message['author_id'],
|
||||||
|
@ -296,13 +308,7 @@ function toggleFullscreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
document.addEventListener('click', () => {
|
document.addEventListener('click', removeAllPopovers)
|
||||||
for (let popover of document.querySelectorAll('span[aria-describedby*="popover"]')) {
|
|
||||||
let instance = bootstrap.Popover.getInstance(popover)
|
|
||||||
if (instance)
|
|
||||||
instance.hide()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the received data from the server.
|
* Process the received data from the server.
|
||||||
|
|
|
@ -87,4 +87,9 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const USER_ID = {{ request.user.id }}
|
||||||
|
const IS_ADMIN = {{ request.user.registration.is_admin|yesno:"true,false" }}
|
||||||
|
</script>
|
Loading…
Reference in New Issue