fix(pairing): Received installation event (#3422)
This commit is contained in:
parent
2950d37e43
commit
b8209cbc7d
|
@ -3919,8 +3919,6 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
|
|||
}
|
||||
|
||||
case protobuf.ContactUpdate:
|
||||
logger.Info("<<< ContactUpdate", zap.String("publicKey", senderID))
|
||||
|
||||
if common.IsPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) {
|
||||
logger.Warn("coming from us, ignoring")
|
||||
continue
|
||||
|
|
|
@ -6,11 +6,12 @@ type EventType string
|
|||
const (
|
||||
// Both Sender and Receiver
|
||||
|
||||
EventPeerDiscovered EventType = "peer-discovered"
|
||||
EventConnectionError EventType = "connection-error"
|
||||
EventConnectionSuccess EventType = "connection-success"
|
||||
EventTransferError EventType = "transfer-error"
|
||||
EventTransferSuccess EventType = "transfer-success"
|
||||
EventPeerDiscovered EventType = "peer-discovered"
|
||||
EventConnectionError EventType = "connection-error"
|
||||
EventConnectionSuccess EventType = "connection-success"
|
||||
EventTransferError EventType = "transfer-error"
|
||||
EventTransferSuccess EventType = "transfer-success"
|
||||
EventReceivedInstallation EventType = "received-installation"
|
||||
|
||||
// Only Receiver side
|
||||
|
||||
|
|
|
@ -298,7 +298,23 @@ func (r *InstallationPayloadStorer) Store() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return messenger.HandleSyncRawMessages(r.payload.rawMessages)
|
||||
|
||||
installations := GetMessengerInstallationsMap(messenger)
|
||||
|
||||
err = messenger.HandleSyncRawMessages(r.payload.rawMessages)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newInstallation := FindNewInstallations(messenger, installations); newInstallation != nil {
|
||||
signal.SendLocalPairingEvent(Event{
|
||||
Type: EventReceivedInstallation,
|
||||
Action: ActionPairingInstallation,
|
||||
Data: newInstallation})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts/settings"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
|
||||
"github.com/status-im/status-go/signal"
|
||||
)
|
||||
|
||||
type SyncRawMessageHandler struct {
|
||||
|
@ -117,5 +119,21 @@ func (s *SyncRawMessageHandler) HandleRawMessage(accountPayload *AccountPayload,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return messenger.HandleSyncRawMessages(rmp.rawMessages)
|
||||
|
||||
installations := GetMessengerInstallationsMap(messenger)
|
||||
|
||||
err = messenger.HandleSyncRawMessages(rmp.rawMessages)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newInstallation := FindNewInstallations(messenger, installations); newInstallation != nil {
|
||||
signal.SendLocalPairingEvent(Event{
|
||||
Type: EventReceivedInstallation,
|
||||
Action: ActionPairingInstallation,
|
||||
Data: newInstallation})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package pairing
|
||||
|
||||
import (
|
||||
"github.com/status-im/status-go/protocol"
|
||||
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
||||
)
|
||||
|
||||
func GetMessengerInstallationsMap(m *protocol.Messenger) map[string]struct{} {
|
||||
ids := map[string]struct{}{}
|
||||
for _, installation := range m.Installations() {
|
||||
ids[installation.ID] = struct{}{}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
func FindNewInstallations(m *protocol.Messenger, prevInstallationIds map[string]struct{}) *multidevice.Installation {
|
||||
for _, installation := range m.Installations() {
|
||||
if _, ok := prevInstallationIds[installation.ID]; !ok {
|
||||
return installation
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue