Skip to content
Permalink
Browse files

Add ability to delete messages

  • Loading branch information
john committed Apr 24, 2017
1 parent d68d596 commit 862c09fa6c1989c1a54525cc588ba59a2f9530fd
Showing with 70 additions and 5 deletions.
  1. +8 −0 public/api.php
  2. +4 −0 public/css/messages.css
  3. +26 −3 public/js/app.js
  4. +28 −2 public/messages.php
  5. +4 −0 public/template/footer.html
@@ -33,6 +33,14 @@
$m->save();
echo json_encode(['success']);
}
} else if ($action === 'delete_message') {
$message = SecureMessage::getByID($params['message_id']);
if (!$message) {
echo json_encode(['unkown_message']);
} else {
$message->delete();
echo json_encode(['success']);
}
}
}
@@ -13,3 +13,7 @@
padding: 10px !important;
border-radius: 5px;
}

.message-opt-button {
padding: 0 !important;
}
@@ -7,7 +7,6 @@ $(() => $('.user-tile').addClass('scale-in'));

$(document).ready(function(){
$('.modal').modal();
Materialize.showStaggeredList('#messages-list')
});

$('.dropdown-button').dropdown({
@@ -26,7 +25,7 @@ $(document).ready(function(){
$('.collapsible').collapsible();
});

$('#messages-list li').click(function() {
$('#messages-list li.message').click(function() {
var message_id = this.value;
var message_icon = $('#inbox-icon-' + message_id);
if (message_icon.html().trim() != 'check') {
@@ -38,7 +37,31 @@ $(document).ready(function(){
message_icon.removeClass('red-text');
});
}
})
});

function deleteInboxMessage(message_id) {
var inbox_list_item = $('#in-message-' + message_id);
var params = new URLSearchParams();
params.append('action', 'delete_message');
params.append('message_id', message_id)
axios.post('api.php', params).then(function(response) {
inbox_list_item.hide('slide',{direction:'right'},250, function() {
inbox_list_item.remove();
});
});
}

function deleteSentMessage(message_id) {
var sent_list_item = $('#out-message-' + message_id);
var params = new URLSearchParams();
params.append('action', 'delete_message');
params.append('message_id', message_id)
axios.post('api.php', params).then(function(response) {
sent_list_item.hide('slide',{direction:'right'},250, function() {
sent_list_item.remove();
});
});
}

function addToSent(recipient, message) {
sentList = $('#sent-list');
@@ -32,7 +32,9 @@
<div id="inbox" class="col s12">
<ul id="messages-list" class="collapsible popout" data-collapsible="accordion">
<?php foreach($inbox as $message) { ?>
<li value="<?php echo $message->id ?>">
<li id="in-message-<?php echo $message->id ?>" value="<?php echo $message->id ?>"
class="message"
>
<div class="collapsible-header">
<?php if ($message->is_read) { ?>
<i id="inbox-icon-<?php echo $message->id ?>"
@@ -44,6 +46,18 @@ class="material-icons red-text">fiber_new
</i>
<?php } ?>
<?php echo htmlspecialchars($message->sender()->username) ?>
<a class="right waves-circle message-opt-button center-align dropdown-button"
data-activates="message-dropdown-<?php echo $message->id ?>"
>
<i class="material-icons">more_vert</i>
</a>
<ul id="message-dropdown-<?php echo $message->id ?>" class='dropdown-content'>
<li>
<a onclick="deleteInboxMessage(<?php echo $message->id ?>)">
Delete
</a>
</li>
</ul>
</div>
<div class="collapsible-body">
<span>
@@ -57,14 +71,26 @@ class="material-icons red-text">fiber_new
<div id="sent" class="col s12" style="display:none">
<ul id="sent-list" class="collapsible popout" data-collapsible="accordion">
<?php foreach($outbox as $message) { ?>
<li>
<li id="out-message-<?php echo $message->id ?>" class="message">
<div class="collapsible-header">
<?php if ($message->is_read) { ?>
<i class="material-icons green-text">check_circle</i>
<?php } else { ?>
<i class="material-icons">arrow_forward</i>
<?php } ?>
<?php echo htmlspecialchars($message->receiver()->username) ?>
<a class="right waves-circle message-opt-button center-align dropdown-button"
data-activates="sent-dropdown-<?php echo $message->id ?>"
>
<i class="material-icons">more_vert</i>
</a>
<ul id="sent-dropdown-<?php echo $message->id ?>" class='dropdown-content'>
<li>
<a onclick="deleteSentMessage(<?php echo $message->id ?>)">
Delete
</a>
</li>
</ul>
</div>
<div class="collapsible-body">
<span>
@@ -3,6 +3,10 @@
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/js/materialize.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="js/app.js"></script>

0 comments on commit 862c09f

Please sign in to comment.
You can’t perform that action at this time.