bridgev2/networkinterface: add post-save callback for matrix messages
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

This commit is contained in:
Tulir Asokan 2024-10-07 16:12:43 +03:00
commit 7a9269e8ff
2 changed files with 5 additions and 0 deletions

View file

@ -284,6 +284,9 @@ type MatrixMessageResponse struct {
// If RemovePending is set, the bridge will remove the provided transaction ID from pending messages
// after saving the provided message to the database. This should be used with AddPendingToIgnore.
RemovePending networkid.TransactionID
// An optional function that is called after the message is saved to the database.
// Will not be called if the message is not saved for some reason.
PostSave func(context.Context, *database.Message)
}
type FileRestriction struct {

View file

@ -928,6 +928,8 @@ func (portal *Portal) handleMatrixMessage(ctx context.Context, sender *UserLogin
err = portal.Bridge.DB.Message.Insert(ctx, message)
if err != nil {
log.Err(err).Msg("Failed to save message to database")
} else if resp.PostSave != nil {
resp.PostSave(ctx, message)
}
if resp.RemovePending != "" {
portal.outgoingMessagesLock.Lock()