浏览代码

Refactor callback method into instance method

JC Brand 6 年之前
父节点
当前提交
14708af715
共有 1 个文件被更改,包括 15 次插入12 次删除
  1. 15 12
      src/converse-muc-views.js

+ 15 - 12
src/converse-muc-views.js

@@ -1509,6 +1509,17 @@ converse.plugins.add('converse-muc-views', {
                 return notification;
             },
 
+            insertNotification (message) {
+                this.content.insertAdjacentHTML(
+                    'beforeend',
+                    tpl_info({
+                        'isodate': (new Date()).toISOString(),
+                        'extra_classes': 'chat-event',
+                        'message': message
+                    })
+                );
+            },
+
             showNotificationsforUser (notification) {
                 /* Given the notification object generated by
                  * parseXUserElement, display any relevant messages and
@@ -1527,21 +1538,13 @@ converse.plugins.add('converse-muc-views', {
                     this.model.save('connection_status', converse.ROOMSTATUS.DISCONNECTED);
                     return;
                 }
-                notification.messages.forEach(message => {
-                    this.content.insertAdjacentHTML(
-                        'beforeend',
-                        tpl_info({
-                            'isodate': (new Date()).toISOString(),
-                            'extra_classes': 'chat-event',
-                            'message': message
-                        }));
-                });
-                if (notification.reason) {
-                    this.showChatEvent(__('The reason given is: "%1$s".', notification.reason));
-                }
                 if (_.get(notification.messages, 'length')) {
+                    notification.messages.forEach(message => this.insertNotification(message));
                     this.scrollDown();
                 }
+                if (notification.reason) {
+                    this.showChatEvent(__('The reason given is: "%1$s".', notification.reason));
+                }
             },
 
             onOccupantAdded (occupant) {