mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:23:00 +08:00
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:
@ -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_LIKES_MATCH = /^in:likes$/gi;
|
||||||
const REGEXP_SPECIAL_IN_TITLE_MATCH = /^in:title$/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_SPECIAL_IN_SEEN_MATCH = /^in:seen$/gi;
|
||||||
|
|
||||||
const REGEXP_CATEGORY_SLUG = /^(\#[a-zA-Z0-9\-:]+)/gi;
|
const REGEXP_CATEGORY_SLUG = /^(\#[a-zA-Z0-9\-:]+)/gi;
|
||||||
@ -98,7 +98,7 @@ export default Component.extend({
|
|||||||
in: {
|
in: {
|
||||||
title: false,
|
title: false,
|
||||||
likes: false,
|
likes: false,
|
||||||
personal: false,
|
messages: false,
|
||||||
seen: false,
|
seen: false,
|
||||||
},
|
},
|
||||||
all_tags: false,
|
all_tags: false,
|
||||||
@ -149,8 +149,8 @@ export default Component.extend({
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.setSearchedTermSpecialInValue(
|
this.setSearchedTermSpecialInValue(
|
||||||
"searchedTerms.special.in.personal",
|
"searchedTerms.special.in.messages",
|
||||||
REGEXP_SPECIAL_IN_PERSONAL_MATCH
|
REGEXP_SPECIAL_IN_MESSAGES_MATCH
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setSearchedTermSpecialInValue(
|
this.setSearchedTermSpecialInValue(
|
||||||
@ -460,9 +460,9 @@ export default Component.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onChangeSearchTermForSpecialInPersonal(checked) {
|
onChangeSearchTermForSpecialInMessages(checked) {
|
||||||
this.set("searchedTerms.special.in.personal", checked);
|
this.set("searchedTerms.special.in.messages", checked);
|
||||||
this.updateInRegex(REGEXP_SPECIAL_IN_PERSONAL_MATCH, "personal");
|
this.updateInRegex(REGEXP_SPECIAL_IN_MESSAGES_MATCH, "messages");
|
||||||
},
|
},
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -211,7 +211,8 @@ export default Controller.extend({
|
|||||||
return (
|
return (
|
||||||
q &&
|
q &&
|
||||||
this.currentUser &&
|
this.currentUser &&
|
||||||
(q.indexOf("in:personal") > -1 ||
|
(q.indexOf("in:messages") > -1 ||
|
||||||
|
q.indexOf("in:personal") > -1 ||
|
||||||
q.indexOf(
|
q.indexOf(
|
||||||
`personal_messages:${this.currentUser.get("username_lower")}`
|
`personal_messages:${this.currentUser.get("username_lower")}`
|
||||||
) > -1)
|
) > -1)
|
||||||
|
@ -83,8 +83,8 @@
|
|||||||
id="matching-in-messages"
|
id="matching-in-messages"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="in-private"
|
class="in-private"
|
||||||
checked=searchedTerms.special.in.personal
|
checked=searchedTerms.special.in.messages
|
||||||
click=(action "onChangeSearchTermForSpecialInPersonal" value="target.checked")
|
click=(action "onChangeSearchTermForSpecialInMessages" value="target.checked")
|
||||||
}}
|
}}
|
||||||
<label for="matching-in-messages">{{i18n "search.advanced.filters.private"}}</label>
|
<label for="matching-in-messages">{{i18n "search.advanced.filters.private"}}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -392,7 +392,7 @@ createWidget("search-menu-assistant", {
|
|||||||
addSearchSuggestion("in:likes");
|
addSearchSuggestion("in:likes");
|
||||||
addSearchSuggestion("in:bookmarks");
|
addSearchSuggestion("in:bookmarks");
|
||||||
addSearchSuggestion("in:mine");
|
addSearchSuggestion("in:mine");
|
||||||
addSearchSuggestion("in:personal");
|
addSearchSuggestion("in:messages");
|
||||||
addSearchSuggestion("in:seen");
|
addSearchSuggestion("in:seen");
|
||||||
addSearchSuggestion("in:tracking");
|
addSearchSuggestion("in:tracking");
|
||||||
addSearchSuggestion("in:unseen");
|
addSearchSuggestion("in:unseen");
|
||||||
@ -532,7 +532,7 @@ createWidget("search-menu-initial-options", {
|
|||||||
case "private_messages":
|
case "private_messages":
|
||||||
content.push(
|
content.push(
|
||||||
this.attach("search-menu-assistant-item", {
|
this.attach("search-menu-assistant-item", {
|
||||||
slug: `${term} in:personal`,
|
slug: `${term} in:messages`,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -218,7 +218,7 @@ export default createWidget("search-menu", {
|
|||||||
if (searchContext?.type === "topic") {
|
if (searchContext?.type === "topic") {
|
||||||
query += encodeURIComponent(` topic:${searchContext.id}`);
|
query += encodeURIComponent(` topic:${searchContext.id}`);
|
||||||
} else if (searchContext?.type === "private_messages") {
|
} else if (searchContext?.type === "private_messages") {
|
||||||
query += encodeURIComponent(` in:personal`);
|
query += encodeURIComponent(` in:messages`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
|
@ -133,7 +133,7 @@ acceptance("Search - Full Page", function (needs) {
|
|||||||
test("search for personal messages", async function (assert) {
|
test("search for personal messages", async function (assert) {
|
||||||
await visit("/search");
|
await visit("/search");
|
||||||
|
|
||||||
await fillIn(".search-query", "discourse in:personal");
|
await fillIn(".search-query", "discourse in:messages");
|
||||||
await click(".search-cta");
|
await click(".search-cta");
|
||||||
|
|
||||||
assert.strictEqual(count(".fps-topic"), 1, "has one post");
|
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 visit("/search");
|
||||||
await fillIn(".search-query", "none");
|
await fillIn(".search-query", "none");
|
||||||
await click(".search-advanced-options .in-private");
|
await click(".search-advanced-options .in-private");
|
||||||
@ -258,8 +258,8 @@ acceptance("Search - Full Page", function (needs) {
|
|||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
queryAll(".search-query").val(),
|
queryAll(".search-query").val(),
|
||||||
"none in:personal",
|
"none in:messages",
|
||||||
'has updated search term to "none in:personal"'
|
'has updated search term to "none in:messages"'
|
||||||
);
|
);
|
||||||
|
|
||||||
await fillIn(".search-query", "none in:personal-direct");
|
await fillIn(".search-query", "none in:personal-direct");
|
||||||
|
@ -788,9 +788,9 @@ acceptance("Search - assistant", function (needs) {
|
|||||||
await triggerKeyEvent("#search-term", "keyup", 51);
|
await triggerKeyEvent("#search-term", "keyup", 51);
|
||||||
assert.strictEqual(query(firstTarget).innerText, "sam in:title");
|
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);
|
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) {
|
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"]));
|
const obj = JSON.parse(JSON.stringify(fixturesByUrl["/search.json"]));
|
||||||
obj.topics.firstObject.visited = true;
|
obj.topics.firstObject.visited = true;
|
||||||
return response(obj);
|
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"]));
|
const obj = JSON.parse(JSON.stringify(fixturesByUrl["/search.json"]));
|
||||||
obj.topics.firstObject.archetype = "private_message";
|
obj.topics.firstObject.archetype = "private_message";
|
||||||
return response(obj);
|
return response(obj);
|
||||||
|
@ -748,6 +748,9 @@ class Search
|
|||||||
elsif word =~ /^in:personal$/i
|
elsif word =~ /^in:personal$/i
|
||||||
@search_pms = true
|
@search_pms = true
|
||||||
nil
|
nil
|
||||||
|
elsif word =~ /^in:messages$/i
|
||||||
|
@search_pms = true
|
||||||
|
nil
|
||||||
elsif word =~ /^in:personal-direct$/i
|
elsif word =~ /^in:personal-direct$/i
|
||||||
@search_pms = true
|
@search_pms = true
|
||||||
nil
|
nil
|
||||||
|
@ -527,7 +527,7 @@ describe Search do
|
|||||||
|
|
||||||
TopicAllowedGroup.create!(group_id: group.id, topic_id: topic.id)
|
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))
|
results = Search.execute(query, guardian: Guardian.new(user))
|
||||||
expect(results.posts).to contain_exactly(reply)
|
expect(results.posts).to contain_exactly(reply)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user