Messages: Integrate primary attachment (image) from Contacts in message thread. Dynamically adjust thread height on window resize.

This commit is contained in:
Nate
2019-03-28 17:58:02 -06:00
parent 6acd640d2f
commit e9780736ef
5 changed files with 182 additions and 77 deletions

View File

@@ -41,10 +41,24 @@
//get number of messages to load
$number = preg_replace('{[\D]}', '', $_GET['number']);
$contact_uuid = $_GET['contact_uuid'];
//set refresh flag
$refresh = $_GET['refresh'] == 'true' ? true : false;
//get contact (primary attachment) image, if any
if (is_uuid($contact_uuid) && (!is_array($_SESSION['tmp']['messages']['contact_em'][$contact_uuid]) || $_SESSION['tmp']['messages']['contact_em'][$contact_uuid] != $contact_uuid)) {
$sql = "select attachment_filename as filename, attachment_content as image from v_contact_attachments ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and contact_uuid = :contact_uuid ";
$sql .= "and attachment_primary = 1 ";
$bind[':contact_uuid'] = $contact_uuid;
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute(is_array($bind) ? $bind : null);
$_SESSION['tmp']['messages']['contact_em'][$contact_uuid] = $prep_statement->fetch(PDO::FETCH_NAMED);
unset ($sql, $bind, $prep_statement);
}
//get messages
if (isset($_SESSION['message']['display_last']['text']) && $_SESSION['message']['display_last']['text'] != '') {
$array = explode(' ',$_SESSION['message']['display_last']['text']);
@@ -58,7 +72,18 @@
}
}
if ($limit == '' && $since == '') { $limit = "limit 25 offset 0"; } //default (message count)
$sql = "select * from v_messages ";
$sql = "select ";
$sql .= "message_uuid, ";
$sql .= "domain_uuid, ";
$sql .= "user_uuid, ";
$sql .= "contact_uuid, ";
$sql .= "message_type, ";
$sql .= "message_direction, ";
$sql .= "message_date at time zone '".$_SESSION['domain']['time_zone']['name']."' as message_date, ";
$sql .= "message_from, ";
$sql .= "message_to, ";
$sql .= "message_text ";
$sql .= "from v_messages ";
$sql .= "where user_uuid = '".$_SESSION['user_uuid']."' ";
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
$sql .= $since;
@@ -101,55 +126,85 @@
//css styles
echo "<style>\n";
echo " .message-bubble {\n";
echo " display: block;\n";
echo " display: table;\n";
echo " padding: 10px;\n";
echo " border: 1px solid;\n";
echo " margin-bottom: 10px;\n";
echo " }\n";
echo " }\n";
echo " .message-bubble-em {\n";
echo " margin-right: 10%;\n";
echo " border-radius: 0px 20px 20px 20px;\n";
echo " margin-right: 30%;\n";
echo " border-radius: 0 20px 20px 20px;\n";
echo " border-color: #cffec7;\n";
echo " background-color: #ecffe9;\n";
echo " }\n";
echo " clear: both;\n";
echo " }\n";
echo " .message-bubble-me {\n";
echo " margin-left: 10%;\n";
echo " border-radius: 20px 20px 0px 20px;\n";
echo " float: right;\n";
echo " margin-left: 30%;\n";
echo " border-radius: 20px 20px 0 20px;\n";
echo " border-color: #cbf0ff;\n";
echo " background-color: #e5f7ff;\n";
echo " }\n";
echo " clear: both;\n";
echo " }\n";
echo " img.message-bubble-image-em {\n";
echo " width: 100px;\n";
echo " height: auto;\n";
echo " border-radius: 0 11px 11px 11px;\n";
echo " }\n";
echo " img.message-bubble-image-me {\n";
echo " width: 100px;\n";
echo " height: auto;\n";
echo " border-radius: 11px 11px 0 11px;\n";
echo " }\n";
echo " div.message-bubble-image-em {\n";
echo " float: left;\n";
echo " margin-right: 15px;\n";
echo " text-align: left;\n";
echo " }\n";
echo " div.message-bubble-image-me {\n";
echo " float: right;\n";
echo " margin-left: 15px;\n";
echo " text-align: right;\n";
echo " }\n";
echo " .message-text {\n";
echo " padding-bottom: 5px;\n";
echo " font-size: 90%;\n";
echo " }\n";
echo " .message-bubble-when {\n";
echo " font-size: 65%;\n";
echo " line-height: 60%;\n";
echo " }\n";
echo " font-size: 71%;\n";
echo " font-style: italic;\n";
echo " }\n";
echo " .message-media-link-em {\n";
echo " display: block;\n";
echo " position: inline;\n";
echo " margin: 5px 10px;\n";
echo " display: inline-block;\n";
echo " margin: 5px 10px 5px 0;\n";
echo " padding: 8px;\n";
echo " background: #cffec7;\n";
echo " border-radius: 7px;\n";
echo " text-align: center;\n";
echo " }\n";
echo " }\n";
echo " .message-media-link-me {\n";
echo " display: block;\n";
echo " position: inline;\n";
echo " margin: 5px 10px;\n";
echo " display: inline-block;\n";
echo " margin: 5px 10px 5px 0;\n";
echo " padding: 8px;\n";
echo " background: #cbf0ff;\n";
echo " border-radius: 7px;\n";
echo " text-align: center;\n";
echo " }\n";
echo " }\n";
echo "</style>\n";
if (!$refresh) {
echo "<div id='thread_messages' style='max-height: 300px; overflow: auto;'>\n";
echo "<div id='thread_messages' style='min-height: 300px; overflow: auto; padding-right: 15px;'>\n";
}
//output messages
@@ -165,28 +220,51 @@
}
//message bubble
echo "<span class='message-bubble message-bubble-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
if ($message['message_text'] != '') {
echo str_replace("\n",'<br />',escape($message['message_text']))."<br />\n";
}
if (is_array($message_media[$message['message_uuid']]) && sizeof($message_media[$message['message_uuid']]) != 0) {
echo "<span class='message-bubble message-bubble-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
//contact image
if ($message['message_direction'] == 'inbound') { //em
if (is_array($_SESSION['tmp']['messages']['contact_em'][$contact_uuid]) && sizeof($_SESSION['tmp']['messages']['contact_em'][$contact_uuid]) != 0) {
$attachment_type = strtolower(pathinfo($_SESSION['tmp']['messages']['contact_em'][$contact_uuid]['filename'], PATHINFO_EXTENSION));
echo "<div class='message-bubble-image-em'>\n";
echo " <img class='message-bubble-image-em' src='data:image/".$attachment_type.";base64,".$_SESSION['tmp']['messages']['contact_em'][$contact_uuid]['image']."'><br />\n";
echo "</div>\n";
}
}
else { //me
if (is_array($_SESSION['tmp']['messages']['contact_me']) && sizeof($_SESSION['tmp']['messages']['contact_me']) != 0) {
$attachment_type = strtolower(pathinfo($_SESSION['tmp']['messages']['contact_me']['filename'], PATHINFO_EXTENSION));
echo "<div class='message-bubble-image-me'>\n";
echo " <img class='message-bubble-image-me' src='data:image/".$attachment_type.";base64,".$_SESSION['tmp']['messages']['contact_me']['image']."'><br />\n";
echo "</div>\n";
}
}
echo "<div style='display: table;'>\n";
//message
if ($message['message_text'] != '') {
echo "<div class='message-text'>".str_replace("\n",'<br />',escape($message['message_text']))."</div>\n";
}
//attachments
if (is_array($message_media[$message['message_uuid']]) && sizeof($message_media[$message['message_uuid']]) != 0) {
foreach ($message_media[$message['message_uuid']] as $media) {
if ($media['type'] != 'txt') {
if ($media['type'] == 'jpg' || $media['type'] == 'jpeg' || $media['type'] == 'gif' || $media['type'] == 'png') {
echo "<a href='#' onclick=\"display_media('".$media['uuid']."','".$media_source."');\" class='message-media-link-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
foreach ($message_media[$message['message_uuid']] as $media) {
if ($media['type'] != 'txt') {
if ($media['type'] == 'jpg' || $media['type'] == 'jpeg' || $media['type'] == 'gif' || $media['type'] == 'png') {
echo "<a href='#' onclick=\"display_media('".$media['uuid']."','".$media_source."');\" class='message-media-link-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
}
else {
echo "<a href='message_media.php?id=".$media['uuid']."&src=".$media_source."&action=download' class='message-media-link-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
}
echo "<img src='resources/images/attachment.png' style='width: 16px; height: 16px; border: none; margin-right: 10px;'>";
echo "<span style='font-size: 85%;'>".strtoupper($media['type']).' &middot; '.strtoupper(byte_convert($media['size']))."</span>";
echo "</a>\n";
}
}
echo "<br />\n";
}
else {
echo "<a href='message_media.php?id=".$media['uuid']."&src=".$media_source."&action=download' class='message-media-link-".($message['message_direction'] == 'inbound' ? 'em' : 'me')."'>";
}
echo "<img src='resources/images/attachment.png' style='width: 16px; height: 16px; border: none; margin-right: 10px;'>";
echo "<span style='font-size: 85%;'>".strtoupper($media['type']).' &middot; '.strtoupper(byte_convert($media['size']))."</span>";
echo "</a>\n";
}
}
}
echo " <span class='message-bubble-when'>".format_when_local($message['message_date'])."</span>\n";
echo "</span>\n";
//message when
echo "<span class='message-bubble-when'>".(gmdate('m-d-Y') != format_when_local($message['message_date'],'d') ? format_when_local($message['message_date']) : format_when_local($message['message_date'],'t'))."</span>\n";
echo "</div>\n";
echo "</span>\n";
}
echo "<span id='thread_bottom'></span>\n";
}
@@ -212,7 +290,7 @@
echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='margin-top: 15px;'>\n";
echo " <tr>\n";
echo " <td align='left' width='50%'><input type='reset' class='btn' value='".$text['button-clear']."' onclick=\"$('#message_text').focus();\"></td>\n";
echo " <td align='center'><span id='thread_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; cursor: pointer;' onclick=\"refresh_thread_stop('".$number."');\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span></td>\n";
echo " <td align='center'><span id='thread_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; cursor: pointer;' onclick=\"refresh_thread_stop('".$number."','".$contact_uuid."');\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span></td>\n";
echo " <td align='right' width='50%'><input type='submit' class='btn' value='".$text['button-send']."' title=\"".$text['label-ctrl_enter']."\"></td>\n";
echo " </td>\n";
echo "</table>\n";
@@ -237,7 +315,7 @@
echo " $('#message_text').focus();\n";
echo " }\n";
}
echo " refresh_thread('".$number."','true');\n";
echo " refresh_thread('".$number."', '".$contact_uuid."', 'true');\n";
echo " }\n";
echo " });\n";
echo " });\n";