fix: harden channel rights and sticker compatibility
Co-authored-by: HSgram <3013954224@qq.com>
This commit is contained in:
parent
6867d201ed
commit
599453a3c4
33 changed files with 1520 additions and 130 deletions
|
|
@ -423,7 +423,7 @@ func channelReplyBelongsToRoot(msg domain.ChannelMessage, channelID int64, rootI
|
|||
return msg.ReplyTo.TopMessageID == rootID || (msg.ReplyTo.TopMessageID == 0 && msg.ReplyTo.MessageID == rootID)
|
||||
}
|
||||
|
||||
func (s *ChannelStore) resolveChannelReplyLocked(req domain.SendChannelMessageRequest, member domain.ChannelMember, channel domain.Channel) (*domain.MessageReply, error) {
|
||||
func (s *ChannelStore) resolveChannelReplyLocked(req domain.SendChannelMessageRequest, member domain.ChannelMember, channel domain.Channel, selfBoostsApplied int) (*domain.MessageReply, error) {
|
||||
if req.ReplyTo == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -446,7 +446,7 @@ func (s *ChannelStore) resolveChannelReplyLocked(req domain.SendChannelMessageRe
|
|||
if !ok || topic.Hidden {
|
||||
return nil, domain.ErrReplyMessageIDInvalid
|
||||
}
|
||||
if topic.Closed && !canManageForumTopic(channel, member, topic, req.UserID) {
|
||||
if topic.Closed && !canManageForumTopic(channel, member, topic, req.UserID, selfBoostsApplied) {
|
||||
return nil, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
reply := cloneMessageReply(req.ReplyTo)
|
||||
|
|
@ -472,7 +472,7 @@ func (s *ChannelStore) resolveChannelReplyLocked(req domain.SendChannelMessageRe
|
|||
}
|
||||
if channel.Forum && reply.TopMessageID > 0 {
|
||||
if topic, ok := s.topics[req.ChannelID][reply.TopMessageID]; ok && !topic.Hidden {
|
||||
if topic.Closed && !canManageForumTopic(channel, member, topic, req.UserID) {
|
||||
if topic.Closed && !canManageForumTopic(channel, member, topic, req.UserID, selfBoostsApplied) {
|
||||
return nil, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
reply.ForumTopic = true
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ func (s *ChannelStore) SendChannelMessage(_ context.Context, req domain.SendChan
|
|||
if channel.Megagroup {
|
||||
fromBoostsApplied = s.selfBoostsAppliedLocked(req.UserID, req.ChannelID, req.Date)
|
||||
}
|
||||
if domain.ChannelBannedRightsBlockMessage(req, channel, member, fromBoostsApplied) {
|
||||
return domain.SendChannelMessageResult{}, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
if !canSendChannelMessageWithBoost(channel, member, fromBoostsApplied) {
|
||||
return domain.SendChannelMessageResult{}, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
|
|
@ -51,7 +54,7 @@ func (s *ChannelStore) SendChannelMessage(_ context.Context, req domain.SendChan
|
|||
if wait := channelSlowModeWait(channel, member, req.Date); wait > 0 {
|
||||
return domain.SendChannelMessageResult{}, domain.NewSlowModeWaitError(wait)
|
||||
}
|
||||
replyTo, err := s.resolveChannelReplyLocked(req, member, channel)
|
||||
replyTo, err := s.resolveChannelReplyLocked(req, member, channel, fromBoostsApplied)
|
||||
if err != nil {
|
||||
return domain.SendChannelMessageResult{}, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,15 @@ func (s *ChannelStore) SetChannelMessageReactions(_ context.Context, req domain.
|
|||
if err != nil {
|
||||
return domain.ChannelMessageReactionsResult{}, err
|
||||
}
|
||||
if len(req.Reactions) > 0 {
|
||||
selfBoostsApplied := 0
|
||||
if channel.Megagroup {
|
||||
selfBoostsApplied = s.selfBoostsAppliedLocked(req.UserID, req.ChannelID, req.Date)
|
||||
}
|
||||
if domain.ChannelBannedRightsBlockReactions(channel, member, selfBoostsApplied) {
|
||||
return domain.ChannelMessageReactionsResult{}, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
}
|
||||
idx, ok := s.findMessageIndexLocked(req.ChannelID, req.MessageID)
|
||||
if !ok {
|
||||
return domain.ChannelMessageReactionsResult{}, domain.ErrMessageIDInvalid
|
||||
|
|
|
|||
|
|
@ -92,6 +92,18 @@ func (s *ChannelStore) CreateForumTopic(ctx context.Context, req domain.CreateCh
|
|||
s.mu.Unlock()
|
||||
return domain.CreateChannelForumTopicResult{}, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
selfBoostsApplied := 0
|
||||
if channel.Megagroup {
|
||||
now := req.Date
|
||||
if now == 0 {
|
||||
now = int(time.Now().Unix())
|
||||
}
|
||||
selfBoostsApplied = s.selfBoostsAppliedLocked(req.UserID, req.ChannelID, now)
|
||||
}
|
||||
if domain.ChannelBannedRightsBlockManageTopics(channel, member, selfBoostsApplied) {
|
||||
s.mu.Unlock()
|
||||
return domain.CreateChannelForumTopicResult{}, domain.ErrChannelWriteForbidden
|
||||
}
|
||||
if id, ok := s.randomToID[channelRandomKey{channelID: req.ChannelID, userID: req.UserID, randomID: req.RandomID}]; ok {
|
||||
if topic, ok := s.topics[req.ChannelID][id]; ok {
|
||||
msg, _ := s.findMessageLocked(req.ChannelID, id)
|
||||
|
|
@ -184,7 +196,15 @@ func (s *ChannelStore) EditForumTopic(ctx context.Context, req domain.EditChanne
|
|||
s.mu.Unlock()
|
||||
return domain.EditChannelForumTopicResult{}, domain.ErrMessageIDInvalid
|
||||
}
|
||||
if !canManageForumTopic(channel, member, topic, req.UserID) {
|
||||
selfBoostsApplied := 0
|
||||
if channel.Megagroup {
|
||||
now := req.Date
|
||||
if now == 0 {
|
||||
now = int(time.Now().Unix())
|
||||
}
|
||||
selfBoostsApplied = s.selfBoostsAppliedLocked(req.UserID, req.ChannelID, now)
|
||||
}
|
||||
if !canManageForumTopic(channel, member, topic, req.UserID, selfBoostsApplied) {
|
||||
s.mu.Unlock()
|
||||
return domain.EditChannelForumTopicResult{}, domain.ErrChannelAdminRequired
|
||||
}
|
||||
|
|
@ -361,7 +381,7 @@ func (s *ChannelStore) DeleteForumTopicHistory(_ context.Context, req domain.Del
|
|||
if !ok {
|
||||
return domain.DeleteChannelHistoryResult{}, domain.ErrMessageIDInvalid
|
||||
}
|
||||
if !canManageForumTopic(channel, member, topic, req.UserID) && !canDeleteAnyChannelMessage(member) {
|
||||
if !canManageForumTopic(channel, member, topic, req.UserID, 0) && !canDeleteAnyChannelMessage(member) {
|
||||
return domain.DeleteChannelHistoryResult{}, domain.ErrChannelAdminRequired
|
||||
}
|
||||
ids := make([]int, 0, domain.MaxDeleteHistoryBatch)
|
||||
|
|
@ -613,7 +633,10 @@ func (s *ChannelStore) channelMessageRepliesLocked(viewerUserID, channelID int64
|
|||
return &stats
|
||||
}
|
||||
|
||||
func canManageForumTopic(channel domain.Channel, member domain.ChannelMember, topic domain.ChannelForumTopic, userID int64) bool {
|
||||
func canManageForumTopic(channel domain.Channel, member domain.ChannelMember, topic domain.ChannelForumTopic, userID int64, selfBoostsApplied int) bool {
|
||||
if domain.ChannelBannedRightsBlockManageTopics(channel, member, selfBoostsApplied) {
|
||||
return false
|
||||
}
|
||||
if topic.CreatorUserID == userID {
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue