fix(pairing): Received installation event (#3422)

This commit is contained in:
Igor Sirotin 2023-04-26 14:48:49 +03:00 committed by GitHub
parent 2950d37e43
commit b8209cbc7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 10 deletions

View File

@ -1 +1 @@
0.147.1
0.148.0

View File

@ -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

View File

@ -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

View File

@ -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
}
/*

View File

@ -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
}

23
server/pairing/utils.go Normal file
View File

@ -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
}