Skip to content

Commit 7a9269e

Browse files
committed
bridgev2/networkinterface: add post-save callback for matrix messages
1 parent 092ba65 commit 7a9269e

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

bridgev2/networkinterface.go

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

289292
type FileRestriction struct {

bridgev2/portal.go

+2
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,8 @@ func (portal *Portal) handleMatrixMessage(ctx context.Context, sender *UserLogin
928928
err = portal.Bridge.DB.Message.Insert(ctx, message)
929929
if err != nil {
930930
log.Err(err).Msg("Failed to save message to database")
931+
} else if resp.PostSave != nil {
932+
resp.PostSave(ctx, message)
931933
}
932934
if resp.RemovePending != "" {
933935
portal.outgoingMessagesLock.Lock()

0 commit comments

Comments
 (0)