FIX: if a message is *partially* archived consider it not archived
This commit is contained in:
parent
85bcda120a
commit
f8637ed616
|
@ -1168,19 +1168,31 @@ SQL
|
|||
def message_archived?(user)
|
||||
return false unless user && user.id
|
||||
|
||||
sql = <<SQL
|
||||
SELECT 1 FROM topic_allowed_groups tg
|
||||
JOIN group_archived_messages gm
|
||||
# tricky query but this checks to see if message is archived for ALL groups you belong to
|
||||
# OR if you have it archived as a user explicitly
|
||||
|
||||
sql = <<~SQL
|
||||
SELECT 1
|
||||
WHERE
|
||||
(
|
||||
SELECT count(*) FROM topic_allowed_groups tg
|
||||
JOIN group_archived_messages gm
|
||||
ON gm.topic_id = tg.topic_id AND
|
||||
gm.group_id = tg.group_id
|
||||
WHERE tg.group_id IN (SELECT g.group_id FROM group_users g WHERE g.user_id = :user_id)
|
||||
AND tg.topic_id = :topic_id
|
||||
) =
|
||||
(
|
||||
SELECT case when count(*) = 0 then -1 else count(*) end FROM topic_allowed_groups tg
|
||||
WHERE tg.group_id IN (SELECT g.group_id FROM group_users g WHERE g.user_id = :user_id)
|
||||
AND tg.topic_id = :topic_id
|
||||
)
|
||||
|
||||
UNION ALL
|
||||
UNION ALL
|
||||
|
||||
SELECT 1 FROM topic_allowed_users tu
|
||||
JOIN user_archived_messages um ON um.user_id = tu.user_id AND um.topic_id = tu.topic_id
|
||||
WHERE tu.user_id = :user_id AND tu.topic_id = :topic_id
|
||||
SELECT 1 FROM topic_allowed_users tu
|
||||
JOIN user_archived_messages um ON um.user_id = tu.user_id AND um.topic_id = tu.topic_id
|
||||
WHERE tu.user_id = :user_id AND tu.topic_id = :topic_id
|
||||
SQL
|
||||
|
||||
User.exec_sql(sql, user_id: user.id, topic_id: id).to_a.length > 0
|
||||
|
|
|
@ -1975,12 +1975,21 @@ describe Topic do
|
|||
expect(topic.message_archived?(user)).to eq(false)
|
||||
|
||||
group = Fabricate(:group)
|
||||
group2 = Fabricate(:group)
|
||||
|
||||
group.add(user)
|
||||
|
||||
TopicAllowedGroup.create!(topic_id: topic.id, group_id: group.id)
|
||||
TopicAllowedGroup.create!(topic_id: topic.id, group_id: group2.id)
|
||||
GroupArchivedMessage.create!(topic_id: topic.id, group_id: group.id)
|
||||
|
||||
expect(topic.message_archived?(user)).to eq(true)
|
||||
|
||||
# here is a pickle, we add another group, make the user a
|
||||
# member of that new group... now this message is not properly archived
|
||||
# for the user any more
|
||||
group2.add(user)
|
||||
expect(topic.message_archived?(user)).to eq(false)
|
||||
end
|
||||
|
||||
it 'will trigger :topic_status_updated' do
|
||||
|
|
Loading…
Reference in New Issue