How to get uid from @userslug?
Solved
General Discussion
-
Hi there
I want to get user id from @userslug
Example: get from '@baris' the '1' uid
How to doing this using JavaScript?
Thanks -
-
Hi, I want to more question
How to get uid from username? (with spaces)
Thanks -
Same as before just turn the username into a user slug with the
slugify
module. Client side it would be.require(['slugify'], function(slugify) { var userslug = slugify('some username'); $.getJSON('/api/user/' + userslug, function (data) { console.log(data.uid); }); });
-
@baris very thanks
This is the JS code I write for new chat with users, thanks to the help you give merequire(['autocomplete'], autocomplete => { var modal = bootbox.dialog({ title: '[[flags:start-new-chat]]<i class="fa fa-comments-o" style="margin: 0 7px;"></i>', message: '<input class="form-control input-lg" placeholder="[[user:username]]">', buttons: { cancel: { label: '[[modules:bootbox.cancel]]', className: 'btn-default', callback: () => modal.modal('hide') }, ok: { label: '[[modules:bootbox.ok]]', className: 'btn-primary', callback: () => false } }, onEscape: true, backdrop: true, show: true }); modal.on('shown.bs.modal', () => { var inputEl = modal.find('input'); inputEl.focus(); autocomplete.user(inputEl); modal.find('.btn-primary').click(() => { utils.isUserNameValid(inputEl.val()) ? require(['slugify'], slugify => $.getJSON(`/api/user/${slugify(inputEl.val())}`, data => { app.newChat(data.uid); if (app.user.uid != data.uid) modal.modal('hide'); }).catch(() => app.alertError('[[error:no-user]]')) ) : app.alertError('[[error:invalid-username]]') }); }); });
Copyright © 2024 NodeBB | Contributors