fix: handle nil descriptions in communities for chat_getChats (#2694)

This commit is contained in:
Richard Ramos 2022-06-08 08:46:52 -04:00 committed by GitHub
parent 30f8bd6dfb
commit 9430f494be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 13 deletions

View File

@ -301,6 +301,16 @@ func (o *Community) OutroMessage() string {
return "" return ""
} }
func (o *Community) Color() string {
if o != nil &&
o.config != nil &&
o.config.CommunityDescription != nil &&
o.config.CommunityDescription.Identity != nil {
return o.config.CommunityDescription.Identity.Color
}
return ""
}
func (o *Community) MembersCount() int { func (o *Community) MembersCount() int {
if o != nil && if o != nil &&
o.config != nil && o.config != nil &&
@ -1069,24 +1079,59 @@ func (o *Community) ToBytes() ([]byte, error) {
} }
func (o *Community) Chats() map[string]*protobuf.CommunityChat { func (o *Community) Chats() map[string]*protobuf.CommunityChat {
o.mutex.Lock()
defer o.mutex.Unlock()
response := make(map[string]*protobuf.CommunityChat) response := make(map[string]*protobuf.CommunityChat)
for k, v := range o.config.CommunityDescription.Chats {
response[k] = v if o != nil {
o.mutex.Lock()
defer o.mutex.Unlock()
} else {
return response
} }
if o != nil && o.config != nil && o.config.CommunityDescription != nil {
for k, v := range o.config.CommunityDescription.Chats {
response[k] = v
}
}
return response
}
func (o *Community) Images() map[string]*protobuf.IdentityImage {
response := make(map[string]*protobuf.IdentityImage)
if o != nil {
o.mutex.Lock()
defer o.mutex.Unlock()
} else {
return response
}
if o != nil && o.config != nil && o.config.CommunityDescription != nil && o.config.CommunityDescription.Identity != nil {
for k, v := range o.config.CommunityDescription.Identity.Images {
response[k] = v
}
}
return response return response
} }
func (o *Community) Categories() map[string]*protobuf.CommunityCategory { func (o *Community) Categories() map[string]*protobuf.CommunityCategory {
o.mutex.Lock()
defer o.mutex.Unlock()
response := make(map[string]*protobuf.CommunityCategory) response := make(map[string]*protobuf.CommunityCategory)
for k, v := range o.config.CommunityDescription.Categories {
response[k] = v if o != nil {
o.mutex.Lock()
defer o.mutex.Unlock()
} else {
return response
} }
if o != nil && o.config != nil && o.config.CommunityDescription != nil {
for k, v := range o.config.CommunityDescription.Categories {
response[k] = v
}
}
return response return response
} }

View File

@ -150,7 +150,7 @@ func (api *API) GetChats(ctx context.Context) (map[string]ChannelGroup, error) {
chGrp := ChannelGroup{ chGrp := ChannelGroup{
Type: Community, Type: Community,
Name: community.Name(), Name: community.Name(),
Color: community.Description().Identity.Color, Color: community.Color(),
Images: make(map[string]images.IdentityImage), Images: make(map[string]images.IdentityImage),
Chats: make(map[string]*Chat), Chats: make(map[string]*Chat),
Categories: make(map[string]communities.CommunityCategory), Categories: make(map[string]communities.CommunityCategory),
@ -165,11 +165,11 @@ func (api *API) GetChats(ctx context.Context) (map[string]ChannelGroup, error) {
Muted: community.Muted(), Muted: community.Muted(),
} }
for t, i := range community.Description().Identity.Images { for t, i := range community.Images() {
chGrp.Images[t] = images.IdentityImage{Name: t, Payload: i.Payload} chGrp.Images[t] = images.IdentityImage{Name: t, Payload: i.Payload}
} }
for _, cat := range community.Description().Categories { for _, cat := range community.Categories() {
chGrp.Categories[cat.CategoryId] = communities.CommunityCategory{ chGrp.Categories[cat.CategoryId] = communities.CommunityCategory{
ID: cat.CategoryId, ID: cat.CategoryId,
Name: cat.Name, Name: cat.Name,