feat: add optional inviteMessage to share-community request (#2776)

This commit is contained in:
Mikhail Rogachev 2022-08-08 13:49:39 +03:00 committed by GitHub
parent 31671ea040
commit cd91b19737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -1188,6 +1188,8 @@ func (s *MessengerCommunitiesSuite) TestShareCommunity() {
Description: "status community description",
}
inviteMessage := "invite to community testing message"
// Create an community chat
response, err := s.bob.CreateCommunity(description, true)
s.Require().NoError(err)
@ -1198,8 +1200,9 @@ func (s *MessengerCommunitiesSuite) TestShareCommunity() {
response, err = s.bob.ShareCommunity(
&requests.ShareCommunity{
CommunityID: community.ID(),
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
CommunityID: community.ID(),
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
InviteMessage: inviteMessage,
},
)
s.Require().NoError(err)
@ -1226,6 +1229,10 @@ func (s *MessengerCommunitiesSuite) TestShareCommunity() {
s.Require().NoError(err)
s.Require().Len(response.Messages(), 1)
message := response.Messages()[0]
s.Require().Equal(community.IDString(), message.CommunityID)
s.Require().Equal(inviteMessage, message.Text)
}
func (s *MessengerCommunitiesSuite) TestBanUser() {

View File

@ -987,6 +987,9 @@ func (m *Messenger) ShareCommunity(request *requests.ShareCommunity) (*Messenger
message.ChatId = pk.String()
message.CommunityID = request.CommunityID.String()
message.Text = fmt.Sprintf("Community %s has been shared with you", community.Name())
if request.InviteMessage != "" {
message.Text = request.InviteMessage
}
messages = append(messages, message)
r, err := m.CreateOneToOneChat(&requests.CreateOneToOneChat{ID: pk})
if err != nil {

View File

@ -10,8 +10,9 @@ var ErrShareCommunityInvalidID = errors.New("share-community: invalid id")
var ErrShareCommunityEmptyUsers = errors.New("share-community: empty users")
type ShareCommunity struct {
CommunityID types.HexBytes `json:"communityId"`
Users []types.HexBytes `json:"users"`
CommunityID types.HexBytes `json:"communityId"`
Users []types.HexBytes `json:"users"`
InviteMessage string `json:"inviteMessage,omitempty"`
}
func (j *ShareCommunity) Validate() error {