mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-20 06:29:53 +01:00
commit
9d14c3708d
2 changed files with 63 additions and 54 deletions
|
@ -143,6 +143,20 @@ Things in context:
|
||||||
|
|
||||||
This hook is called on the client side whenever a user joins or changes. This can be used to create notifications or an alternate user list.
|
This hook is called on the client side whenever a user joins or changes. This can be used to create notifications or an alternate user list.
|
||||||
|
|
||||||
|
## chatNewMessage
|
||||||
|
Called from: src/static/js/chat.js
|
||||||
|
|
||||||
|
Things in context:
|
||||||
|
|
||||||
|
1. authorName - The user that wrote this message
|
||||||
|
2. author - The authorID of the user that wrote the message
|
||||||
|
2. text - the message text
|
||||||
|
3. sticky (boolean) - if you want the gritter notification bubble to fade out on its own or just sit there
|
||||||
|
3. timestamp - the timestamp of the chat message
|
||||||
|
4. timeStr - the timestamp as a formatted string
|
||||||
|
|
||||||
|
This hook is called on the client side whenever a chat message is received from the server. It can be used to create different notifications for chat messages.
|
||||||
|
|
||||||
## collectContentPre
|
## collectContentPre
|
||||||
Called from: src/static/js/contentcollector.js
|
Called from: src/static/js/contentcollector.js
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
var padutils = require('./pad_utils').padutils;
|
var padutils = require('./pad_utils').padutils;
|
||||||
var padcookie = require('./pad_cookie').padcookie;
|
var padcookie = require('./pad_cookie').padcookie;
|
||||||
var Tinycon = require('tinycon/tinycon');
|
var Tinycon = require('tinycon/tinycon');
|
||||||
|
var hooks = require('./pluginfw/hooks');
|
||||||
|
|
||||||
var chat = (function()
|
var chat = (function()
|
||||||
{
|
{
|
||||||
|
@ -99,74 +100,68 @@ var chat = (function()
|
||||||
|
|
||||||
var text = padutils.escapeHtmlWithClickableLinks(msg.text, "_blank");
|
var text = padutils.escapeHtmlWithClickableLinks(msg.text, "_blank");
|
||||||
|
|
||||||
/* Performs an action if your name is mentioned */
|
|
||||||
var myName = $('#myusernameedit').val();
|
|
||||||
myName = myName.toLowerCase();
|
|
||||||
var chatText = text.toLowerCase();
|
|
||||||
var wasMentioned = false;
|
|
||||||
if (chatText.indexOf(myName) !== -1 && myName != "undefined"){
|
|
||||||
wasMentioned = true;
|
|
||||||
}
|
|
||||||
/* End of new action */
|
|
||||||
|
|
||||||
var authorName = msg.userName == null ? _('pad.userlist.unnamed') : padutils.escapeHtml(msg.userName);
|
var authorName = msg.userName == null ? _('pad.userlist.unnamed') : padutils.escapeHtml(msg.userName);
|
||||||
|
|
||||||
var html = "<p data-authorId='" + msg.userId + "' class='" + authorClass + "'><b>" + authorName + ":</b><span class='time " + authorClass + "'>" + timeStr + "</span> " + text + "</p>";
|
// the hook args
|
||||||
if(isHistoryAdd)
|
var ctx = {
|
||||||
$(html).insertAfter('#chatloadmessagesbutton');
|
"authorName" : authorName,
|
||||||
else
|
"author" : msg.userId,
|
||||||
$("#chattext").append(html);
|
"text" : text,
|
||||||
|
"sticky" : false,
|
||||||
|
"timestamp" : msg.time,
|
||||||
|
"timeStr" : timeStr
|
||||||
|
}
|
||||||
|
|
||||||
//should we increment the counter??
|
// is the users focus already in the chatbox?
|
||||||
if(increment && !isHistoryAdd)
|
var alreadyFocused = $("#chatinput").is(":focus");
|
||||||
{
|
|
||||||
var count = Number($("#chatcounter").text());
|
|
||||||
count++;
|
|
||||||
|
|
||||||
// is the users focus already in the chatbox?
|
// does the user already have the chatbox open?
|
||||||
var alreadyFocused = $("#chatinput").is(":focus");
|
var chatOpen = $("#chatbox").is(":visible");
|
||||||
|
|
||||||
// does the user already have the chatbox open?
|
// does this message contain this user's name? (is the curretn user mentioned?)
|
||||||
var chatOpen = $("#chatbox").is(":visible");
|
var myName = $('#myusernameedit').val();
|
||||||
|
var wasMentioned = (text.toLowerCase().indexOf(myName.toLowerCase()) !== -1 && myName != "undefined");
|
||||||
|
|
||||||
$("#chatcounter").text(count);
|
if(wasMentioned && !alreadyFocused && !isHistoryAdd && !chatOpen)
|
||||||
// chat throb stuff -- Just make it throw for twice as long
|
{ // If the user was mentioned show for twice as long and flash the browser window
|
||||||
if(wasMentioned && !alreadyFocused && !isHistoryAdd && !chatOpen)
|
chatMentions++;
|
||||||
{ // If the user was mentioned show for twice as long and flash the browser window
|
Tinycon.setBubble(chatMentions);
|
||||||
$.gritter.add({
|
ctx.sticky = true;
|
||||||
// (string | mandatory) the heading of the notification
|
}
|
||||||
title: authorName,
|
|
||||||
// (string | mandatory) the text inside the notification
|
|
||||||
text: text,
|
|
||||||
// (bool | optional) if you want it to fade out on its own or just sit there
|
|
||||||
sticky: true,
|
|
||||||
// (int | optional) the time you want it to be alive for before fading out
|
|
||||||
time: '2000'
|
|
||||||
});
|
|
||||||
|
|
||||||
chatMentions++;
|
// Call chat message hook
|
||||||
Tinycon.setBubble(chatMentions);
|
hooks.aCallAll("chatNewMessage", ctx, function() {
|
||||||
}
|
|
||||||
|
var html = "<p data-authorId='" + msg.userId + "' class='" + authorClass + "'><b>" + authorName + ":</b><span class='time " + authorClass + "'>" + ctx.timeStr + "</span> " + ctx.text + "</p>";
|
||||||
|
if(isHistoryAdd)
|
||||||
|
$(html).insertAfter('#chatloadmessagesbutton');
|
||||||
else
|
else
|
||||||
|
$("#chattext").append(html);
|
||||||
|
|
||||||
|
//should we increment the counter??
|
||||||
|
if(increment && !isHistoryAdd)
|
||||||
{
|
{
|
||||||
if(!chatOpen){
|
// Update the counter of unread messages
|
||||||
|
var count = Number($("#chatcounter").text());
|
||||||
|
count++;
|
||||||
|
$("#chatcounter").text(count);
|
||||||
|
|
||||||
|
if(!chatOpen) {
|
||||||
$.gritter.add({
|
$.gritter.add({
|
||||||
// (string | mandatory) the heading of the notification
|
// (string | mandatory) the heading of the notification
|
||||||
title: authorName,
|
title: ctx.authorName,
|
||||||
// (string | mandatory) the text inside the notification
|
// (string | mandatory) the text inside the notification
|
||||||
text: text,
|
text: ctx.text,
|
||||||
|
|
||||||
// (bool | optional) if you want it to fade out on its own or just sit there
|
// (bool | optional) if you want it to fade out on its own or just sit there
|
||||||
sticky: false,
|
sticky: ctx.sticky,
|
||||||
// (int | optional) the time you want it to be alive for before fading out
|
// (int | optional) the time you want it to be alive for before fading out
|
||||||
time: '4000'
|
time: '4000'
|
||||||
});
|
});
|
||||||
Tinycon.setBubble(count);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
// Clear the chat mentions when the user clicks on the chat input box
|
|
||||||
|
// Clear the chat mentions when the user clicks on the chat input box
|
||||||
$('#chatinput').click(function(){
|
$('#chatinput').click(function(){
|
||||||
chatMentions = 0;
|
chatMentions = 0;
|
||||||
Tinycon.setBubble(0);
|
Tinycon.setBubble(0);
|
||||||
|
|
Loading…
Reference in a new issue