Skip to content

Commit

Permalink
fix: pass message data only in send group message request
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Normore committed Jan 12, 2024
1 parent 9c76ef4 commit e979017
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/uptrace/bun/driver/pgdriver v1.1.16
github.com/waku-org/go-waku v0.8.0
github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3
github.com/xmtp/proto/v3 v3.36.3-0.20240112003601-b127b3d5b7b9
github.com/xmtp/proto/v3 v3.36.3-0.20240112004139-20d010b31f31
github.com/yoheimuta/protolint v0.39.0
go.uber.org/zap v1.24.0
golang.org/x/sync v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,8 @@ github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0
github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3 h1:wzUffJGCTBGXIDyNU+1UBu1fn2Nzo+OQzM1pLrheh58=
github.com/xmtp/go-msgio v0.2.1-0.20220510223757-25a701b79cd3/go.mod h1:bJREWk+NDnZYjgLQdAi8SUWuq/5pkMme4GqiffEhUF4=
github.com/xmtp/proto/v3 v3.36.3-0.20240112003601-b127b3d5b7b9 h1:iWIW7/LCIej+Aof/RglSUKU/+bIv1vFpD4vyOwQz4PY=
github.com/xmtp/proto/v3 v3.36.3-0.20240112003601-b127b3d5b7b9/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xmtp/proto/v3 v3.36.3-0.20240112004139-20d010b31f31 h1:qp3MYtKaDfZmrL3l2YOdfleOARDaoI9zOVvtz5yPpTk=
github.com/xmtp/proto/v3 v3.36.3-0.20240112004139-20d010b31f31/go.mod h1:NF2zAjtNpVIhS4tFG19g4L1tJcPZHm81oeDFXltmOiY=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/yoheimuta/go-protoparser/v4 v4.6.0 h1:uvz1e9/5Ihsm4Ku8AJeDImTpirKmIxubZdSn0QJNdnw=
github.com/yoheimuta/go-protoparser/v4 v4.6.0/go.mod h1:AHNNnSWnb0UoL4QgHPiOAg2BniQceFscPI5X/BZNHl8=
Expand Down
13 changes: 2 additions & 11 deletions pkg/mls/api/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,14 @@ func (s *Service) SendGroupMessages(ctx context.Context, req *proto.SendGroupMes
return nil, err
}

messages := make([][]byte, len(req.Messages))
for i, message := range req.Messages {
v1 := message.GetV1()
if v1 == nil {
return nil, status.Errorf(codes.InvalidArgument, "message must be v1")
}
messages[i] = v1.Data
}

validationResults, err := s.validationService.ValidateGroupMessages(ctx, messages)
validationResults, err := s.validationService.ValidateGroupMessages(ctx, req.Messages)
if err != nil {
// TODO: Separate validation errors from internal errors
return nil, status.Errorf(codes.InvalidArgument, "invalid group message: %s", err)
}

for i, result := range validationResults {
data := messages[i]
data := req.Messages[i]

if err = requireReadyToSend(result.GroupId, data); err != nil {
return nil, err
Expand Down
13 changes: 3 additions & 10 deletions pkg/mls/api/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,9 @@ func TestSendGroupMessages(t *testing.T) {
mlsValidationService.mockValidateGroupMessages(groupId)

_, err := svc.SendGroupMessages(ctx, &mlsv1.SendGroupMessagesRequest{
Messages: []*message_contents.GroupMessage{{
Version: &message_contents.GroupMessage_V1_{
V1: &message_contents.GroupMessage_V1{
Id: 1,
CreatedNs: 1,
GroupId: groupId,
Data: []byte("test"),
},
},
}},
Messages: [][]byte{
[]byte("test"),
},
})
require.NoError(t, err)

Expand Down

0 comments on commit e979017

Please sign in to comment.