FEATURE: Add in:messages search modifier (#16567)
This adds `in:messages` as a synonym for `in:personal` and sets it up as our default nomenclature (`in:personal` will still work).
This commit is contained in:
parent
8dd3d6cb97
commit
eebce8f80a
|
@ -20,7 +20,7 @@ const REGEXP_TAGS_REPLACE = /(^(tags?:|#(?=[a-z0-9\-]+::tag))|::tag\s?$)/gi;
|
|||
|
||||
const REGEXP_SPECIAL_IN_LIKES_MATCH = /^in:likes$/gi;
|
||||
const REGEXP_SPECIAL_IN_TITLE_MATCH = /^in:title$/gi;
|
||||
const REGEXP_SPECIAL_IN_PERSONAL_MATCH = /^in:personal$/gi;
|
||||
const REGEXP_SPECIAL_IN_MESSAGES_MATCH = /^in:(personal|messages)$/gi;
|
||||
const REGEXP_SPECIAL_IN_SEEN_MATCH = /^in:seen$/gi;
|
||||
|
||||
const REGEXP_CATEGORY_SLUG = /^(\#[a-zA-Z0-9\-:]+)/gi;
|
||||
|
@ -98,7 +98,7 @@ export default Component.extend({
|
|||
in: {
|
||||
title: false,
|
||||
likes: false,
|
||||
personal: false,
|
||||
messages: false,
|
||||
seen: false,
|
||||
},
|
||||
all_tags: false,
|
||||
|
@ -149,8 +149,8 @@ export default Component.extend({
|
|||
);
|
||||
|
||||
this.setSearchedTermSpecialInValue(
|
||||
"searchedTerms.special.in.personal",
|
||||
REGEXP_SPECIAL_IN_PERSONAL_MATCH
|
||||
"searchedTerms.special.in.messages",
|
||||
REGEXP_SPECIAL_IN_MESSAGES_MATCH
|
||||
);
|
||||
|
||||
this.setSearchedTermSpecialInValue(
|
||||
|
@ -460,9 +460,9 @@ export default Component.extend({
|
|||
},
|
||||
|
||||
@action
|
||||
onChangeSearchTermForSpecialInPersonal(checked) {
|
||||
this.set("searchedTerms.special.in.personal", checked);
|
||||
this.updateInRegex(REGEXP_SPECIAL_IN_PERSONAL_MATCH, "personal");
|
||||
onChangeSearchTermForSpecialInMessages(checked) {
|
||||
this.set("searchedTerms.special.in.messages", checked);
|
||||
this.updateInRegex(REGEXP_SPECIAL_IN_MESSAGES_MATCH, "messages");
|
||||
},
|
||||
|
||||
@action
|
||||
|
|
|
@ -211,7 +211,8 @@ export default Controller.extend({
|
|||
return (
|
||||
q &&
|
||||
this.currentUser &&
|
||||
(q.indexOf("in:personal") > -1 ||
|
||||
(q.indexOf("in:messages") > -1 ||
|
||||
q.indexOf("in:personal") > -1 ||
|
||||
q.indexOf(
|
||||
`personal_messages:${this.currentUser.get("username_lower")}`
|
||||
) > -1)
|
||||
|
|
|
@ -83,8 +83,8 @@
|
|||
id="matching-in-messages"
|
||||
type="checkbox"
|
||||
class="in-private"
|
||||
checked=searchedTerms.special.in.personal
|
||||
click=(action "onChangeSearchTermForSpecialInPersonal" value="target.checked")
|
||||
checked=searchedTerms.special.in.messages
|
||||
click=(action "onChangeSearchTermForSpecialInMessages" value="target.checked")
|
||||
}}
|
||||
<label for="matching-in-messages">{{i18n "search.advanced.filters.private"}}</label>
|
||||
</div>
|
||||
|
|
|
@ -392,7 +392,7 @@ createWidget("search-menu-assistant", {
|
|||
addSearchSuggestion("in:likes");
|
||||
addSearchSuggestion("in:bookmarks");
|
||||
addSearchSuggestion("in:mine");
|
||||
addSearchSuggestion("in:personal");
|
||||
addSearchSuggestion("in:messages");
|
||||
addSearchSuggestion("in:seen");
|
||||
addSearchSuggestion("in:tracking");
|
||||
addSearchSuggestion("in:unseen");
|
||||
|
@ -532,7 +532,7 @@ createWidget("search-menu-initial-options", {
|
|||
case "private_messages":
|
||||
content.push(
|
||||
this.attach("search-menu-assistant-item", {
|
||||
slug: `${term} in:personal`,
|
||||
slug: `${term} in:messages`,
|
||||
})
|
||||
);
|
||||
break;
|
||||
|
|
|
@ -218,7 +218,7 @@ export default createWidget("search-menu", {
|
|||
if (searchContext?.type === "topic") {
|
||||
query += encodeURIComponent(` topic:${searchContext.id}`);
|
||||
} else if (searchContext?.type === "private_messages") {
|
||||
query += encodeURIComponent(` in:personal`);
|
||||
query += encodeURIComponent(` in:messages`);
|
||||
}
|
||||
|
||||
if (query) {
|
||||
|
|
|
@ -133,7 +133,7 @@ acceptance("Search - Full Page", function (needs) {
|
|||
test("search for personal messages", async function (assert) {
|
||||
await visit("/search");
|
||||
|
||||
await fillIn(".search-query", "discourse in:personal");
|
||||
await fillIn(".search-query", "discourse in:messages");
|
||||
await click(".search-cta");
|
||||
|
||||
assert.strictEqual(count(".fps-topic"), 1, "has one post");
|
||||
|
@ -246,7 +246,7 @@ acceptance("Search - Full Page", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("update in:personal filter through advanced search ui", async function (assert) {
|
||||
test("update in:messages filter through advanced search ui", async function (assert) {
|
||||
await visit("/search");
|
||||
await fillIn(".search-query", "none");
|
||||
await click(".search-advanced-options .in-private");
|
||||
|
@ -258,8 +258,8 @@ acceptance("Search - Full Page", function (needs) {
|
|||
|
||||
assert.strictEqual(
|
||||
queryAll(".search-query").val(),
|
||||
"none in:personal",
|
||||
'has updated search term to "none in:personal"'
|
||||
"none in:messages",
|
||||
'has updated search term to "none in:messages"'
|
||||
);
|
||||
|
||||
await fillIn(".search-query", "none in:personal-direct");
|
||||
|
|
|
@ -788,9 +788,9 @@ acceptance("Search - assistant", function (needs) {
|
|||
await triggerKeyEvent("#search-term", "keyup", 51);
|
||||
assert.strictEqual(query(firstTarget).innerText, "sam in:title");
|
||||
|
||||
await fillIn("#search-term", "in:pers");
|
||||
await fillIn("#search-term", "in:mess");
|
||||
await triggerKeyEvent("#search-term", "keyup", 51);
|
||||
assert.strictEqual(query(firstTarget).innerText, "in:personal");
|
||||
assert.strictEqual(query(firstTarget).innerText, "in:messages");
|
||||
});
|
||||
|
||||
test("shows users when typing @", async function (assert) {
|
||||
|
|
|
@ -271,7 +271,10 @@ export function applyDefaultHandlers(pretender) {
|
|||
const obj = JSON.parse(JSON.stringify(fixturesByUrl["/search.json"]));
|
||||
obj.topics.firstObject.visited = true;
|
||||
return response(obj);
|
||||
} else if (request.queryParams.q === "discourse in:personal") {
|
||||
} else if (
|
||||
request.queryParams.q === "discourse in:personal" ||
|
||||
request.queryParams.q === "discourse in:messages"
|
||||
) {
|
||||
const obj = JSON.parse(JSON.stringify(fixturesByUrl["/search.json"]));
|
||||
obj.topics.firstObject.archetype = "private_message";
|
||||
return response(obj);
|
||||
|
|
|
@ -748,6 +748,9 @@ class Search
|
|||
elsif word =~ /^in:personal$/i
|
||||
@search_pms = true
|
||||
nil
|
||||
elsif word =~ /^in:messages$/i
|
||||
@search_pms = true
|
||||
nil
|
||||
elsif word =~ /^in:personal-direct$/i
|
||||
@search_pms = true
|
||||
nil
|
||||
|
|
|
@ -527,7 +527,7 @@ describe Search do
|
|||
|
||||
TopicAllowedGroup.create!(group_id: group.id, topic_id: topic.id)
|
||||
|
||||
["mars in:personal", "mars IN:PERSONAL"].each do |query|
|
||||
["mars in:personal", "mars IN:PERSONAL", "in:messages mars", "IN:MESSAGES mars"].each do |query|
|
||||
results = Search.execute(query, guardian: Guardian.new(user))
|
||||
expect(results.posts).to contain_exactly(reply)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue