{"action":"closed","issue":{"url":"https://api.github.com/repos/jcbrand/converse.js/issues/654","repository_url":"https://api.github.com/repos/jcbrand/converse.js","labels_url":"https://api.github.com/repos/jcbrand/converse.js/issues/654/labels{/name}","comments_url":"https://api.github.com/repos/jcbrand/converse.js/issues/654/comments","events_url":"https://api.github.com/repos/jcbrand/converse.js/issues/654/events","html_url":"https://github.com/jcbrand/converse.js/issues/654","id":157912382,"number":654,"title":"Override renderMessage Function","user":{"login":"julian-d","id":1136495,"avatar_url":"https://avatars.githubusercontent.com/u/1136495?v=3","gravatar_id":"","url":"https://api.github.com/users/julian-d","html_url":"https://github.com/julian-d","followers_url":"https://api.github.com/users/julian-d/followers","following_url":"https://api.github.com/users/julian-d/following{/other_user}","gists_url":"https://api.github.com/users/julian-d/gists{/gist_id}","starred_url":"https://api.github.com/users/julian-d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julian-d/subscriptions","organizations_url":"https://api.github.com/users/julian-d/orgs","repos_url":"https://api.github.com/users/julian-d/repos","events_url":"https://api.github.com/users/julian-d/events{/privacy}","received_events_url":"https://api.github.com/users/julian-d/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-06-01T13:53:18Z","updated_at":"2016-06-03T05:46:03Z","closed_at":"2016-06-03T05:46:02Z","body":"I need some Help on writing my first Plugin.\r\n\r\nI want to rewrite the complete renderMessage function but I can't get it up and running. \r\nWhat am I doing wrong?\r\n\r\n```\r\n\r\n(function (root, factory) {\r\n    if (typeof define === 'function' && define.amd) {\r\n        // AMD. Register as a module called \"myplugin\"\r\n        define(\"customsmiley\", [\"converse\"], factory);\r\n    } else {\r\n        // Browser globals. If you're not using a module loader such as require.js,\r\n        // then this line below executes. Make sure that your plugin's <script> tag\r\n        // appears after the one from converse.js.\r\n        factory(converse);\r\n    }\r\n}(this, function (converse_api) {\r\n\r\n    // Commonly used utilities and variables can be found under the \"env\"\r\n    // namespace of converse_api\r\n\r\n    // Strophe methods for building stanzas\r\n    var Strophe = converse_api.env.Strophe,\r\n        $iq = converse_api.env.$iq,\r\n        $msg = converse_api.env.$msg,\r\n        $pres = converse_api.env.$pres,\r\n        $build = converse_api.env.$build,\r\n        b64_sha1 = converse_api.env.b64_sha1;\r\n\r\n    // Other frequently used utilities\r\n    var $ = converse_api.env.jQuery,\r\n        _ = converse_api.env._,\r\n        moment = converse_api.env.moment;\r\n\r\n\r\n    // The following line registers your plugin.\r\n    converse_api.plugins.add('customsmiley', {\r\n\r\n        initialize: function () {\r\n            // Converse.js's plugin mechanism will call the initialize\r\n            // method on any plugin (if it exists) as soon as the plugin has\r\n            // been loaded.\r\n\r\n            // Inside this method, you have access to the protected \"inner\"\r\n            // converse object, from which you can get any configuration\r\n            // options that the user might have passed in via\r\n            // converse.initialize. These values are stored in the\r\n            // \"user_settings\" attribute.\r\n\r\n            // Let's assume the user might in a custom setting, like so:\r\n            // converse.initialize({\r\n            //      \"initialize_message\": \"My plugin has been initialized\"\r\n            // });\r\n            //\r\n            // Then we can alert that message, like so:\r\n            // alert(this.converse.user_settings.initialize_message);\r\n        },\r\n\r\n        \r\n        overrides: {\r\n          \r\n\r\n            renderMessage: function (attrs) {\r\n                  var converse = this;\r\n                    /* Renders a chat message based on the passed in attributes.\r\n                     *\r\n                     * Parameters:\r\n                     *  (Object) attrs: An object containing the message attributes.\r\n                     *\r\n                     *  Returns:\r\n                     *      The DOM element representing the message.\r\n                     */\r\n                    var msg_time = moment(attrs.time) || moment,\r\n                        text = attrs.message,\r\n                        match = text.match(/^\\/(.*?)(?: (.*))?$/),\r\n                        fullname = this.model.get('fullname') || attrs.fullname,\r\n                        extra_classes = attrs.delayed && 'delayed' || '',\r\n                        template, username;\r\n\r\n                    if ((match) && (match[1] === 'me')) {\r\n                        text = text.replace(/^\\/me/, '');\r\n                        template = converse.templates.action;\r\n                        username = fullname;\r\n                    } else  {\r\n                        template = converse.templates.message;\r\n                        username = attrs.sender === 'me' && __('me') || fullname;\r\n                    }\r\n                    this.$content.find('div.chat-event').remove();\r\n\r\n                    // FIXME: leaky abstraction from MUC\r\n                    if (this.is_chatroom && attrs.sender === 'them' && (new RegExp(\"\\\\b\"+this.model.get('nick')+\"\\\\b\")).test(text)) {\r\n                        // Add special class to mark groupchat messages in which we\r\n                        // are mentioned.\r\n                        extra_classes += ' mentioned';\r\n                    }\r\n                    return $(template({\r\n                            msgid: attrs.msgid,\r\n                            'sender': attrs.sender,\r\n                            'time': msg_time.format('hh:mm'),\r\n                            'isodate': msg_time.format(),\r\n                            'username': username,\r\n                            'message': '',\r\n                            'extra_classes': extra_classes\r\n                       })).children('.chat-msg-content').first().text(text)\r\n                            .addHyperlinks()\r\n                            .parent().replaceEmoticons();\r\n                    \r\n                    \r\n                   \r\n                },\r\n                \r\n               \r\n\r\n        }\r\n    });\r\n}));\r\n```"}}
{"actor":{"display_login":"jcbrand"}}