feat: Added `setInstallationName` method (#3294)

This commit is contained in:
Igor Sirotin 2023-03-20 23:51:17 +11:00 committed by GitHub
parent 94cd1ecebe
commit 7e8804788e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 2 deletions

View File

@ -1 +1 @@
0.138.6
0.138.7

View File

@ -109,6 +109,11 @@ func (s *Multidevice) SetInstallationMetadata(identity *ecdsa.PublicKey, install
return s.persistence.SetInstallationMetadata(identityC, installationID, metadata)
}
func (s *Multidevice) SetInstallationName(identity *ecdsa.PublicKey, installationID string, name string) error {
identityC := crypto.CompressPubkey(identity)
return s.persistence.SetInstallationName(identityC, installationID, name)
}
func (s *Multidevice) EnableInstallation(identity *ecdsa.PublicKey, installationID string) error {
identityC := crypto.CompressPubkey(identity)
return s.persistence.EnableInstallation(identityC, installationID)

View File

@ -263,3 +263,16 @@ func (s *sqlitePersistence) SetInstallationMetadata(identity []byte, installatio
_, err = stmt.Exec(metadata.Name, metadata.DeviceType, metadata.FCMToken, identity, installationID)
return err
}
// SetInstallationName sets the only the name in metadata for a given installation
func (s *sqlitePersistence) SetInstallationName(identity []byte, installationID string, name string) error {
stmt, err := s.db.Prepare(`UPDATE installation_metadata
SET name = ?
WHERE identity = ? AND installation_id = ?`)
if err != nil {
return err
}
_, err = stmt.Exec(name, identity, installationID)
return err
}

View File

@ -471,6 +471,11 @@ func (p *Protocol) SetInstallationMetadata(myIdentityKey *ecdsa.PublicKey, insta
return p.multidevice.SetInstallationMetadata(myIdentityKey, installationID, data)
}
// SetInstallationName sets the metadata for our own installation
func (p *Protocol) SetInstallationName(myIdentityKey *ecdsa.PublicKey, installationID string, name string) error {
return p.multidevice.SetInstallationName(myIdentityKey, installationID, name)
}
// GetPublicBundle retrieves a public bundle given an identity
func (p *Protocol) GetPublicBundle(theirIdentityKey *ecdsa.PublicKey) (*Bundle, error) {
installations, err := p.multidevice.GetActiveInstallations(theirIdentityKey)

View File

@ -1657,13 +1657,23 @@ func (m *Messenger) setInstallationMetadata(id string, data *multidevice.Install
}
installation.InstallationMetadata = data
return m.encryptor.SetInstallationMetadata(&m.identity.PublicKey, id, data)
return m.encryptor.SetInstallationMetadata(m.IdentityPublicKey(), id, data)
}
func (m *Messenger) SetInstallationMetadata(id string, data *multidevice.InstallationMetadata) error {
return m.setInstallationMetadata(id, data)
}
func (m *Messenger) SetInstallationName(id string, name string) error {
installation, ok := m.allInstallations.Load(id)
if !ok {
return errors.New("no installation found")
}
installation.InstallationMetadata.Name = name
return m.encryptor.SetInstallationName(m.IdentityPublicKey(), id, name)
}
// NOT IMPLEMENTED
func (m *Messenger) SelectMailserver(id string) error {
return ErrNotImplemented

View File

@ -358,6 +358,11 @@ func (api *PublicAPI) SetInstallationMetadata(installationID string, data *multi
return api.service.messenger.SetInstallationMetadata(installationID, data)
}
// SetInstallationName sets the only the name in metadata for a given installation
func (api *PublicAPI) SetInstallationName(installationID string, name string) error {
return api.service.messenger.SetInstallationName(installationID, name)
}
// Communities returns a list of communities that are stored
func (api *PublicAPI) Communities(parent context.Context) ([]*communities.Community, error) {
return api.service.messenger.Communities()