Skip to content

Commit

Permalink
refactor: public
Browse files Browse the repository at this point in the history
  • Loading branch information
tahadostifam committed Dec 1, 2024
1 parent cf16959 commit 7ad643c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/service/chat/chat_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ var (
ErrJoinDirectChat = errors.New("joining direct chat is not possible")
ErrRecipientNotFound = errors.New("recipient not found")
ErrMessageStoreCreation = errors.New("failed to create message store for chat")
ErrPublishEvent = errors.New("failed to publish event to streamer")
)
5 changes: 4 additions & 1 deletion internal/service/chat/chat_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,16 @@ func (s *ChatService) CreateDirect(ctx context.Context, userID model.UserID, rec
return nil, &vali.Varror{Error: service.ErrProtoMarshaling}
}

s.eventPublisher.Publish(&eventsv1.StreamEvent{
err = s.eventPublisher.Publish(&eventsv1.StreamEvent{
SenderUserId: userID,
ReceiversUserId: []model.UserID{
finalRecipientUserID,
},
Payload: payloadProtoBuf,
})
if err != nil {
return nil, &vali.Varror{Error: ErrPublishEvent}
}

return chatDTO, nil
}
Expand Down
4 changes: 1 addition & 3 deletions internal/service/common_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ package service

import "errors"

var (
ErrProtoMarshaling = errors.New("proto marshaling failed")
)
var ErrProtoMarshaling = errors.New("proto marshaling failed")
6 changes: 3 additions & 3 deletions utils/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
const UserIDLength = 8

var (
min = int64(math.Pow(10, float64(UserIDLength)-1))
max = int64(math.Pow(10, float64(UserIDLength))) - 1
minInt = int64(math.Pow(10, float64(UserIDLength)-1))
maxInt = int64(math.Pow(10, float64(UserIDLength))) - 1
)

func GenerateUserID() int {
Expand All @@ -22,7 +22,7 @@ func GenerateUserID() int {
panic(err)
}

randomNumber = int64(binary.BigEndian.Uint64(buf))%(max-min+1) + min
randomNumber = int64(binary.BigEndian.Uint64(buf))%(maxInt-minInt+1) + minInt

return int(randomNumber)
}

0 comments on commit 7ad643c

Please sign in to comment.