diff --git a/VERSION b/VERSION index 829fca46d..bf6d05f74 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.162.13 +0.162.14 diff --git a/protocol/messenger_community_for_mobile_testing.go b/protocol/messenger_community_for_mobile_testing.go new file mode 100644 index 000000000..7a85ef306 --- /dev/null +++ b/protocol/messenger_community_for_mobile_testing.go @@ -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}, + }) +} diff --git a/services/ext/api.go b/services/ext/api.go index aaa3ad0e0..9f4c01ac1 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -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 // -----