From 386f361855663b445d1497bbbabcf87891ce94d9 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 4 Jan 2015 12:54:23 +0100 Subject: Autocmplete suggestions for non-local users, also suggest from visited channel's connections --- view/js/autocomplete.js | 16 ++++++++++++---- view/tpl/head.tpl | 2 ++ view/tpl/jot-header.tpl | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) (limited to 'view') diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index 7c3145769..204d3756f 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -3,13 +3,16 @@ * * require jQuery, jquery.textcomplete */ -function mysearch(term, callback, backend_url) { +function mysearch(term, callback, backend_url, extra_channels) { var postdata = { start:0, count:100, search:term, type:'c', } + + if(extra_channels) { + postdata['extra_channels[]'] = extra_channels; $.ajax({ type:'POST', @@ -28,20 +31,25 @@ function format(item) { function replace(item) { // $2 ensures that prefix (@,@!) is preserved - return '$1$2'+item.nick.replace(' ','') + '+' + item.id; + var id = item.id; + // 16 chars of hash should be enough. Full hash could be used if it can be done in a visually appealing way. + // 16 chars is also the minimum length in the backend (otherwise it's interpreted as a local id). + if(id.length > 16) + id = item.id.substring(0,16); + return '$1$2'+item.nick.replace(' ','') + '+' + id; } /** * jQuery plugin 'contact_autocomplete' */ (function( $ ){ - $.fn.contact_autocomplete = function(backend_url) { + $.fn.contact_autocomplete = function(backend_url, extra_channels = null) { // Autocomplete contacts contacts = { match: /(^|\s)(@\!*)([^ \n]+)$/, index: 3, - search: function(term, callback) { mysearch(term, callback, backend_url); }, + search: function(term, callback) { mysearch(term, callback, backend_url, extra_channels); }, replace: replace, template: format, } diff --git a/view/tpl/head.tpl b/view/tpl/head.tpl index 9c9e7b970..8a32bd7f6 100755 --- a/view/tpl/head.tpl +++ b/view/tpl/head.tpl @@ -26,6 +26,8 @@ var localUser = {{if $local_user}}{{$local_user}}{{else}}false{{/if}}; var zid = {{if $zid}}'{{$zid}}'{{else}}null{{/if}}; var justifiedGalleryActive = false; + {{if $channel_hash}}var channelHash = '{{$channel_hash}}';{{/if}} + {{if $channel_id}}var channelId = '{{$channel_id}}';{{/if}}{{* Used in e.g. autocomplete *}} diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index bdbb7d09c..c23395b03 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -10,7 +10,7 @@ function initEditor(cb){ if(plaintext == 'none') { $("#profile-jot-text-loading").spin(false).hide(); $("#profile-jot-text").css({ 'height': 200, 'color': '#000' }); - $("#profile-jot-text").contact_autocomplete(baseurl+"/acl"); + $("#profile-jot-text").contact_autocomplete(baseurl+"/acl",[channelId]); // Also gives suggestions from current channel's connections editor = true; $("a#jot-perms-icon").colorbox({ 'inline' : true, -- cgit v1.2.3