mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-08 08:32:53 +01:00
Squashed commit of the following:
Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
This commit is contained in:
@@ -101,6 +101,7 @@
|
||||
"too-many-messages": "You have sent too many messages, please wait awhile.",
|
||||
"invalid-chat-message": "Invalid chat message",
|
||||
"chat-message-too-long": "Chat message is too long",
|
||||
"cant-edit-chat-message": "You are not allowed to edit this message",
|
||||
|
||||
"reputation-system-disabled": "Reputation system is disabled.",
|
||||
"downvoting-disabled": "Downvoting is disabled",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"chat.seven_days": "7 Days",
|
||||
"chat.thirty_days": "30 Days",
|
||||
"chat.three_months": "3 Months",
|
||||
"chat.delete_message_confirm": "Are you sure you wish to delete this message?",
|
||||
|
||||
"composer.compose": "Compose",
|
||||
"composer.show_preview": "Show Preview",
|
||||
|
||||
@@ -63,6 +63,17 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
});
|
||||
});
|
||||
|
||||
components.get('chat/messages')
|
||||
.on('click', '[data-action="edit"]', function() {
|
||||
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
||||
var inputEl = components.get('chat/input');
|
||||
Chats.prepEdit(inputEl, messageId);
|
||||
})
|
||||
.on('click', '[data-action="delete"]', function() {
|
||||
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
||||
Chats.delete(messageId);
|
||||
});
|
||||
|
||||
$('.recent-chats').on('scroll', function() {
|
||||
var $this = $(this);
|
||||
var bottom = ($this[0].scrollHeight - $this.height()) * 0.9;
|
||||
@@ -95,6 +106,49 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
|
||||
$('[component="chat/input"]').focus();
|
||||
});
|
||||
Mousetrap.bind('up', function(e) {
|
||||
if (e.target === components.get('chat/input').get(0)) {
|
||||
// Retrieve message id from messages list
|
||||
var message = components.get('chat/messages').find('.chat-message[data-self="1"]').last();
|
||||
var lastMid = message.attr('data-mid');
|
||||
var inputEl = components.get('chat/input');
|
||||
|
||||
Chats.prepEdit(inputEl, lastMid);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Chats.prepEdit = function(inputEl, messageId) {
|
||||
socket.emit('modules.chats.getRaw', { mid: messageId }, function(err, raw) {
|
||||
// Populate the input field with the raw message content
|
||||
if (inputEl.val().length === 0) {
|
||||
// By setting the `data-mid` attribute, I tell the chat code that I am editing a
|
||||
// message, instead of posting a new one.
|
||||
inputEl.attr('data-mid', messageId).addClass('editing');
|
||||
inputEl.val(raw);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Chats.delete = function(messageId) {
|
||||
translator.translate('[[modules:chat.delete_message_confirm]]', function(translated) {
|
||||
bootbox.confirm(translated, function(ok) {
|
||||
if (ok) {
|
||||
socket.emit('modules.chats.delete', {
|
||||
messageId: messageId
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
// Remove message from list
|
||||
components.get('chat/message', messageId).slideUp('slow', function() {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Chats.addSinceHandler = function(toUid, chatContentEl, sinceEl) {
|
||||
@@ -253,6 +307,22 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
socket.on('event:user_status_change', function(data) {
|
||||
app.updateUserStatus($('.chats-list [data-uid="' + data.uid + '"] [component="user/status"]'), data.status);
|
||||
});
|
||||
|
||||
socket.on('event:chats.edit', function(data) {
|
||||
var message;
|
||||
|
||||
data.messages.forEach(function(message) {
|
||||
templates.parse('partials/chat_message', {
|
||||
messages: message
|
||||
}, function(html) {
|
||||
body = components.get('chat/message', message.messageId);
|
||||
if (body.length) {
|
||||
body.replaceWith(html);
|
||||
components.get('chat/message', message.messageId).find('.timeago').timeago();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Chats.resizeMainWindow = function() {
|
||||
@@ -278,7 +348,9 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
};
|
||||
|
||||
Chats.sendMessage = function(toUid, inputEl) {
|
||||
var msg = inputEl.val();
|
||||
var msg = inputEl.val(),
|
||||
mid = inputEl.attr('data-mid');
|
||||
|
||||
if (msg.length > config.maximumChatMessageLength) {
|
||||
return app.alertError('[[error:chat-message-too-long]]');
|
||||
}
|
||||
@@ -288,20 +360,35 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll',
|
||||
}
|
||||
|
||||
inputEl.val('');
|
||||
socket.emit('modules.chats.send', {
|
||||
touid: toUid,
|
||||
message: msg
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
if (err.message === '[[error:email-not-confirmed-chat]]') {
|
||||
return app.showEmailConfirmWarning(err);
|
||||
}
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
inputEl.removeAttr('data-mid');
|
||||
|
||||
sounds.play('chat-outgoing');
|
||||
Chats.notifyTyping(toUid, false);
|
||||
});
|
||||
if (!mid) {
|
||||
socket.emit('modules.chats.send', {
|
||||
touid: toUid,
|
||||
message: msg
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
if (err.message === '[[error:email-not-confirmed-chat]]') {
|
||||
return app.showEmailConfirmWarning(err);
|
||||
}
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
sounds.play('chat-outgoing');
|
||||
Chats.notifyTyping(toUid, false);
|
||||
});
|
||||
} else {
|
||||
socket.emit('modules.chats.edit', {
|
||||
mid: mid,
|
||||
message: msg
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
Chats.notifyTyping(toUid, false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Chats.scrollToBottom = function(containerEl) {
|
||||
|
||||
@@ -19,6 +19,10 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
});
|
||||
|
||||
socket.on('event:chats.receive', function(data) {
|
||||
if (ajaxify.currentPage.match(/^chats/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var username = data.message.fromUser.username;
|
||||
var isSelf = parseInt(data.message.fromUser.uid, 10) === parseInt(app.user.uid, 10);
|
||||
data.message.self = data.self;
|
||||
@@ -252,6 +256,17 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
|
||||
}
|
||||
});
|
||||
|
||||
chatModal.find('[component="chat/messages"]')
|
||||
.on('click', '[data-action="edit"]', function() {
|
||||
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
||||
var inputEl = chatModal.find('[component="chat/input"]');
|
||||
Chats.prepEdit(inputEl, messageId);
|
||||
})
|
||||
.on('click', '[data-action="delete"]', function() {
|
||||
var messageId = $(this).parents('[data-mid]').attr('data-mid');
|
||||
Chats.delete(messageId);
|
||||
});
|
||||
|
||||
Chats.addSinceHandler(chatModal.attr('touid'), chatModal.find('.chat-content'), chatModal.find('[data-since]'));
|
||||
|
||||
Chats.addSendHandlers(chatModal.attr('touid'), chatModal.find('#chat-message-input'), chatModal.find('#chat-message-send-btn'));
|
||||
|
||||
@@ -35,6 +35,13 @@ define('components', function() {
|
||||
|
||||
'categories/category': function(name, value) {
|
||||
return $('[component="categories/category"][data-' + name + '="' + value + '"]');
|
||||
},
|
||||
|
||||
'chat/message': function(messageId) {
|
||||
return $('[component="chat/message"][data-mid="' + messageId + '"]');
|
||||
},
|
||||
'chat/message/body': function(messageId) {
|
||||
return $('[component="chat/message"][data-mid="' + messageId + '"] [component="chat/message/body"]');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user