Add a final safety net in redirectToChannel.SendMessage that refuses a
message when ApplicationID == 0, so it can never be stored as an orphaned
message (application_id = 0, not shown, not deletable). Requested in review.
Cover the previously untested error branches around internal-application
back-fill (create/update failures) so patch coverage no longer regresses.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When a plugin gains the Messenger capability after it was first
initialized for a user, its plugin conf already exists without an
associated internal application (ApplicationID == 0). Messages sent by
the plugin were then stored with application_id = 0, orphaning them:
they disappeared on reload and could not be deleted (#653).
Back-fill the internal application during initialization when a
Messenger plugin has none yet, mirroring the creation already done for
plugins that support Messenger from the start.
Fixes#653
Co-Authored-By: Claude <noreply@anthropic.com>