forked from GNUsocial/gnu-social
[COMPONENT][Posting] Page should flush with a different notification
This commit is contained in:
parent
b6ed0b4c6c
commit
b69f4a46c5
@ -139,7 +139,7 @@ class Post extends Controller
|
|||||||
$extra_args = [];
|
$extra_args = [];
|
||||||
Event::handle('AddExtraArgsToNoteContent', [$request, $actor, $data, &$extra_args, $form_params, $form]);
|
Event::handle('AddExtraArgsToNoteContent', [$request, $actor, $data, &$extra_args, $form_params, $form]);
|
||||||
|
|
||||||
$note = Posting::storeLocalPage(
|
[,$note,] = Posting::storeLocalPage(
|
||||||
actor: $actor,
|
actor: $actor,
|
||||||
content: $data['content'],
|
content: $data['content'],
|
||||||
content_type: $content_type,
|
content_type: $content_type,
|
||||||
|
@ -216,21 +216,21 @@ class Posting extends Component
|
|||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public static function storeLocalPage(
|
public static function storeLocalPage(
|
||||||
Actor $actor,
|
Actor $actor,
|
||||||
?string $content,
|
?string $content,
|
||||||
string $content_type,
|
string $content_type,
|
||||||
?string $locale = null,
|
?string $locale = null,
|
||||||
?VisibilityScope $scope = null,
|
?VisibilityScope $scope = null,
|
||||||
array $targets = [],
|
array $targets = [],
|
||||||
null|int|Note $reply_to = null,
|
null|int|Note $reply_to = null,
|
||||||
array $attachments = [],
|
array $attachments = [],
|
||||||
array $processed_attachments = [],
|
array $processed_attachments = [],
|
||||||
array $process_note_content_extra_args = [],
|
array $process_note_content_extra_args = [],
|
||||||
bool $notify = true,
|
bool $flush_and_notify = true,
|
||||||
?string $rendered = null,
|
?string $rendered = null,
|
||||||
string $source = 'web',
|
string $source = 'web',
|
||||||
): Note {
|
): array {
|
||||||
$note = self::storeLocalNote(
|
[$activity, $note, $attention_ids] = self::storeLocalNote(
|
||||||
actor: $actor,
|
actor: $actor,
|
||||||
content: $content,
|
content: $content,
|
||||||
content_type: $content_type,
|
content_type: $content_type,
|
||||||
@ -241,11 +241,19 @@ class Posting extends Component
|
|||||||
attachments: $attachments,
|
attachments: $attachments,
|
||||||
processed_attachments: $processed_attachments,
|
processed_attachments: $processed_attachments,
|
||||||
process_note_content_extra_args: $process_note_content_extra_args,
|
process_note_content_extra_args: $process_note_content_extra_args,
|
||||||
notify: $notify,
|
flush_and_notify: false,
|
||||||
rendered: $rendered,
|
rendered: $rendered,
|
||||||
source: $source
|
source: $source
|
||||||
);
|
);
|
||||||
return $note->setType(NoteType::PAGE);
|
$note->setType(NoteType::PAGE);
|
||||||
|
|
||||||
|
if ($flush_and_notify) {
|
||||||
|
// Flush before notification
|
||||||
|
DB::flush();
|
||||||
|
Event::handle('NewNotification', [$actor, $activity, ['object' => $attention_ids], _m('{nickname} created a page {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$activity, $note, $attention_ids];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -263,10 +271,10 @@ class Posting extends Component
|
|||||||
* @param array $attachments UploadedFile[] to be stored as GSFiles associated to this note
|
* @param array $attachments UploadedFile[] to be stored as GSFiles associated to this note
|
||||||
* @param array $processed_attachments Array of [Attachment, Attachment's name][] to be associated to this $actor and Note
|
* @param array $processed_attachments Array of [Attachment, Attachment's name][] to be associated to this $actor and Note
|
||||||
* @param array $process_note_content_extra_args Extra arguments for the event ProcessNoteContent
|
* @param array $process_note_content_extra_args Extra arguments for the event ProcessNoteContent
|
||||||
* @param bool $notify True if the newly created Note activity should be passed on as a Notification
|
* @param bool $flush_and_notify True if the newly created Note activity should be passed on as a Notification
|
||||||
* @param null|string $rendered The Note's content post RenderNoteContent event, which sanitizes and processes the raw content sent
|
* @param null|string $rendered The Note's content post RenderNoteContent event, which sanitizes and processes the raw content sent
|
||||||
* @param string $source The source of this Note
|
* @param string $source The source of this Note
|
||||||
* @return Note
|
* @return array [Activity, Note, int[]] Activity, Note, Attention Ids
|
||||||
* @throws ClientException
|
* @throws ClientException
|
||||||
* @throws DuplicateFoundException
|
* @throws DuplicateFoundException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
@ -282,10 +290,10 @@ class Posting extends Component
|
|||||||
array $attachments = [],
|
array $attachments = [],
|
||||||
array $processed_attachments = [],
|
array $processed_attachments = [],
|
||||||
array $process_note_content_extra_args = [],
|
array $process_note_content_extra_args = [],
|
||||||
bool $notify = true,
|
bool $flush_and_notify = true,
|
||||||
?string $rendered = null,
|
?string $rendered = null,
|
||||||
string $source = 'web',
|
string $source = 'web',
|
||||||
): Note {
|
): array {
|
||||||
$scope ??= VisibilityScope::EVERYWHERE; // TODO: If site is private, default to LOCAL
|
$scope ??= VisibilityScope::EVERYWHERE; // TODO: If site is private, default to LOCAL
|
||||||
$reply_to_id = is_null($reply_to) ? null : (is_int($reply_to) ? $reply_to : $reply_to->getId());
|
$reply_to_id = is_null($reply_to) ? null : (is_int($reply_to) ? $reply_to : $reply_to->getId());
|
||||||
$mentions = [];
|
$mentions = [];
|
||||||
@ -360,16 +368,15 @@ class Posting extends Component
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$mention_ids = F\unique(F\flat_map($mentions, fn (array $m) => F\map($m['mentioned'] ?? [], fn (Actor $a) => $a->getId())));
|
$attention_ids = F\unique(F\flat_map($mentions, fn (array $m) => F\map($m['mentioned'] ?? [], fn (Actor $a) => $a->getId())));
|
||||||
|
|
||||||
// Flush before notification
|
if ($flush_and_notify) {
|
||||||
DB::flush();
|
// Flush before notification
|
||||||
|
DB::flush();
|
||||||
if ($notify) {
|
Event::handle('NewNotification', [$actor, $activity, ['object' => $attention_ids], _m('{nickname} created a note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
||||||
Event::handle('NewNotification', [$actor, $activity, ['object' => $mention_ids], _m('{nickname} created a note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $note;
|
return [$activity, $note, $attention_ids];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?string $language = null, array &$mentions = [])
|
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?string $language = null, array &$mentions = [])
|
||||||
|
@ -80,7 +80,7 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
$original_note_id = $note->getId();
|
$original_note_id = $note->getId();
|
||||||
|
|
||||||
// Create a new note with the same content as the original
|
// Create a new note with the same content as the original
|
||||||
$repeat = Posting::storeLocalNote(
|
[, $repeat, ] = Posting::storeLocalNote(
|
||||||
actor: Actor::getById($actor_id),
|
actor: Actor::getById($actor_id),
|
||||||
content: $note->getContent(),
|
content: $note->getContent(),
|
||||||
content_type: $note->getContentType(),
|
content_type: $note->getContentType(),
|
||||||
@ -88,7 +88,7 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
// If it's a repeat, the reply_to should be to the original, conversation ought to be the same
|
// If it's a repeat, the reply_to should be to the original, conversation ought to be the same
|
||||||
reply_to: $note->getReplyTo(),
|
reply_to: $note->getReplyTo(),
|
||||||
processed_attachments: $note->getAttachmentsWithTitle(),
|
processed_attachments: $note->getAttachmentsWithTitle(),
|
||||||
notify: false,
|
flush_and_notify: false,
|
||||||
rendered: $note->getRendered(),
|
rendered: $note->getRendered(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -110,6 +110,9 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
]);
|
]);
|
||||||
DB::persist($repeat_activity);
|
DB::persist($repeat_activity);
|
||||||
|
|
||||||
|
// Flush before notification
|
||||||
|
DB::flush();
|
||||||
|
|
||||||
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $repeat_activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $repeat_activity->getObjectId()])]);
|
Event::handle('NewNotification', [$actor = Actor::getById($actor_id), $repeat_activity, [], _m('{nickname} repeated note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $repeat_activity->getObjectId()])]);
|
||||||
|
|
||||||
return $repeat_activity;
|
return $repeat_activity;
|
||||||
|
Loading…
Reference in New Issue
Block a user