PerBonomi
8 years agoBoss
Make usernames in Notification Feed clickable again
Got this working today; thought I'd share.
Simple endpoint to resolve the user's user id from their login (also works in reverse if you want to use it to find a user's login from their id)
<#assign user_login_get = http.request.parameters.name.get("user_login", "")?string/> <#assign user_id_get = http.request.parameters.name.get("user_id", "")?string/> <#if user_login_get?has_content> <#assign user_id = rest("/users/login/${user_login_get?trim}/id").value/> </#if> <#if user_id_get?has_content> <#attempt> <#assign user_login = rest("/users/id/${user_id_get}/login").value/> <#recover> <#assign user_login = "na"/> </#attempt> </#if> <response> <#if user_id?? && user_id?has_content> <status>success</status> <user_id>${user_id}</user_id> <#elseif user_login?? && user_login != "na"> <status>success</status> <user_login>${user_login}</user_login> <#else> <status>error</status> </#if> </response>
Code on the Notification Feed page. It's on demand. If user hovers a username in the feed, it calls the endpoint, finds the user id, then scans the page for all instances of that username and changes them into links to that user's profile. If a username has already been "converted" the script doesn't trigger.
<@liaAddScript> var obj_user, user_login; $(document).on('mouseenter', '.lia-quilt-notification-feed-item .lia-user-login', function() { var obj_user = $(this); var user_login = obj_user.text(); $.ajax({ url: '<insert path to your endpoint>', type: 'post', data: 'user_login=' + user_login }).done(function(data) { status = $(data).find("status").text(); if(status == "success") { user_id = $(data).find("user_id").text(); if(user_id !== 'undefined') { user_url = '/t5/user/viewprofilepage/user-id/' + user_id; $('.lia-quilt-notification-feed-item .lia-user-login:contains("' +user_login + '")').filter(function() { return $(this).text() == user_login; }).replaceWith('<a class="cust-user-login" href="' + user_url + '" target="_new">' + user_login + '</a>'); } } }); }); </@liaAddScript>
You could probably add some error catching to the JavaScript if you want, but the call is so basic, in this case, I didn't bother.