mirror of
https://github.com/friendica/friendica
synced 2025-04-26 19:50:10 +00:00
Mail storing is now centralized
This commit is contained in:
parent
10b5ea825d
commit
b8a23369b6
3 changed files with 72 additions and 97 deletions
|
@ -9,6 +9,7 @@ use Friendica\Core\L10n;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -18,6 +19,70 @@ use Friendica\Util\DateTimeFormat;
|
|||
*/
|
||||
class Mail
|
||||
{
|
||||
/**
|
||||
* Insert received private message
|
||||
*
|
||||
* @param array $msg
|
||||
* @return int|boolean Message ID or false on error
|
||||
*/
|
||||
public static function insert($msg)
|
||||
{
|
||||
$user = User::getById($msg['uid']);
|
||||
|
||||
if (empty($msg['convid'])) {
|
||||
$mail = DBA::selectFirst('mail', ['convid'], ["`convid` != 0 AND `parent-uri` = ?", $msg['parent-uri']]);
|
||||
if (DBA::isResult($mail)) {
|
||||
$msg['convid'] = $mail['convid'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($msg['guid'])) {
|
||||
$host = parse_url($msg['from-url'], PHP_URL_HOST);
|
||||
$msg['guid'] = Item::guidFromUri($msg['uri'], $host);
|
||||
}
|
||||
|
||||
DBA::lock('mail');
|
||||
|
||||
if (DBA::exists('mail', ['uri' => $msg['uri'], 'uid' => $msg['uid']])) {
|
||||
DBA::unlock();
|
||||
Logger::info('duplicate message already delivered.');
|
||||
return false;
|
||||
}
|
||||
|
||||
DBA::insert('mail', $msg);
|
||||
|
||||
$msg['id'] = DBA::lastInsertId();
|
||||
|
||||
DBA::unlock();
|
||||
|
||||
if (!empty($msg['convid'])) {
|
||||
DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $msg['convid']]);
|
||||
}
|
||||
|
||||
// send notifications.
|
||||
$notif_params = [
|
||||
'type' => NOTIFY_MAIL,
|
||||
'notify_flags' => $user['notify-flags'],
|
||||
'language' => $user['language'],
|
||||
'to_name' => $user['username'],
|
||||
'to_email' => $user['email'],
|
||||
'uid' => $user['uid'],
|
||||
'item' => $msg,
|
||||
'parent' => $msg['parent-uri'],
|
||||
'source_name' => $msg['from-name'],
|
||||
'source_link' => $msg['from-url'],
|
||||
'source_photo' => $msg['from-photo'],
|
||||
'verb' => ACTIVITY_POST,
|
||||
'otype' => 'mail'
|
||||
];
|
||||
|
||||
notification($notif_params);
|
||||
|
||||
Logger::info('Mail is processed, notification was sent.', ['id' => $msg['id'], 'uri' => $msg['uri']]);
|
||||
|
||||
return $msg['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Send private message
|
||||
*
|
||||
|
@ -48,7 +113,7 @@ class Mail
|
|||
}
|
||||
|
||||
$guid = System::createUUID();
|
||||
$uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
|
||||
$uri = Item::newURI(local_user(), $guid);
|
||||
|
||||
$convid = 0;
|
||||
$reply = false;
|
||||
|
@ -176,7 +241,7 @@ class Mail
|
|||
}
|
||||
|
||||
$guid = System::createUUID();
|
||||
$uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
|
||||
$uri = Item::newURI(local_user(), $guid);
|
||||
|
||||
$me = Probe::uri($replyto);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue