Add emoji support

This commit is contained in:
Midgard 2021-02-17 21:58:06 +01:00
parent 8983e0e504
commit 72f6a3e201
Signed by: midgard
GPG key ID: 511C112F1331BBB4
4 changed files with 2279 additions and 9 deletions

View file

@ -66,6 +66,7 @@
<script type="text/javascript" src="/js/mm_client.js"></script> <script type="text/javascript" src="/js/mm_client.js"></script>
<script type="text/javascript" src="/js/view/view.js"></script> <script type="text/javascript" src="/js/view/view.js"></script>
<script type="text/javascript" src="/js/controller.js"></script> <script type="text/javascript" src="/js/controller.js"></script>
<script type="text/javascript" src="/js/emoji.js"></script>
<script type="text/javascript" src="/js/main.js"></script> <script type="text/javascript" src="/js/main.js"></script>
</body> </body>
</html> </html>

View file

@ -143,17 +143,16 @@ function switchToChannel(client, team, channel) {
function sendMessage(endpoint, channel_id, message) { function sendMessage(endpoint, channel_id, message) {
const client = mm_client.get(endpoint); const client = mm_client.get(endpoint);
client.writePost(channel_id, message); client.writePost(channel_id, message);
pubsub.publish("MESSAGES_NEW", { //pubsub.publish("MESSAGES_NEW", {
endpoint, //endpoint,
channel_id: channel_id, //channel_id: channel_id,
create_at: (new Date()).getTime(), //create_at: (new Date()).getTime(),
user_id: client.me.id, //user_id: client.me.id,
message //message
}); //});
} }
function checkKeyPress(event) { function checkKeyPress(event) {
console.debug(event);
// Battle tested for many years in several browsers // Battle tested for many years in several browsers
if ((event.keyCode === event.DOM_VK_RETURN || event.keyCode === 13 || event.keyCode === 10 || event.key === "Enter" || event.keyIdentifier === "U+000A") && !event.shiftKey && !event.ctrlKey) { if ((event.keyCode === event.DOM_VK_RETURN || event.keyCode === 13 || event.keyCode === 10 || event.key === "Enter" || event.keyIdentifier === "U+000A") && !event.shiftKey && !event.ctrlKey) {
if (byId("compose").value.length > 0) { if (byId("compose").value.length > 0) {

2263
js/emoji.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -53,13 +53,20 @@ function populateChannelList() {
} }
function transformMessageText(message) {
return message.split(/(?<=:|\W|^)(:[a-z0-9_-]+:)(?=:|\W|$)/).map(
(x, i) => i % 2 ? emoji[x.slice(1, -1)] || x : x
);
}
async function createMessageElement(client, post, lastTime, lastAuthor) { async function createMessageElement(client, post, lastTime, lastAuthor) {
const users = await client.getUsers(); const users = await client.getUsers();
const isThreadReply = !!post.parent_id; const isThreadReply = !!post.parent_id;
const messageDiv = document.createElement("div"); const messageDiv = document.createElement("div");
messageDiv.className = "message"; messageDiv.className = "message";
messageDiv.innerText = post.message; messageDiv.innerText = transformMessageText(post.message);
const createAt = new Date(post.create_at); const createAt = new Date(post.create_at);
const createAtDiv = document.createElement("time"); const createAtDiv = document.createElement("time");