Skip to content

Commit

Permalink
take into account RegularParticipantCanWriteMessage in SetPersonalize…
Browse files Browse the repository at this point in the history
…dFields()
  • Loading branch information
nkonev committed Jan 23, 2025
1 parent 3b9c831 commit e9598d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
46 changes: 24 additions & 22 deletions chat/dto/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type EmbedMessageRequest struct {
}

type Reaction struct {
Count int64 `json:"count"`
Count int64 `json:"count"`
Users []*User `json:"users"`
Reaction string `json:"reaction"`
Reaction string `json:"reaction"`
}

type DisplayMessageDto struct {
Expand All @@ -40,36 +40,36 @@ type DisplayMessageDto struct {
Owner *User `json:"owner"`
CanEdit bool `json:"canEdit"`
CanDelete bool `json:"canDelete"`
FileItemUuid *string `json:"fileItemUuid"`
FileItemUuid *string `json:"fileItemUuid"`
EmbedMessage *EmbedMessageResponse `json:"embedMessage"`
Pinned bool `json:"pinned"`
BlogPost bool `json:"blogPost"`
PinnedPromoted *bool `json:"pinnedPromoted"`
Reactions []Reaction `json:"reactions"`
Reactions []Reaction `json:"reactions"`
Published bool `json:"published"`
CanPublish bool `json:"canPublish"`
CanPin bool `json:"canPin"`
}

type PublishedMessageDto struct {
Id int64 `json:"id"`
Text string `json:"text"`
ChatId int64 `json:"chatId"`
OwnerId int64 `json:"ownerId"`
Owner *User `json:"owner"`
CanPublish bool `json:"canPublish"`
CreateDateTime time.Time `json:"createDateTime"`
Id int64 `json:"id"`
Text string `json:"text"`
ChatId int64 `json:"chatId"`
OwnerId int64 `json:"ownerId"`
Owner *User `json:"owner"`
CanPublish bool `json:"canPublish"`
CreateDateTime time.Time `json:"createDateTime"`
}

type PinnedMessageDto struct {
Id int64 `json:"id"`
Text string `json:"text"`
ChatId int64 `json:"chatId"`
OwnerId int64 `json:"ownerId"`
Owner *User `json:"owner"`
PinnedPromoted bool `json:"pinnedPromoted"`
CreateDateTime time.Time `json:"createDateTime"`
CanPin bool `json:"canPin"`
Id int64 `json:"id"`
Text string `json:"text"`
ChatId int64 `json:"chatId"`
OwnerId int64 `json:"ownerId"`
Owner *User `json:"owner"`
PinnedPromoted bool `json:"pinnedPromoted"`
CreateDateTime time.Time `json:"createDateTime"`
CanPin bool `json:"canPin"`
}

func CanPublishMessage(chatRegularParticipantCanPublishMessage, chatIsAdmin bool, messageOwnerId, behalfUserId int64) bool {
Expand All @@ -80,9 +80,11 @@ func CanPinMessage(chatRegularParticipantCanPinMessage, chatIsAdmin bool) bool {
return chatIsAdmin || chatRegularParticipantCanPinMessage
}

func (copied *DisplayMessageDto) SetPersonalizedFields(chatRegularParticipantCanPublishMessage, chatRegularParticipantCanPinMessage, chatIsAdmin bool, participantId int64) {
copied.CanEdit = ((copied.OwnerId == participantId) && (copied.EmbedMessage == nil || copied.EmbedMessage.EmbedType != EmbedMessageTypeResend))
copied.CanDelete = copied.OwnerId == participantId
func (copied *DisplayMessageDto) SetPersonalizedFields(chatRegularParticipantCanPublishMessage, chatRegularParticipantCanPinMessage, chatCanWriteMessage, chatIsAdmin bool, participantId int64) {
canWriteMessage := chatIsAdmin || chatCanWriteMessage

copied.CanEdit = ((copied.OwnerId == participantId) && (copied.EmbedMessage == nil || copied.EmbedMessage.EmbedType != EmbedMessageTypeResend)) && canWriteMessage
copied.CanDelete = copied.OwnerId == participantId && canWriteMessage
copied.CanPublish = CanPublishMessage(chatRegularParticipantCanPublishMessage, chatIsAdmin, copied.OwnerId, participantId)
copied.CanPin = CanPinMessage(chatRegularParticipantCanPinMessage, chatIsAdmin)
}
Expand Down
2 changes: 1 addition & 1 deletion chat/handlers/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func convertToMessageDto(ctx context.Context, lgr *logger.Logger, dbMessage *db.
if !ok {
lgr.WithTracing(ctx).Errorf("Unable to get message's chat for message id = %v, chat id = %v", dbMessage.Id, dbMessage.ChatId)
}
ret.SetPersonalizedFields(messageChat.RegularParticipantCanPublishMessage, messageChat.RegularParticipantCanPinMessage, behalfUserIsAdminInChat, behalfUserId)
ret.SetPersonalizedFields(messageChat.RegularParticipantCanPublishMessage, messageChat.RegularParticipantCanPinMessage, messageChat.RegularParticipantCanWriteMessage, behalfUserIsAdminInChat, behalfUserId)

return ret
}
Expand Down
2 changes: 1 addition & 1 deletion chat/services/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (not *Events) messageNotifyCommon(ctx context.Context, userIds []int64, cha
continue
}

copied.SetPersonalizedFields(chatBasic.RegularParticipantCanPublishMessage, chatBasic.RegularParticipantCanPinMessage, chatAdmins[participantId], participantId)
copied.SetPersonalizedFields(chatBasic.RegularParticipantCanPublishMessage, chatBasic.RegularParticipantCanPinMessage, chatBasic.RegularParticipantCanWriteMessage, chatAdmins[participantId], participantId)

err := not.rabbitEventPublisher.Publish(ctx, dto.ChatEvent{
EventType: eventType,
Expand Down

0 comments on commit e9598d2

Please sign in to comment.