diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 2050fedf00..039104da5c 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -1584,4 +1584,36 @@ class MessageManager return $messages; } + /** + * Check whether a message has attachments + * @param int $messageId The message id + * @return boolean Whether the message has attachments return true. Otherwise return false + */ + public static function hasAttachments($messageId) + { + $messageId = intval($messageId); + + if (empty($messageId)) { + return false; + } + + $messageAttachmentTable = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); + + $conditions = array( + 'where' => array( + 'message_id = ?' => $messageId + ) + ); + + $result = Database::select('COUNT(1) AS qty', $messageAttachmentTable, $conditions, 'first'); + + if (!empty($result)) { + if ($result['qty'] > 0) { + return true; + } + } + + return false; + } + } diff --git a/main/inc/lib/webservices/MessagesWebService.class.php b/main/inc/lib/webservices/MessagesWebService.class.php index cf5eb3aa72..40d262e2ec 100644 --- a/main/inc/lib/webservices/MessagesWebService.class.php +++ b/main/inc/lib/webservices/MessagesWebService.class.php @@ -102,6 +102,8 @@ class MessagesWebService extends WebService $lastMessages = MessageManager::getMessagesFromLastReceivedMessage($userId, $lastId); foreach ($lastMessages as $message) { + $hasAttachments = MessageManager::hasAttachments($message['id']); + $messages[] = array( 'id' => $message['id'], 'title' => $message['title'], @@ -112,6 +114,7 @@ class MessagesWebService extends WebService 'completeName' => api_get_person_name($message['firstname'], $message['lastname']), ), 'content' => $message['content'], + 'hasAttachments' => $hasAttachments, 'platform' => array( 'website' => api_get_path(WEB_PATH), 'messagingTool' => api_get_path(WEB_PATH) . 'main/messages/inbox.php' diff --git a/webservices/rest.php b/webservices/rest.php index 10549f05b7..8591cbd27b 100644 --- a/webservices/rest.php +++ b/webservices/rest.php @@ -62,10 +62,12 @@ switch ($action) { $messages = $webService->getNewMessages($username, $lastId); - $json = $messages; - } else { $json = array( 'status' => true, + 'messages' => $messages + ); + } else { + $json = array( 'status' => false ); }