]> git.mxchange.org Git - friendica.git/commitdiff
Fix Twitter NewDM API w/OAuth by passing in UID not query session
authorHank Grabowski <hankgrabowski@gmail.com>
Wed, 22 Mar 2023 22:18:49 +0000 (18:18 -0400)
committerHank Grabowski <hankgrabowski@gmail.com>
Wed, 22 Mar 2023 22:18:49 +0000 (18:18 -0400)
src/Model/Mail.php
src/Module/Api/Twitter/DirectMessages/NewDM.php

index e624a6f9758e120fb572f927f767134c49fc981a..2b9d8bea498a917f54265e8045ccbec8c5bb1d1b 100644 (file)
@@ -124,7 +124,7 @@ class Mail
         * @return int
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function send(int $recipient = 0, string $body = '', string $subject = '', string $replyto = ''): int
+       public static function send(string $uid, int $recipient = 0, string $body = '', string $subject = '', string $replyto = ''): int
        {
                $a = DI::app();
 
@@ -136,12 +136,12 @@ class Mail
                        $subject = DI::l10n()->t('[no subject]');
                }
 
-               $me = DBA::selectFirst('contact', [], ['uid' => DI::userSession()->getLocalUserId(), 'self' => true]);
+               $me = DBA::selectFirst('contact', [], ['uid' => $uid, 'self' => true]);
                if (!DBA::isResult($me)) {
                        return -2;
                }
 
-               $contacts = ACL::getValidMessageRecipientsForUser(DI::userSession()->getLocalUserId());
+               $contacts = ACL::getValidMessageRecipientsForUser($uid);
 
                $contactIndex = array_search($recipient, array_column($contacts, 'id'));
                if ($contactIndex === false) {
@@ -150,7 +150,7 @@ class Mail
 
                $contact = $contacts[$contactIndex];
 
-               Photo::setPermissionFromBody($body, DI::userSession()->getLocalUserId(), $me['id'],  '<' . $contact['id'] . '>', '', '', '');
+               Photo::setPermissionFromBody($body, $uid, $me['id'], '<' . $contact['id'] . '>', '', '', '');
 
                $guid = System::createUUID();
                $uri = Item::newURI($guid);
@@ -163,7 +163,7 @@ class Mail
                if (strlen($replyto)) {
                        $reply = true;
                        $condition = ["`uid` = ? AND (`uri` = ? OR `parent-uri` = ?)",
-                               DI::userSession()->getLocalUserId(), $replyto, $replyto];
+                               $uid, $replyto, $replyto];
                        $mail = DBA::selectFirst('mail', ['convid'], $condition);
                        if (DBA::isResult($mail)) {
                                $convid = $mail['convid'];
@@ -176,7 +176,7 @@ class Mail
                        $conv_guid = System::createUUID();
                        $convuri = $contact['addr'] . ':' . $conv_guid;
 
-                       $fields = ['uid' => DI::userSession()->getLocalUserId(), 'guid' => $conv_guid, 'creator' => $me['addr'],
+                       $fields = ['uid' => $uid, 'guid' => $conv_guid, 'creator' => $me['addr'],
                                'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(),
                                'subject' => $subject, 'recips' => $contact['addr'] . ';' . $me['addr']];
                        if (DBA::insert('conv', $fields)) {
@@ -195,7 +195,7 @@ class Mail
 
                $post_id = self::insert(
                        [
-                               'uid' => DI::userSession()->getLocalUserId(),
+                               'uid' => $uid,
                                'guid' => $guid,
                                'convid' => $convid,
                                'from-name' => $me['name'],
@@ -210,7 +210,8 @@ class Mail
                                'uri' => $uri,
                                'parent-uri' => $replyto,
                                'created' => DateTimeFormat::utcNow()
-                       ], false
+                       ],
+                       false
                );
 
                /**
@@ -231,7 +232,7 @@ class Mail
                                foreach ($images as $image) {
                                        $image_rid = Photo::ridFromURI($image);
                                        if (!empty($image_rid)) {
-                                               Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_rid, 'album' => 'Wall Photos', 'uid' => DI::userSession()->getLocalUserId()]);
+                                               Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_rid, 'album' => 'Wall Photos', 'uid' => $uid]);
                                        }
                                }
                        }
@@ -311,7 +312,8 @@ class Mail
                                'parent-uri' => $me['url'],
                                'created' => DateTimeFormat::utcNow(),
                                'unknown' => 1
-                       ], false
+                       ],
+                       false
                );
 
                return 0;
index 5d7fb3a5645977d14930c8ec4bf9763761a69e2f..866660810c265d96efa5c6b50ef8d70082c8546a 100644 (file)
@@ -83,7 +83,7 @@ class NewDM extends BaseApi
 
                $cdata = Contact::getPublicAndUserContactID($cid, $uid);
 
-               $id = Mail::send($cdata['user'], $request['text'], $sub, $replyto);
+               $id = Mail::send($uid, $cdata['user'], $request['text'], $sub, $replyto);
 
                if ($id > -1) {
                        $ret = $this->directMessage->createFromMailId($id, $uid, $this->getRequestValue($request, 'getText', ''));