add api to create community for testing (#3818)
This commit is contained in:
parent
9ae632893c
commit
60143556ff
|
@ -0,0 +1,134 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/requests"
|
||||
)
|
||||
|
||||
func (m *Messenger) createCommunityChat(communityID types.HexBytes, name string) (*MessengerResponse, error) {
|
||||
return m.CreateCommunityChat(communityID, &protobuf.CommunityChat{
|
||||
Permissions: &protobuf.CommunityPermissions{
|
||||
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
},
|
||||
Identity: &protobuf.ChatIdentity{
|
||||
DisplayName: name,
|
||||
Description: name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Messenger) CreateClosedCommunity() (*MessengerResponse, error) {
|
||||
response, err := m.CreateCommunity(&requests.CreateCommunity{
|
||||
Name: "closed community",
|
||||
Description: "closed community to check membership requests",
|
||||
Color: "#887af9",
|
||||
HistoryArchiveSupportEnabled: true,
|
||||
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
||||
PinMessageAllMembersEnabled: true,
|
||||
}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
community := response.Communities()[0]
|
||||
cid := community.ID()
|
||||
|
||||
var (
|
||||
catsChannelID string
|
||||
dogsChannelID string
|
||||
rulesChannelID string
|
||||
)
|
||||
response2, err := m.createCommunityChat(cid, "cats")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
catsChannelID = response2.Chats()[0].CommunityChatID()
|
||||
if err = response.Merge(response2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response2, err = m.createCommunityChat(cid, "dogs")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dogsChannelID = response2.Chats()[0].CommunityChatID()
|
||||
if err = response.Merge(response2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response2, err = m.createCommunityChat(cid, "rules")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rulesChannelID = response2.Chats()[0].CommunityChatID()
|
||||
if err = response.Merge(response2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response2, err = m.CreateCommunityCategory(&requests.CreateCommunityCategory{
|
||||
CommunityID: cid,
|
||||
CategoryName: "pets",
|
||||
ChatIDs: []string{catsChannelID, dogsChannelID},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = response.Merge(response2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response2, err = m.CreateCommunityCategory(&requests.CreateCommunityCategory{
|
||||
CommunityID: cid,
|
||||
CategoryName: "household",
|
||||
ChatIDs: []string{rulesChannelID},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = response.Merge(response2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) CreateOpenCommunity() (*MessengerResponse, error) {
|
||||
response, err := m.CreateCommunity(&requests.CreateCommunity{
|
||||
Name: "open community",
|
||||
Description: "open community to join with no requests",
|
||||
Color: "#26a69a",
|
||||
HistoryArchiveSupportEnabled: true,
|
||||
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
PinMessageAllMembersEnabled: false,
|
||||
}, true)
|
||||
return response, err
|
||||
}
|
||||
|
||||
func (m *Messenger) CreateTokenGatedCommunity() (*MessengerResponse, error) {
|
||||
response, err := m.CreateCommunity(&requests.CreateCommunity{
|
||||
Name: "SNT community",
|
||||
Description: "require 10 SNT Goerli to use",
|
||||
Color: "#eab700",
|
||||
HistoryArchiveSupportEnabled: true,
|
||||
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
||||
PinMessageAllMembersEnabled: false,
|
||||
}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
community := response.Communities()[0]
|
||||
cid := community.ID()
|
||||
generalChatID := response.Chats()[0].CommunityChatID()
|
||||
|
||||
return m.CreateCommunityTokenPermission(&requests.CreateCommunityTokenPermission{
|
||||
CommunityID: cid,
|
||||
Type: protobuf.CommunityTokenPermission_BECOME_MEMBER,
|
||||
TokenCriteria: []*protobuf.TokenCriteria{{
|
||||
ContractAddresses: map[uint64]string{params.GoerliNetworkID: "0x3D6AFAA395C31FCd391fE3D562E75fe9E8ec7E6a"},
|
||||
Type: protobuf.CommunityTokenType_ERC20,
|
||||
Symbol: "STT",
|
||||
Name: "Status Test Token",
|
||||
Amount: "10",
|
||||
Decimals: 18,
|
||||
}},
|
||||
ChatIds: []string{generalChatID},
|
||||
})
|
||||
}
|
|
@ -1453,6 +1453,21 @@ func (api *PublicAPI) GetCheckChannelPermissionResponses(parent context.Context,
|
|||
return api.service.messenger.GetCommunityCheckChannelPermissionResponses(communityID)
|
||||
}
|
||||
|
||||
// CreateClosedCommunity used only for test purposes
|
||||
func (api *PublicAPI) CreateClosedCommunity() (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.CreateClosedCommunity()
|
||||
}
|
||||
|
||||
// CreateOpenCommunity used only for test purposes
|
||||
func (api *PublicAPI) CreateOpenCommunity() (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.CreateOpenCommunity()
|
||||
}
|
||||
|
||||
// CreateTokenGatedCommunity used only for test purposes
|
||||
func (api *PublicAPI) CreateTokenGatedCommunity() (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.CreateTokenGatedCommunity()
|
||||
}
|
||||
|
||||
// -----
|
||||
// HELPER
|
||||
// -----
|
||||
|
|
Loading…
Reference in New Issue