FEATURE: add composer warning when user haven't been seen in a long time (#18340)

* FEATURE: add composer warning when user haven't been seen in a long time

When a user creates a PM and adds a recipient that hasn't been seen in a
long time then we'll now show a warning in composer indicating that the
user hasn't been seen in a long time.
This commit is contained in:
Arpit Jalan
2022-09-27 22:06:40 +05:30
committed by GitHub
parent 0f5db0838d
commit 2ee721f8aa
10 changed files with 183 additions and 0 deletions

View File

@ -30,4 +30,45 @@ RSpec.describe ComposerMessagesController do
end
end
end
describe '#user_not_seen_in_a_while' do
fab!(:user_1) { Fabricate(:user, last_seen_at: 3.years.ago) }
fab!(:user_2) { Fabricate(:user, last_seen_at: 2.years.ago) }
fab!(:user_3) { Fabricate(:user, last_seen_at: 6.months.ago) }
it 'requires you to be logged in' do
get '/composer_messages/user_not_seen_in_a_while.json', params: { usernames: [user_1.username, user_2.username, user_3.username] }
expect(response.status).to eq(403)
end
context 'when logged in' do
let!(:user) { sign_in(Fabricate(:user)) }
before do
SiteSetting.pm_warn_user_last_seen_months_ago = 24
end
it 'requires usernames parameter to be present' do
get '/composer_messages/user_not_seen_in_a_while.json'
expect(response.status).to eq(400)
end
it 'returns users that have not been seen recently' do
get '/composer_messages/user_not_seen_in_a_while.json', params: { usernames: [user_1.username, user_2.username, user_3.username] }
expect(response.status).to eq(200)
json = response.parsed_body
expect(json["user_count"]).to eq(2)
expect(json["usernames"]).to contain_exactly(user_1.username, user_2.username)
end
it 'accounts for pm_warn_user_last_seen_months_ago site setting' do
SiteSetting.pm_warn_user_last_seen_months_ago = 30
get '/composer_messages/user_not_seen_in_a_while.json', params: { usernames: [user_1.username, user_2.username, user_3.username] }
expect(response.status).to eq(200)
json = response.parsed_body
expect(json["user_count"]).to eq(1)
expect(json["usernames"]).to contain_exactly(user_1.username)
end
end
end
end