fix(RequestCommunityInfoFromMailserver): Add useDatabase flag to read/not read community info before requesting mailserver..

Fix #2878
This commit is contained in:
Michal Iskierko 2022-09-23 12:15:06 +02:00 committed by Michał Iskierko
parent 4c29c97591
commit 6e96586bdb
4 changed files with 15 additions and 12 deletions

View File

@ -145,7 +145,7 @@ func main() {
messenger := wakuextservice.Messenger() messenger := wakuextservice.Messenger()
community, err := messenger.RequestCommunityInfoFromMailserver(*communityID) community, err := messenger.RequestCommunityInfoFromMailserver(*communityID, true)
if err != nil { if err != nil {
logger.Error("community error", "error", err) logger.Error("community error", "error", err)

View File

@ -1114,7 +1114,7 @@ func (m *Messenger) ImportCommunity(ctx context.Context, key *ecdsa.PrivateKey)
//request info already stored on mailserver, but its success is not crucial //request info already stored on mailserver, but its success is not crucial
// for import // for import
_, _ = m.RequestCommunityInfoFromMailserver(community.IDString()) _, _ = m.RequestCommunityInfoFromMailserver(community.IDString(), false)
// We add ourselves // We add ourselves
community, err = m.communitiesManager.AddMemberToCommunity(community.ID(), &m.identity.PublicKey) community, err = m.communitiesManager.AddMemberToCommunity(community.ID(), &m.identity.PublicKey)
@ -1342,14 +1342,17 @@ func (m *Messenger) findCommunityInfoFromDB(communityID string) (*communities.Co
} }
// RequestCommunityInfoFromMailserver installs filter for community and requests its details // RequestCommunityInfoFromMailserver installs filter for community and requests its details
// from mailserver. It waits until it has the community before returning it // from mailserver. It waits until it has the community before returning it.
func (m *Messenger) RequestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) { // If useDatabase is true, it searches for community in database and does not request mailserver.
community, err := m.findCommunityInfoFromDB(communityID) func (m *Messenger) RequestCommunityInfoFromMailserver(communityID string, useDatabase bool) (*communities.Community, error) {
if err != nil { if useDatabase {
return nil, err community, err := m.findCommunityInfoFromDB(communityID)
} if err != nil {
if community != nil { return nil, err
return community, nil }
if community != nil {
return community, nil
}
} }
return m.requestCommunityInfoFromMailserver(communityID, true) return m.requestCommunityInfoFromMailserver(communityID, true)
} }

View File

@ -1032,7 +1032,7 @@ func (api *PublicAPI) EnsVerified(pk, ensName string) error {
} }
func (api *PublicAPI) RequestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) { func (api *PublicAPI) RequestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) {
return api.service.messenger.RequestCommunityInfoFromMailserver(communityID) return api.service.messenger.RequestCommunityInfoFromMailserver(communityID, true)
} }
func (api *PublicAPI) RequestCommunityInfoFromMailserverAsync(communityID string) error { func (api *PublicAPI) RequestCommunityInfoFromMailserverAsync(communityID string) error {

View File

@ -74,7 +74,7 @@ func (p *PublicAPI) CommunityInfo(communityID types.HexBytes) (json.RawMessage,
return nil, ErrNotInitialized return nil, ErrNotInitialized
} }
community, err := p.service.messenger.RequestCommunityInfoFromMailserver(communityID.String()) community, err := p.service.messenger.RequestCommunityInfoFromMailserver(communityID.String(), true)
if err != nil { if err != nil {
return nil, err return nil, err
} }