feat: delete profile showcase community entry on community leave or kicked (#4686)
This commit is contained in:
parent
2350461818
commit
9b7926b23b
|
@ -1817,6 +1817,11 @@ func (m *Messenger) leaveCommunity(communityID types.HexBytes) (*MessengerRespon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = m.DeleteProfileShowcaseCommunity(community)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
_, err = m.transport.RemoveFilterByChatID(communityID.String())
|
_, err = m.transport.RemoveFilterByChatID(communityID.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1834,6 +1839,11 @@ func (m *Messenger) kickedOutOfCommunity(communityID types.HexBytes) (*Messenger
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = m.DeleteProfileShowcaseCommunity(community)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
response.AddCommunity(community)
|
response.AddCommunity(community)
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||||
"github.com/status-im/status-go/protocol/common"
|
"github.com/status-im/status-go/protocol/common"
|
||||||
|
"github.com/status-im/status-go/protocol/communities"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -477,10 +478,25 @@ func (m *Messenger) UpdateProfileShowcaseWalletAccount(account *accounts.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) DeleteProfileShowcaseWalletAccount(account *accounts.Account) error {
|
func (m *Messenger) DeleteProfileShowcaseWalletAccount(account *accounts.Account) error {
|
||||||
err := m.persistence.DeleteProfileShowcaseAccountPreference(account.Address.Hex())
|
deleted, err := m.persistence.DeleteProfileShowcaseAccountPreference(account.Address.Hex())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.DispatchProfileShowcase()
|
if deleted {
|
||||||
|
return m.DispatchProfileShowcase()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) DeleteProfileShowcaseCommunity(community *communities.Community) error {
|
||||||
|
deleted, err := m.persistence.DeleteProfileShowcaseCommunityPreference(community.IDString())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if deleted {
|
||||||
|
return m.DispatchProfileShowcase()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ const (
|
||||||
|
|
||||||
const upsertProfileShowcaseCommunityPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_communities_preferences(community_id, visibility, sort_order) VALUES (?, ?, ?)" // #nosec G101
|
const upsertProfileShowcaseCommunityPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_communities_preferences(community_id, visibility, sort_order) VALUES (?, ?, ?)" // #nosec G101
|
||||||
const selectProfileShowcaseCommunityPreferenceQuery = "SELECT community_id, visibility, sort_order FROM profile_showcase_communities_preferences" // #nosec G101
|
const selectProfileShowcaseCommunityPreferenceQuery = "SELECT community_id, visibility, sort_order FROM profile_showcase_communities_preferences" // #nosec G101
|
||||||
|
const deleteProfileShowcaseCommunityPreferenceQuery = "DELETE FROM profile_showcase_communities_preferences WHERE community_id = ?" // #nosec G101
|
||||||
|
|
||||||
const upsertProfileShowcaseAccountPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_accounts_preferences(address, name, color_id, emoji, visibility, sort_order) VALUES (?, ?, ?, ?, ?, ?)" // #nosec G101
|
const upsertProfileShowcaseAccountPreferenceQuery = "INSERT OR REPLACE INTO profile_showcase_accounts_preferences(address, name, color_id, emoji, visibility, sort_order) VALUES (?, ?, ?, ?, ?, ?)" // #nosec G101
|
||||||
const selectProfileShowcaseAccountPreferenceQuery = "SELECT address, name, color_id, emoji, visibility, sort_order FROM profile_showcase_accounts_preferences" // #nosec G101
|
const selectProfileShowcaseAccountPreferenceQuery = "SELECT address, name, color_id, emoji, visibility, sort_order FROM profile_showcase_accounts_preferences" // #nosec G101
|
||||||
|
@ -255,10 +256,24 @@ func (db sqlitePersistence) GetProfileShowcaseAccountPreference(accountAddress s
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) DeleteProfileShowcaseAccountPreference(accountAddress string) error {
|
func (db sqlitePersistence) DeleteProfileShowcaseAccountPreference(accountAddress string) (bool, error) {
|
||||||
_, err := db.db.Exec(deleteProfileShowcaseAccountPreferenceQuery, accountAddress)
|
result, err := db.db.Exec(deleteProfileShowcaseAccountPreferenceQuery, accountAddress)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
rows, err := result.RowsAffected()
|
||||||
|
return rows > 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db sqlitePersistence) DeleteProfileShowcaseCommunityPreference(communityID string) (bool, error) {
|
||||||
|
result, err := db.db.Exec(deleteProfileShowcaseCommunityPreferenceQuery, communityID)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := result.RowsAffected()
|
||||||
|
return rows > 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db sqlitePersistence) saveProfileShowcaseCollectiblePreference(tx *sql.Tx, collectible *ProfileShowcaseCollectiblePreference) error {
|
func (db sqlitePersistence) saveProfileShowcaseCollectiblePreference(tx *sql.Tx, collectible *ProfileShowcaseCollectiblePreference) error {
|
||||||
|
|
|
@ -421,8 +421,14 @@ func (s *TestProfileShowcasePersistence) TestUpdateProfileShowcaseAccountOnWalle
|
||||||
err = persistence.SaveProfileShowcaseAccountPreference(account)
|
err = persistence.SaveProfileShowcaseAccountPreference(account)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = persistence.DeleteProfileShowcaseAccountPreference(deleteAccountAddress)
|
deleted, err := persistence.DeleteProfileShowcaseAccountPreference(deleteAccountAddress)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
s.Require().True(deleted)
|
||||||
|
|
||||||
|
// One more time to check correct error handling
|
||||||
|
deleted, err = persistence.DeleteProfileShowcaseAccountPreference(deleteAccountAddress)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().False(deleted)
|
||||||
|
|
||||||
preferencesBack, err := persistence.GetProfileShowcasePreferences()
|
preferencesBack, err := persistence.GetProfileShowcasePreferences()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -430,3 +436,44 @@ func (s *TestProfileShowcasePersistence) TestUpdateProfileShowcaseAccountOnWalle
|
||||||
s.Require().Len(preferencesBack.Accounts, 1)
|
s.Require().Len(preferencesBack.Accounts, 1)
|
||||||
s.Require().Equal(*preferencesBack.Accounts[0], *account)
|
s.Require().Equal(*preferencesBack.Accounts[0], *account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TestProfileShowcasePersistence) TestUpdateProfileShowcaseCommunityOnChange() {
|
||||||
|
db, err := openTestDB()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
persistence := newSQLitePersistence(db)
|
||||||
|
|
||||||
|
deleteCommunityID := "0x3243344513424"
|
||||||
|
|
||||||
|
preferences := &ProfileShowcasePreferences{
|
||||||
|
Communities: []*ProfileShowcaseCommunityPreference{
|
||||||
|
&ProfileShowcaseCommunityPreference{
|
||||||
|
CommunityID: "0x32433445133424",
|
||||||
|
ShowcaseVisibility: ProfileShowcaseVisibilityEveryone,
|
||||||
|
Order: 0,
|
||||||
|
},
|
||||||
|
&ProfileShowcaseCommunityPreference{
|
||||||
|
CommunityID: deleteCommunityID,
|
||||||
|
ShowcaseVisibility: ProfileShowcaseVisibilityContacts,
|
||||||
|
Order: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = persistence.SaveProfileShowcasePreferences(preferences)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
deleted, err := persistence.DeleteProfileShowcaseCommunityPreference(deleteCommunityID)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().True(deleted)
|
||||||
|
|
||||||
|
// One more time to check correct error handling
|
||||||
|
deleted, err = persistence.DeleteProfileShowcaseCommunityPreference(deleteCommunityID)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().False(deleted)
|
||||||
|
|
||||||
|
preferencesBack, err := persistence.GetProfileShowcasePreferences()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.Require().Len(preferencesBack.Communities, 1)
|
||||||
|
s.Require().Equal(*preferencesBack.Communities[0], *preferences.Communities[0])
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue