]> git.mxchange.org Git - friendica.git/blobdiff - include/message.php
Throw NotFoundException if results are empty in api_users_lookup
[friendica.git] / include / message.php
index 6800663b5c838a4b831a3e4ba71bd8cfbbec3d1a..e49647b6ef7c9868fe162a28a31298a6e180711c 100644 (file)
@@ -4,6 +4,8 @@
 
 use Friendica\App;
 use Friendica\Core\System;
+use Friendica\Core\Worker;
+use Friendica\Database\DBM;
 
 function send_message($recipient=0, $body='', $subject='', $replyto=''){
 
@@ -41,7 +43,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
                        dbesc($replyto),
                        dbesc($replyto)
                );
-               if (dbm::is_result($r))
+               if (DBM::is_result($r))
                        $convid = $r[0]['convid'];
        }
 
@@ -60,22 +62,14 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
 
                $handles = $recip_handle . ';' . $sender_handle;
 
-               $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
-                       intval(local_user()),
-                       dbesc($conv_guid),
-                       dbesc($sender_handle),
-                       dbesc(datetime_convert()),
-                       dbesc(datetime_convert()),
-                       dbesc($subject),
-                       dbesc($handles)
-               );
+               $fields = array('uid' => local_user(), 'guid' => $conv_guid, 'creator' => $sender_handle,
+                               'created' => datetime_convert(), 'updated' => datetime_convert(),
+                               'subject' => $subject, 'recips' => $handles);
+               $r = dba::insert('conv', $fields);
 
-               $r = q("select * from conv where guid = '%s' and uid = %d limit 1",
-                       dbesc($conv_guid),
-                       intval(local_user())
-               );
-               if (dbm::is_result($r))
-                       $convid = $r[0]['id'];
+               $r = dba::select('conv', array('id'), array('guid' => $conv_guid, 'uid' => local_user()), array('limit' => 1));
+               if (DBM::is_result($r))
+                       $convid = $r['id'];
        }
 
        if (! $convid) {
@@ -113,7 +107,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
                dbesc($uri),
                intval(local_user())
        );
-       if (dbm::is_result($r))
+       if (DBM::is_result($r))
                $post_id = $r[0]['id'];
 
        /**
@@ -151,7 +145,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
        }
 
        if ($post_id) {
-               proc_run(PRIORITY_HIGH, "include/notifier.php", "mail", $post_id);
+               Worker::add(PRIORITY_HIGH, "Notifier", "mail", $post_id);
                return intval($post_id);
        } else {
                return -3;
@@ -175,9 +169,7 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
        $convid = 0;
        $reply = false;
 
-       require_once 'include/probe.php';
-
-       $me = probe_url($replyto);
+       $me = Probe::uri($replyto);
 
        if (! $me['name']) {
                return -2;
@@ -194,28 +186,18 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
 
        $handles = $recip_handle . ';' . $sender_handle;
 
-       $r = q("INSERT INTO `conv` (`uid`,`guid`,`creator`,`created`,`updated`,`subject`,`recips`) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
-               intval($recipient['uid']),
-               dbesc($conv_guid),
-               dbesc($sender_handle),
-               dbesc(datetime_convert()),
-               dbesc(datetime_convert()),
-               dbesc($subject),
-               dbesc($handles)
-       );
-
-       $r = q("SELECT * FROM `conv` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
-               dbesc($conv_guid),
-               intval($recipient['uid'])
-       );
-
+       $fields = array('uid' => $recipient['uid'], 'guid' => $conv_guid, 'creator' => $sender_handle,
+                       'created' => datetime_convert(), 'updated' => datetime_convert(),
+                       'subject' => $subject, 'recips' => $handles);
+       $r = dba::insert('conv', $fields);
 
-       if (! dbm::is_result($r)) {
+       $r = dba::select('conv', array('id'), array('guid' => $conv_guid, 'uid' => $recipient['uid']), array('limit' => 1));
+       if (!DBM::is_result($r)) {
                logger('send message: conversation not found.');
                return -4;
        }
 
-       $convid = $r[0]['id'];
+       $convid = $r['id'];
 
        $r = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
                `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`)