feat: add RequestCommunityInfoFromMailserverAsync (#2537)
This function doesn't wait for the response from mailservers, so the client has to rely on signals
This commit is contained in:
parent
aa8a84bf91
commit
ece535aaf7
|
@ -746,21 +746,21 @@ func (m *Messenger) BanUserFromCommunity(request *requests.BanUserFromCommunity)
|
|||
}
|
||||
|
||||
// RequestCommunityInfoFromMailserver installs filter for community and requests its details
|
||||
// from mailserver. When response received it will be passed through signals handler
|
||||
// from mailserver. It waits until it has the community before returning it
|
||||
func (m *Messenger) RequestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) {
|
||||
return m.requestCommunityInfoFromMailserver(communityID)
|
||||
return m.requestCommunityInfoFromMailserver(communityID, true)
|
||||
}
|
||||
|
||||
// RequestCommunityInfoFromMailserverSync installs filter for community and requests its details
|
||||
// from mailserver. It will wait for a response and return it if any community is found
|
||||
func (m *Messenger) RequestCommunityInfoFromMailserverSync(communityID string) (*communities.Community, error) {
|
||||
return m.requestCommunityInfoFromMailserver(communityID)
|
||||
// RequestCommunityInfoFromMailserverAsync installs filter for community and requests its details
|
||||
// from mailserver. When response received it will be passed through signals handler
|
||||
func (m *Messenger) RequestCommunityInfoFromMailserverAsync(communityID string) error {
|
||||
_, err := m.requestCommunityInfoFromMailserver(communityID, false)
|
||||
return err
|
||||
}
|
||||
|
||||
// RequestCommunityInfoFromMailserver installs filter for community and requests its details
|
||||
// from mailserver. When response received it will be passed through signals handler
|
||||
func (m *Messenger) requestCommunityInfoFromMailserver(communityID string) (*communities.Community, error) {
|
||||
|
||||
func (m *Messenger) requestCommunityInfoFromMailserver(communityID string, waitForResponse bool) (*communities.Community, error) {
|
||||
if _, ok := m.requestedCommunities[communityID]; ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -792,12 +792,16 @@ func (m *Messenger) requestCommunityInfoFromMailserver(communityID string) (*com
|
|||
nil,
|
||||
nil,
|
||||
filter,
|
||||
true)
|
||||
waitForResponse)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !waitForResponse {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
defer cancel()
|
||||
|
|
|
@ -848,6 +848,10 @@ func (api *PublicAPI) RequestCommunityInfoFromMailserver(communityID string) (*c
|
|||
return api.service.messenger.RequestCommunityInfoFromMailserver(communityID)
|
||||
}
|
||||
|
||||
func (api *PublicAPI) RequestCommunityInfoFromMailserverAsync(communityID string) error {
|
||||
return api.service.messenger.RequestCommunityInfoFromMailserverAsync(communityID)
|
||||
}
|
||||
|
||||
func (api *PublicAPI) UnreadActivityCenterNotificationsCount() (uint64, error) {
|
||||
return api.service.messenger.UnreadActivityCenterNotificationsCount()
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func (p *PublicAPI) CommunityInfo(communityID types.HexBytes) (json.RawMessage,
|
|||
return nil, ErrNotInitialized
|
||||
}
|
||||
|
||||
community, err := p.service.messenger.RequestCommunityInfoFromMailserverSync(communityID.String())
|
||||
community, err := p.service.messenger.RequestCommunityInfoFromMailserver(communityID.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue