mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add callback on megolm session receive
This commit is contained in:
parent
a8e1ae1936
commit
bb6c88faf3
4 changed files with 12 additions and 5 deletions
|
|
@ -179,6 +179,6 @@ func (mach *OlmMachine) ImportRoomKeyFromBackup(ctx context.Context, version id.
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to store new inbound group session: %w", err)
|
||||
}
|
||||
mach.markSessionReceived(sessionID)
|
||||
mach.markSessionReceived(ctx, sessionID)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ func (mach *OlmMachine) importExportedRoomKey(ctx context.Context, session Expor
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("failed to store imported session: %w", err)
|
||||
}
|
||||
mach.markSessionReceived(igs.ID())
|
||||
mach.markSessionReceived(ctx, igs.ID())
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ func (mach *OlmMachine) importForwardedRoomKey(ctx context.Context, evt *Decrypt
|
|||
log.Error().Err(err).Msg("Failed to store new inbound group session")
|
||||
return false
|
||||
}
|
||||
mach.markSessionReceived(content.SessionID)
|
||||
mach.markSessionReceived(ctx, content.SessionID)
|
||||
log.Debug().Msg("Received forwarded inbound group session")
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ type OlmMachine struct {
|
|||
keyWaiters map[id.SessionID]chan struct{}
|
||||
keyWaitersLock sync.Mutex
|
||||
|
||||
// Optional callback which is called when we save a session to store
|
||||
SessionReceived func(context.Context, id.SessionID)
|
||||
|
||||
devicesToUnwedge map[id.IdentityKey]bool
|
||||
devicesToUnwedgeLock sync.Mutex
|
||||
recentlyUnwedged map[id.IdentityKey]time.Time
|
||||
|
|
@ -520,7 +523,7 @@ func (mach *OlmMachine) createGroupSession(ctx context.Context, senderKey id.Sen
|
|||
log.Error().Err(err).Str("session_id", sessionID.String()).Msg("Failed to store new inbound group session")
|
||||
return
|
||||
}
|
||||
mach.markSessionReceived(sessionID)
|
||||
mach.markSessionReceived(ctx, sessionID)
|
||||
log.Debug().
|
||||
Str("session_id", sessionID.String()).
|
||||
Str("sender_key", senderKey.String()).
|
||||
|
|
@ -530,7 +533,11 @@ func (mach *OlmMachine) createGroupSession(ctx context.Context, senderKey id.Sen
|
|||
Msg("Received inbound group session")
|
||||
}
|
||||
|
||||
func (mach *OlmMachine) markSessionReceived(id id.SessionID) {
|
||||
func (mach *OlmMachine) markSessionReceived(ctx context.Context, id id.SessionID) {
|
||||
if mach.SessionReceived != nil {
|
||||
mach.SessionReceived(ctx, id)
|
||||
}
|
||||
|
||||
mach.keyWaitersLock.Lock()
|
||||
ch, ok := mach.keyWaiters[id]
|
||||
if ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue