Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions models/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

type Device struct {
VaultId string `gorm:"type:varchar(255);not null" json:"vault_id" binding:"required"`
PartyName string `gorm:"type:varchar(255);not null" json:"party_name" binding:"required"`
VaultId string `gorm:"type:varchar(255);not null;uniqueIndex:idx_vault_party" json:"vault_id" binding:"required"`
PartyName string `gorm:"type:varchar(255);not null;uniqueIndex:idx_vault_party" json:"party_name" binding:"required"`
Token string `gorm:"type:text;not null" json:"token" binding:"required"`
DeviceType string `gorm:"type:varchar(255);not null" json:"device_type" binding:"required"` // apple, android, or web
}
Expand Down
4 changes: 2 additions & 2 deletions service/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (s *NotificationService) processAppleNotification(ctx context.Context, devi
notification.Topic = appID
p := payload.NewPayload().Alert(nil).
AlertTitle("Vultisig Keysign request").
AlertSubtitle("Vault: " + request.VaultName).
AlertBody(request.QRCodeData).
AlertSubtitle("Vault: "+request.VaultName).
Custom("deeplink", request.QRCodeData).
Sound("default")
notification.Payload = p // See Payload section below

Expand Down
10 changes: 8 additions & 2 deletions storage/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/vultisig/notification/models"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/logger"
)

Expand Down Expand Up @@ -50,7 +51,12 @@ func (d *Database) RegisterDevice(ctx context.Context, device models.Device) err
cancel()
}()
deviceModel := device.GetDeviceDBModel()
result := d.db.WithContext(newContext).Create(&deviceModel)
result := d.db.WithContext(newContext).
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "vault_id"}, {Name: "party_name"}},
DoUpdates: clause.AssignmentColumns([]string{"token", "device_type", "updated_at"}),
}).
Create(&deviceModel)
if result.Error != nil {
return fmt.Errorf("failed to register device: %w", result.Error)
}
Expand All @@ -70,7 +76,7 @@ func (d *Database) UnregisterDevice(ctx context.Context, vaultId, tokenId string
defer func() {
cancel()
}()
result := d.db.WithContext(newContext).Where("vault_id = ? and token = ?", vaultId, tokenId).Delete(&models.DeviceDBModel{})
result := d.db.WithContext(newContext).Unscoped().Where("vault_id = ? and token = ?", vaultId, tokenId).Delete(&models.DeviceDBModel{})
if result.Error != nil {
return fmt.Errorf("failed to unregister device: %w", result.Error)
}
Expand Down