Backup deleted communities
This commit is contained in:
parent
e215e7b923
commit
9de4eb3c8a
|
@ -226,6 +226,10 @@ func (m *Manager) JoinedAndPendingCommunitiesWithRequests() ([]*Community, error
|
||||||
return m.persistence.JoinedAndPendingCommunitiesWithRequests(m.identity)
|
return m.persistence.JoinedAndPendingCommunitiesWithRequests(m.identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) DeletedCommunities() ([]*Community, error) {
|
||||||
|
return m.persistence.DeletedCommunities(m.identity)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) Created() ([]*Community, error) {
|
func (m *Manager) Created() ([]*Community, error) {
|
||||||
return m.persistence.CreatedCommunities(m.identity)
|
return m.persistence.CreatedCommunities(m.identity)
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,19 +104,7 @@ func (p *Persistence) JoinedCommunities(memberIdentity *ecdsa.PublicKey) ([]*Com
|
||||||
return p.queryCommunities(memberIdentity, query)
|
return p.queryCommunities(memberIdentity, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Persistence) JoinedAndPendingCommunitiesWithRequests(memberIdentity *ecdsa.PublicKey) (comms []*Community, err error) {
|
func (p *Persistence) rowsToCommunities(memberIdentity *ecdsa.PublicKey, rows *sql.Rows) (comms []*Community, err error) {
|
||||||
query := `SELECT
|
|
||||||
c.id, c.private_key, c.description, c.joined, c.verified, c.muted,
|
|
||||||
r.id, r.public_key, r.clock, r.ens_name, r.chat_id, r.community_id, r.state
|
|
||||||
FROM communities_communities c
|
|
||||||
LEFT JOIN communities_requests_to_join r ON c.id = r.community_id AND r.public_key = ?
|
|
||||||
WHERE c.Joined OR r.state = ?`
|
|
||||||
|
|
||||||
rows, err := p.db.Query(query, common.PubkeyToHex(memberIdentity), RequestToJoinStatePending)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't shadow original error
|
// Don't shadow original error
|
||||||
|
@ -161,6 +149,38 @@ WHERE c.Joined OR r.state = ?`
|
||||||
return comms, nil
|
return comms, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Persistence) JoinedAndPendingCommunitiesWithRequests(memberIdentity *ecdsa.PublicKey) (comms []*Community, err error) {
|
||||||
|
query := `SELECT
|
||||||
|
c.id, c.private_key, c.description, c.joined, c.verified, c.muted,
|
||||||
|
r.id, r.public_key, r.clock, r.ens_name, r.chat_id, r.community_id, r.state
|
||||||
|
FROM communities_communities c
|
||||||
|
LEFT JOIN communities_requests_to_join r ON c.id = r.community_id AND r.public_key = ?
|
||||||
|
WHERE c.Joined OR r.state = ?`
|
||||||
|
|
||||||
|
rows, err := p.db.Query(query, common.PubkeyToHex(memberIdentity), RequestToJoinStatePending)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.rowsToCommunities(memberIdentity, rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Persistence) DeletedCommunities(memberIdentity *ecdsa.PublicKey) (comms []*Community, err error) {
|
||||||
|
query := `SELECT
|
||||||
|
c.id, c.private_key, c.description, c.joined, c.verified, c.muted,
|
||||||
|
r.id, r.public_key, r.clock, r.ens_name, r.chat_id, r.community_id, r.state
|
||||||
|
FROM communities_communities c
|
||||||
|
LEFT JOIN communities_requests_to_join r ON c.id = r.community_id AND r.public_key = ?
|
||||||
|
WHERE NOT c.Joined AND (r.community_id IS NULL or r.state != ?)`
|
||||||
|
|
||||||
|
rows, err := p.db.Query(query, common.PubkeyToHex(memberIdentity), RequestToJoinStatePending)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.rowsToCommunities(memberIdentity, rows)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Persistence) CreatedCommunities(memberIdentity *ecdsa.PublicKey) ([]*Community, error) {
|
func (p *Persistence) CreatedCommunities(memberIdentity *ecdsa.PublicKey) ([]*Community, error) {
|
||||||
query := communitiesBaseQuery + ` WHERE c.private_key IS NOT NULL`
|
query := communitiesBaseQuery + ` WHERE c.private_key IS NOT NULL`
|
||||||
return p.queryCommunities(memberIdentity, query)
|
return p.queryCommunities(memberIdentity, query)
|
||||||
|
|
|
@ -119,10 +119,17 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cs, err := m.communitiesManager.JoinedAndPendingCommunitiesWithRequests()
|
joinedCs, err := m.communitiesManager.JoinedAndPendingCommunitiesWithRequests()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deletedCs, err := m.communitiesManager.DeletedCommunities()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cs := append(joinedCs, deletedCs...)
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
|
|
||||||
syncMessage, err := c.ToSyncCommunityProtobuf(clock)
|
syncMessage, err := c.ToSyncCommunityProtobuf(clock)
|
||||||
|
|
|
@ -309,6 +309,7 @@ func (m *Messenger) HandleBackup(state *ReceivedMessageState, message protobuf.B
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue