chore: allow GetMembers for the communty by communityID only
This commit is contained in:
parent
e8cd779e35
commit
45c5fd1cdf
|
@ -19,6 +19,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrChatNotFound = errors.New("can't find chat")
|
ErrChatNotFound = errors.New("can't find chat")
|
||||||
|
ErrCommunityNotFound = errors.New("can't find community")
|
||||||
ErrCommunitiesNotSupported = errors.New("communities are not supported")
|
ErrCommunitiesNotSupported = errors.New("communities are not supported")
|
||||||
ErrChatTypeNotSupported = errors.New("chat type not supported")
|
ErrChatTypeNotSupported = errors.New("chat type not supported")
|
||||||
)
|
)
|
||||||
|
@ -226,6 +227,10 @@ func (api *API) GetChat(ctx context.Context, communityID types.HexBytes, chatID
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if messengerChat == nil {
|
||||||
|
return nil, ErrChatNotFound
|
||||||
|
}
|
||||||
|
|
||||||
result, err := api.toAPIChat(messengerChat, community, pubKey)
|
result, err := api.toAPIChat(messengerChat, community, pubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -324,24 +329,26 @@ func (api *API) toAPIChat(protocolChat *protocol.Chat, community *communities.Co
|
||||||
|
|
||||||
func getChatMembers(sourceChat *protocol.Chat, community *communities.Community, userPubKey string) (map[string]Member, error) {
|
func getChatMembers(sourceChat *protocol.Chat, community *communities.Community, userPubKey string) (map[string]Member, error) {
|
||||||
result := make(map[string]Member)
|
result := make(map[string]Member)
|
||||||
if sourceChat.ChatType == protocol.ChatTypePrivateGroupChat && len(sourceChat.Members) > 0 {
|
if sourceChat != nil {
|
||||||
for _, m := range sourceChat.Members {
|
if sourceChat.ChatType == protocol.ChatTypePrivateGroupChat && len(sourceChat.Members) > 0 {
|
||||||
result[m.ID] = Member{
|
for _, m := range sourceChat.Members {
|
||||||
Admin: m.Admin,
|
result[m.ID] = Member{
|
||||||
|
Admin: m.Admin,
|
||||||
|
Joined: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceChat.ChatType == protocol.ChatTypeOneToOne {
|
||||||
|
result[sourceChat.ID] = Member{
|
||||||
Joined: true,
|
Joined: true,
|
||||||
}
|
}
|
||||||
|
result[userPubKey] = Member{
|
||||||
|
Joined: true,
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if sourceChat.ChatType == protocol.ChatTypeOneToOne {
|
|
||||||
result[sourceChat.ID] = Member{
|
|
||||||
Joined: true,
|
|
||||||
}
|
|
||||||
result[userPubKey] = Member{
|
|
||||||
Joined: true,
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if community != nil {
|
if community != nil {
|
||||||
|
@ -363,6 +370,20 @@ func getChatMembers(sourceChat *protocol.Chat, community *communities.Community,
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) getCommunityByID(id string) (*communities.Community, error) {
|
||||||
|
communityID, err := hexutil.Decode(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
community, err := api.s.messenger.GetCommunityByID(communityID)
|
||||||
|
if community == nil && err == nil {
|
||||||
|
return nil, ErrCommunityNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return community, err
|
||||||
|
}
|
||||||
|
|
||||||
func (chat *Chat) populateCommunityFields(community *communities.Community) error {
|
func (chat *Chat) populateCommunityFields(community *communities.Community) error {
|
||||||
if community == nil {
|
if community == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -398,7 +419,14 @@ func (api *API) getChatAndCommunity(pubKey string, communityID types.HexBytes, c
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(communityID) != 0 {
|
if len(communityID) != 0 {
|
||||||
fullChatID = string(communityID.Bytes()) + chatID
|
id := string(communityID.Bytes())
|
||||||
|
|
||||||
|
if chatID == "" {
|
||||||
|
community, err := api.getCommunityByID(id)
|
||||||
|
return nil, community, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fullChatID = id + chatID
|
||||||
}
|
}
|
||||||
|
|
||||||
messengerChat := api.s.messenger.Chat(fullChatID)
|
messengerChat := api.s.messenger.Chat(fullChatID)
|
||||||
|
@ -408,12 +436,9 @@ func (api *API) getChatAndCommunity(pubKey string, communityID types.HexBytes, c
|
||||||
|
|
||||||
var community *communities.Community
|
var community *communities.Community
|
||||||
if messengerChat.CommunityID != "" {
|
if messengerChat.CommunityID != "" {
|
||||||
communityID, err := hexutil.Decode(messengerChat.CommunityID)
|
var err error
|
||||||
if err != nil {
|
community, err = api.getCommunityByID(messengerChat.CommunityID)
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
community, err = api.s.messenger.GetCommunityByID(communityID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue