github.com/status-im/status-go@v1.1.0/protocol/messenger_community_for_mobile_testing.go (about)

     1  package protocol
     2  
     3  import (
     4  	"github.com/status-im/status-go/eth-node/types"
     5  	"github.com/status-im/status-go/params"
     6  	"github.com/status-im/status-go/protocol/protobuf"
     7  	"github.com/status-im/status-go/protocol/requests"
     8  )
     9  
    10  func (m *Messenger) createCommunityChat(communityID types.HexBytes, name string) (*MessengerResponse, error) {
    11  	return m.CreateCommunityChat(communityID, &protobuf.CommunityChat{
    12  		Permissions: &protobuf.CommunityPermissions{
    13  			Access: protobuf.CommunityPermissions_AUTO_ACCEPT,
    14  		},
    15  		Identity: &protobuf.ChatIdentity{
    16  			DisplayName: name,
    17  			Description: name,
    18  		},
    19  	})
    20  }
    21  
    22  func (m *Messenger) CreateClosedCommunity() (*MessengerResponse, error) {
    23  	response, err := m.CreateCommunity(&requests.CreateCommunity{
    24  		Name:                         "closed community",
    25  		Description:                  "closed community to check membership requests",
    26  		Color:                        "#887af9",
    27  		HistoryArchiveSupportEnabled: true,
    28  		Membership:                   protobuf.CommunityPermissions_MANUAL_ACCEPT,
    29  		PinMessageAllMembersEnabled:  true,
    30  	}, true)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	community := response.Communities()[0]
    35  	cid := community.ID()
    36  
    37  	var (
    38  		catsChannelID  string
    39  		dogsChannelID  string
    40  		rulesChannelID string
    41  	)
    42  	response2, err := m.createCommunityChat(cid, "cats")
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  	catsChannelID = response2.Chats()[0].CommunityChatID()
    47  	if err = response.Merge(response2); err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	response2, err = m.createCommunityChat(cid, "dogs")
    52  	if err != nil {
    53  		return nil, err
    54  	}
    55  	dogsChannelID = response2.Chats()[0].CommunityChatID()
    56  	if err = response.Merge(response2); err != nil {
    57  		return nil, err
    58  	}
    59  	response2, err = m.createCommunityChat(cid, "rules")
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  	rulesChannelID = response2.Chats()[0].CommunityChatID()
    64  	if err = response.Merge(response2); err != nil {
    65  		return nil, err
    66  	}
    67  
    68  	response2, err = m.CreateCommunityCategory(&requests.CreateCommunityCategory{
    69  		CommunityID:  cid,
    70  		CategoryName: "pets",
    71  		ChatIDs:      []string{catsChannelID, dogsChannelID},
    72  	})
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  	if err = response.Merge(response2); err != nil {
    77  		return nil, err
    78  	}
    79  	response2, err = m.CreateCommunityCategory(&requests.CreateCommunityCategory{
    80  		CommunityID:  cid,
    81  		CategoryName: "household",
    82  		ChatIDs:      []string{rulesChannelID},
    83  	})
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  	if err = response.Merge(response2); err != nil {
    88  		return nil, err
    89  	}
    90  	return response, nil
    91  }
    92  
    93  func (m *Messenger) CreateOpenCommunity() (*MessengerResponse, error) {
    94  	response, err := m.CreateCommunity(&requests.CreateCommunity{
    95  		Name:                         "open community",
    96  		Description:                  "open community to join with no requests",
    97  		Color:                        "#26a69a",
    98  		HistoryArchiveSupportEnabled: true,
    99  		Membership:                   protobuf.CommunityPermissions_AUTO_ACCEPT,
   100  		PinMessageAllMembersEnabled:  false,
   101  	}, true)
   102  	return response, err
   103  }
   104  
   105  func (m *Messenger) CreateTokenGatedCommunity() (*MessengerResponse, error) {
   106  	response, err := m.CreateCommunity(&requests.CreateCommunity{
   107  		Name:                         "SNT community",
   108  		Description:                  "require 10 SNT Goerli to use",
   109  		Color:                        "#eab700",
   110  		HistoryArchiveSupportEnabled: true,
   111  		Membership:                   protobuf.CommunityPermissions_MANUAL_ACCEPT,
   112  		PinMessageAllMembersEnabled:  false,
   113  	}, true)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  	community := response.Communities()[0]
   118  	cid := community.ID()
   119  	generalChatID := response.Chats()[0].CommunityChatID()
   120  
   121  	return m.CreateCommunityTokenPermission(&requests.CreateCommunityTokenPermission{
   122  		CommunityID: cid,
   123  		Type:        protobuf.CommunityTokenPermission_BECOME_MEMBER,
   124  		TokenCriteria: []*protobuf.TokenCriteria{{
   125  			ContractAddresses: map[uint64]string{params.GoerliNetworkID: "0x3D6AFAA395C31FCd391fE3D562E75fe9E8ec7E6a"},
   126  			Type:              protobuf.CommunityTokenType_ERC20,
   127  			Symbol:            "STT",
   128  			Name:              "Status Test Token",
   129  			AmountInWei:       "10000000000000000000",
   130  			Decimals:          18,
   131  		}},
   132  		ChatIds: []string{generalChatID},
   133  	})
   134  }