fix: make fetchCommunity return latest available community
Fixes #13145
This commit is contained in:
parent
16f11d49df
commit
9d9c40b7cf
|
@ -2535,7 +2535,7 @@ func (m *Messenger) RemoveRoleFromMember(request *requests.RemoveRoleFromMember)
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) findCommunityInfoFromDB(communityID string) (*communities.Community, error) {
|
func (m *Messenger) FindCommunityInfoFromDB(communityID string) (*communities.Community, error) {
|
||||||
id, err := hexutil.Decode(communityID)
|
id, err := hexutil.Decode(communityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2564,7 +2564,7 @@ func (m *Messenger) FetchCommunity(request *FetchCommunityRequest) (*communities
|
||||||
communityID := request.getCommunityID()
|
communityID := request.getCommunityID()
|
||||||
|
|
||||||
if request.TryDatabase {
|
if request.TryDatabase {
|
||||||
community, err := m.findCommunityInfoFromDB(communityID)
|
community, err := m.FindCommunityInfoFromDB(communityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -549,7 +549,9 @@ func (s *Service) FillCollectibleMetadata(collectible *thirdparty.FullCollectibl
|
||||||
return fmt.Errorf("invalid communityID")
|
return fmt.Errorf("invalid communityID")
|
||||||
}
|
}
|
||||||
|
|
||||||
community, err := s.fetchCommunity(communityID, true)
|
// FetchCommunityInfo should have been previously called once to ensure
|
||||||
|
// that the latest version of the CommunityDescription is available in the DB
|
||||||
|
community, err := s.fetchCommunity(communityID, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -632,7 +634,7 @@ func communityToInfo(community *communities.Community) *thirdparty.CommunityInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) FetchCommunityInfo(communityID string) (*thirdparty.CommunityInfo, error) {
|
func (s *Service) FetchCommunityInfo(communityID string) (*thirdparty.CommunityInfo, error) {
|
||||||
community, err := s.fetchCommunity(communityID, false)
|
community, err := s.fetchCommunity(communityID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -640,7 +642,7 @@ func (s *Service) FetchCommunityInfo(communityID string) (*thirdparty.CommunityI
|
||||||
return communityToInfo(community), nil
|
return communityToInfo(community), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) fetchCommunity(communityID string, tryDatabase bool) (*communities.Community, error) {
|
func (s *Service) fetchCommunity(communityID string, fetchLatest bool) (*communities.Community, error) {
|
||||||
if s.messenger == nil {
|
if s.messenger == nil {
|
||||||
return nil, fmt.Errorf("messenger not ready")
|
return nil, fmt.Errorf("messenger not ready")
|
||||||
}
|
}
|
||||||
|
@ -650,14 +652,24 @@ func (s *Service) fetchCommunity(communityID string, tryDatabase bool) (*communi
|
||||||
// TODO: we need the shard information in the collectible to be able to retrieve info for
|
// TODO: we need the shard information in the collectible to be able to retrieve info for
|
||||||
// communities that have specific shards
|
// communities that have specific shards
|
||||||
|
|
||||||
var shard *shard.Shard = nil // TODO: build this with info from token
|
if fetchLatest {
|
||||||
community, err := s.messenger.FetchCommunity(&protocol.FetchCommunityRequest{
|
// Try to fetch the latest version of the Community
|
||||||
CommunityKey: communityID,
|
var shard *shard.Shard = nil // TODO: build this with info from token
|
||||||
Shard: shard,
|
// NOTE: The community returned by this function will be nil if
|
||||||
TryDatabase: tryDatabase,
|
// the version we have in the DB is the latest available.
|
||||||
WaitForResponse: true,
|
_, err := s.messenger.FetchCommunity(&protocol.FetchCommunityRequest{
|
||||||
})
|
CommunityKey: communityID,
|
||||||
|
Shard: shard,
|
||||||
|
TryDatabase: false,
|
||||||
|
WaitForResponse: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the latest successfully fetched version of the Community
|
||||||
|
community, err := s.messenger.FindCommunityInfoFromDB(communityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue