mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 23:15:48 +01:00
search user and initiate chat from expanded chat page
This commit is contained in:
@@ -276,7 +276,12 @@ app.cacheBuster = null;
|
|||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
app.openChat(roomId);
|
if (!ajaxify.currentPage.match(/^chats\//)) {
|
||||||
|
app.openChat(roomId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ajaxify.go('chats/' + roomId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
|||||||
Chats.scrollToBottom($('.expanded-chat ul'));
|
Chats.scrollToBottom($('.expanded-chat ul'));
|
||||||
|
|
||||||
Chats.initialised = true;
|
Chats.initialised = true;
|
||||||
|
|
||||||
|
Chats.handleSearch();
|
||||||
|
|
||||||
if (ajaxify.data.hasOwnProperty('roomId')) {
|
if (ajaxify.data.hasOwnProperty('roomId')) {
|
||||||
components.get('chat/input').focus();
|
components.get('chat/input').focus();
|
||||||
@@ -530,6 +532,75 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
|||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Chats.handleSearch = function() {
|
||||||
|
var timeoutId = 0;
|
||||||
|
|
||||||
|
components.get('chat/search').on('keyup', function() {
|
||||||
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
timeoutId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeoutId = setTimeout(doSearch, 250);
|
||||||
|
});
|
||||||
|
|
||||||
|
function doSearch() {
|
||||||
|
var username = components.get('chat/search').val();
|
||||||
|
var chatsListEl = $('[component="chat/search/list"]');
|
||||||
|
|
||||||
|
if(username) {
|
||||||
|
socket.emit('user.search', {
|
||||||
|
query: username,
|
||||||
|
searchBy: 'username'
|
||||||
|
}, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
chatsListEl.empty();
|
||||||
|
|
||||||
|
if (data.users.length === 0) {
|
||||||
|
chatsListEl.append('<li><div><span>No users found!</span></div></li>');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data.users.forEach(function(userObj) {
|
||||||
|
function createUserImage() {
|
||||||
|
return (userObj.picture ?
|
||||||
|
'<img src="' + userObj.picture + '" title="' + userObj.username +'" />' :
|
||||||
|
'<div class="user-icon" style="background-color: ' + userObj['icon:bgColor'] + '">' + userObj['icon:text'] + '</div>') +
|
||||||
|
'<i class="fa fa-circle status ' + userObj.status + '"></i> ' +
|
||||||
|
userObj.username;
|
||||||
|
}
|
||||||
|
|
||||||
|
var chatEl = $('<li component="chat/search/user" />')
|
||||||
|
.attr('data-uid', userObj.uid)
|
||||||
|
.appendTo(chatsListEl);
|
||||||
|
|
||||||
|
chatEl.append(createUserImage());
|
||||||
|
|
||||||
|
chatEl.click(function() {
|
||||||
|
socket.emit('modules.chats.hasPrivateChat', userObj.uid, function(err, roomId) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
if (roomId) {
|
||||||
|
ajaxify.go('chats/' + roomId);
|
||||||
|
} else {
|
||||||
|
app.newChat(userObj.uid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chatsListEl.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return Chats;
|
return Chats;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user