Is there something like @mentions but for posts?
-
@baris said in Is there something like @mentions but for posts?:
What would you put after the &? The post id? So
&61013
would link to https://community.nodebb.org/post/61013?That would work, also have some auto-parsing where if you link to a thread it shows favicon and the topic title?
-
It would be nice to have some shortcut to post/topics/categories: like #p61013 #t1021 and #c12 (od with &, as Esteban suggested),
and possibly it automatically parse it like this:&p61013
->[Is there something like @mentions but for posts? | NodeBB - Post 61013](https://community.nodebb.org/post/61013)
so : Is there something like @mentions but for posts?- Post 61013 -
@baris said in Is there something like @mentions but for posts?:
What would you put after the &? The post id? So
&61013
would link to https://community.nodebb.org/post/61013?You'd get a list of the topic titles, just like with Mentions
-
@Giggiux said in Is there something like @mentions but for posts?:
It would be nice to have some shortcut to post/topics/categories: like #p61013 #t1021 and #c12 (od with &, as Esteban suggested),
and possibly it automatically parse it like this:&p61013
->[Is there something like @mentions but for posts? | NodeBB - Post 61013](https://community.nodebb.org/post/61013)
so : Is there something like @mentions but for posts?- Post 61013My main issue is the whole composer thing, I want it to open up a window and show me the posts.
The parsing the content once I know the post && is not that problematic.
-
@Esteban-Constante I can suggest you to read the source code to see how mentions work
-
@Giggiux said in Is there something like @mentions but for posts?:
@Esteban-Constante I can suggest you to read the source code to see how mentions work
So far I've got the Topic Title Search working (through the API, as I haven't found a way to do it by sockets), I'm having issues trying to replace it with the link.
-
@Esteban-Constante by socket you can create a new socket handler in your plugin (and it can use the same function as the one you already use for the api route more or less), check here how they create a new "socket route", and here how they use it for the Q&A plugin.
Here is how they do for actual mentions (you probably already saw it)
-
/* globals socket, app, utils */ $(document).ready(function() { // start variable to grab the last JSON data var lastData; var topicList; var catList = []; var catData = []; $(window).on('composer:autocomplete:init', function(ev, data) { loadCatNames(); var topicSearch = { match: /\&t([^\s\n]*)?$/, search: function (term, callback) { //var topicList; $.getJSON("/api/search/?term=" + term + "&in=titles&sortBy=topic.title&sortDirection=&showAs=posts", function (data) { if (data) { topicList = data.posts.map(function(post) { return post.topic.title; }); // save lastData to be used in replacing function lastData = data.posts; callback(topicList); } }); }, index: 1, replace: function (mention, ev) { if (lastData.length && lastData[0].topic) { return '[' + mention + '](/topic/' + lastData[0].topic.slug + ') ' } else { return; } }, cache: true }; var categorySearch = { match: /\&c([^\s\n]*)?$/, search: function (term, callback) { //var topicList; if (!term) { var categories = catList.filter(function(value, index, array) { return array.indexOf(value) === index; }); callback(categories); } else { callback($.map(catList, function (word) { return word.indexOf(term) === 0 ? word : null; })); } }, index: 1, replace: function (mention, ev) { function search(nameKey, myArray){ for (var i=0; i < myArray.length; i++) { if (myArray[i].name === nameKey) { return myArray[i]; } } } var resultObject = search(mention, catData); return '[' + resultObject.name + '](/category/' + resultObject.cid + ') ' }, cache: true }; data.strategies.push(topicSearch); data.strategies.push(categorySearch); }); $(window).on('action:composer.loaded', function(e, data) { var composer = $('#cmp-uuid-' + data.post_uuid + ' .write'); composer.attr('data-mentions', '1'); }); function loadCatNames() { $.getJSON("/api/categories", function (data) { if (data) { var childrenCids = []; var allCategories = []; var category; function eachRecursive(obj) { for (var k in obj) { if (typeof obj[k] == "object" && obj[k] !== null) { catList.push(obj[k].name); category = { name: obj[k].name, cid: obj[k].cid } catData.push(category) eachRecursive(obj[k].children); } else { return; } } } eachRecursive(data.categories); } }); } });
Here's the code I've made. You can even try it in this forum using the console.
Use "&t" and type the topic title. Use "&c" and type the forum category.EDIT
Replaced /topics/ with /topic/ -