Completed
Push — master ( a9bb65...7eff16 )
by Florin
03:45
created
event/main_listener.php 3 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -14,144 +14,144 @@
 block discarded – undo
14 14
 class main_listener implements EventSubscriberInterface
15 15
 {
16 16
 
17
-    static public function getSubscribedEvents()
18
-    {
19
-        return array(
20
-            'core.user_setup' => 'load_language_on_setup',
21
-            'core.page_footer' => 'friends_list',
22
-            'core.page_header' => 'check_login',
23
-            'core.memberlist_view_profile' => 'check_friends'
24
-        );
25
-    }
26
-
27
-
28
-    /* @var \phpbb\template\template */
29
-    protected $template;
30
-
31
-    /**
32
-     * @var main_model
33
-     */
34
-    protected $model;
35
-
36
-    /**
37
-     * @var friends_model
38
-     */
39
-    protected $friends_model;
40
-
41
-    /**
42
-     * @var user
43
-     */
44
-    protected $user;
45
-
46
-    /**
47
-     * @var symfony_request
48
-     */
49
-    protected $symfony_request;
50
-
51
-    public function __construct(
52
-        template $template,
53
-        main_model $model,
54
-        friends_model $friends_model,
55
-        user $user,
56
-        symfony_request $symfony_request
57
-    )
58
-    {
59
-        $this->template = $template;
60
-        $this->model = $model;
61
-        $this->friends_model = $friends_model;
62
-        $this->user = $user;
63
-        $this->symfony_request = $symfony_request;
64
-    }
65
-
66
-    public function friends_list()
67
-    {
68
-        $context = new RequestContext();
69
-        $context->fromRequest($this->symfony_request);
70
-        $baseUrl = generate_board_url(true) . $context->getBaseUrl();
71
-
72
-        $scriptName = $this->symfony_request->getScriptName();
73
-        $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName);
74
-
75
-        if ($scriptName != '') {
76
-            $baseUrl = str_replace('/' . $scriptName, '', $baseUrl);
77
-        }
78
-
79
-        $friends = $this->model->getFriends();
80
-        $friends_online = array_filter($friends, function ($friend) {
81
-            return $friend['user_status'] != 0;
82
-        });
83
-        $this->template->assign_var('S_COUNT_FRIENDS', count($friends_online));
84
-        foreach ($friends as $friend) {
85
-            $this->template->assign_block_vars('chat_friends', array(
86
-                'U_USERID' => $friend['user_id'],
87
-                'U_USERNAME' => $friend['username'],
88
-                'U_USERCOLOR' => $friend['user_colour'],
89
-                'U_STATUS' => $friend['user_status'],
90
-                'U_USERINBOX' => $friend['inbox'],
91
-            ));
92
-        }
93
-        $this->template->assign_vars(array(
94
-            'BASE_URL' => $baseUrl
95
-        ));
96
-    }
97
-
98
-    public function load_language_on_setup($event)
99
-    {
100
-        $lang_set_ext = $event['lang_set_ext'];
101
-        $lang_set_ext[] = array(
102
-            'ext_name' => 'florinp/messenger',
103
-            'lang_set' => 'common',
104
-        );
105
-        $event['lang_set_ext'] = $lang_set_ext;
106
-    }
107
-
108
-    public function check_login()
109
-    {
110
-        $s_enable_messenger = 0;
111
-        if (in_array($this->user->data['user_type'], array(USER_NORMAL, USER_FOUNDER))) {
112
-            $s_enable_messenger = 1;
113
-        }
114
-        $this->template->assign_var('S_ENABLE_MESSENGER', $s_enable_messenger);
115
-    }
116
-
117
-    public function check_friends($event)
118
-    {
119
-        $context = new RequestContext();
120
-        $context->fromRequest($this->symfony_request);
121
-        $baseUrl = generate_board_url(true) . $context->getBaseUrl();
122
-
123
-        $scriptName = $this->symfony_request->getScriptName();
124
-        $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName);
125
-
126
-        if ($scriptName != '') {
127
-            $baseUrl = str_replace('/' . $scriptName, '', $baseUrl);
128
-        }
129
-
130
-        $user_id = $event['member']['user_id'];
131
-        $sender_id = $this->user->data['user_id'];
132
-        $request = $this->friends_model->get_request_by_sender_id($sender_id);
133
-        $check_friend = $this->friends_model->check_friend(array(
134
-            'user_id' => $this->user->data['user_id'],
135
-            'friend_id' => $user_id,
136
-        ));
137
-        $check_request = $this->friends_model->check_request(array(
138
-            'user_id' => $user_id,
139
-            'sender_id' => $this->user->data['user_id']
140
-        ));
141
-        $check_request_confirm = $this->friends_model->check_request(array(
142
-            'user_id' => $this->user->data['user_id'],
143
-            'sender_id' => $user_id
144
-        ));
145
-        $check_widget = true;
146
-        if ($user_id == $this->user->data['user_id']) $check_widget = false;
147
-        $this->template->assign_vars(array(
148
-            'U_USER_ID' => $user_id,
149
-            'U_CHECK_FRIEND' => $check_friend,
150
-            'U_CHECK_REQUEST' => $check_request,
151
-            'U_CHECK_REQUEST_CONFIRM' => $check_request_confirm,
152
-            'U_CHECK_WIDGET' => $check_widget,
153
-            'U_REQUEST_ID' => $request['request_id'],
154
-            'BASE_URL' => $baseUrl
155
-        ));
156
-    }
17
+	static public function getSubscribedEvents()
18
+	{
19
+		return array(
20
+			'core.user_setup' => 'load_language_on_setup',
21
+			'core.page_footer' => 'friends_list',
22
+			'core.page_header' => 'check_login',
23
+			'core.memberlist_view_profile' => 'check_friends'
24
+		);
25
+	}
26
+
27
+
28
+	/* @var \phpbb\template\template */
29
+	protected $template;
30
+
31
+	/**
32
+	 * @var main_model
33
+	 */
34
+	protected $model;
35
+
36
+	/**
37
+	 * @var friends_model
38
+	 */
39
+	protected $friends_model;
40
+
41
+	/**
42
+	 * @var user
43
+	 */
44
+	protected $user;
45
+
46
+	/**
47
+	 * @var symfony_request
48
+	 */
49
+	protected $symfony_request;
50
+
51
+	public function __construct(
52
+		template $template,
53
+		main_model $model,
54
+		friends_model $friends_model,
55
+		user $user,
56
+		symfony_request $symfony_request
57
+	)
58
+	{
59
+		$this->template = $template;
60
+		$this->model = $model;
61
+		$this->friends_model = $friends_model;
62
+		$this->user = $user;
63
+		$this->symfony_request = $symfony_request;
64
+	}
65
+
66
+	public function friends_list()
67
+	{
68
+		$context = new RequestContext();
69
+		$context->fromRequest($this->symfony_request);
70
+		$baseUrl = generate_board_url(true) . $context->getBaseUrl();
71
+
72
+		$scriptName = $this->symfony_request->getScriptName();
73
+		$scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName);
74
+
75
+		if ($scriptName != '') {
76
+			$baseUrl = str_replace('/' . $scriptName, '', $baseUrl);
77
+		}
78
+
79
+		$friends = $this->model->getFriends();
80
+		$friends_online = array_filter($friends, function ($friend) {
81
+			return $friend['user_status'] != 0;
82
+		});
83
+		$this->template->assign_var('S_COUNT_FRIENDS', count($friends_online));
84
+		foreach ($friends as $friend) {
85
+			$this->template->assign_block_vars('chat_friends', array(
86
+				'U_USERID' => $friend['user_id'],
87
+				'U_USERNAME' => $friend['username'],
88
+				'U_USERCOLOR' => $friend['user_colour'],
89
+				'U_STATUS' => $friend['user_status'],
90
+				'U_USERINBOX' => $friend['inbox'],
91
+			));
92
+		}
93
+		$this->template->assign_vars(array(
94
+			'BASE_URL' => $baseUrl
95
+		));
96
+	}
97
+
98
+	public function load_language_on_setup($event)
99
+	{
100
+		$lang_set_ext = $event['lang_set_ext'];
101
+		$lang_set_ext[] = array(
102
+			'ext_name' => 'florinp/messenger',
103
+			'lang_set' => 'common',
104
+		);
105
+		$event['lang_set_ext'] = $lang_set_ext;
106
+	}
107
+
108
+	public function check_login()
109
+	{
110
+		$s_enable_messenger = 0;
111
+		if (in_array($this->user->data['user_type'], array(USER_NORMAL, USER_FOUNDER))) {
112
+			$s_enable_messenger = 1;
113
+		}
114
+		$this->template->assign_var('S_ENABLE_MESSENGER', $s_enable_messenger);
115
+	}
116
+
117
+	public function check_friends($event)
118
+	{
119
+		$context = new RequestContext();
120
+		$context->fromRequest($this->symfony_request);
121
+		$baseUrl = generate_board_url(true) . $context->getBaseUrl();
122
+
123
+		$scriptName = $this->symfony_request->getScriptName();
124
+		$scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName);
125
+
126
+		if ($scriptName != '') {
127
+			$baseUrl = str_replace('/' . $scriptName, '', $baseUrl);
128
+		}
129
+
130
+		$user_id = $event['member']['user_id'];
131
+		$sender_id = $this->user->data['user_id'];
132
+		$request = $this->friends_model->get_request_by_sender_id($sender_id);
133
+		$check_friend = $this->friends_model->check_friend(array(
134
+			'user_id' => $this->user->data['user_id'],
135
+			'friend_id' => $user_id,
136
+		));
137
+		$check_request = $this->friends_model->check_request(array(
138
+			'user_id' => $user_id,
139
+			'sender_id' => $this->user->data['user_id']
140
+		));
141
+		$check_request_confirm = $this->friends_model->check_request(array(
142
+			'user_id' => $this->user->data['user_id'],
143
+			'sender_id' => $user_id
144
+		));
145
+		$check_widget = true;
146
+		if ($user_id == $this->user->data['user_id']) $check_widget = false;
147
+		$this->template->assign_vars(array(
148
+			'U_USER_ID' => $user_id,
149
+			'U_CHECK_FRIEND' => $check_friend,
150
+			'U_CHECK_REQUEST' => $check_request,
151
+			'U_CHECK_REQUEST_CONFIRM' => $check_request_confirm,
152
+			'U_CHECK_WIDGET' => $check_widget,
153
+			'U_REQUEST_ID' => $request['request_id'],
154
+			'BASE_URL' => $baseUrl
155
+		));
156
+	}
157 157
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
     {
68 68
         $context = new RequestContext();
69 69
         $context->fromRequest($this->symfony_request);
70
-        $baseUrl = generate_board_url(true) . $context->getBaseUrl();
70
+        $baseUrl = generate_board_url(true).$context->getBaseUrl();
71 71
 
72 72
         $scriptName = $this->symfony_request->getScriptName();
73 73
         $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName);
74 74
 
75 75
         if ($scriptName != '') {
76
-            $baseUrl = str_replace('/' . $scriptName, '', $baseUrl);
76
+            $baseUrl = str_replace('/'.$scriptName, '', $baseUrl);
77 77
         }
78 78
 
79 79
         $friends = $this->model->getFriends();
80
-        $friends_online = array_filter($friends, function ($friend) {
80
+        $friends_online = array_filter($friends, function($friend) {
81 81
             return $friend['user_status'] != 0;
82 82
         });
83 83
         $this->template->assign_var('S_COUNT_FRIENDS', count($friends_online));
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $context = new RequestContext();
120 120
         $context->fromRequest($this->symfony_request);
121
-        $baseUrl = generate_board_url(true) . $context->getBaseUrl();
121
+        $baseUrl = generate_board_url(true).$context->getBaseUrl();
122 122
 
123 123
         $scriptName = $this->symfony_request->getScriptName();
124 124
         $scriptName = substr($scriptName, -1, 1) == '/' ? '' : utf8_basename($scriptName);
125 125
 
126 126
         if ($scriptName != '') {
127
-            $baseUrl = str_replace('/' . $scriptName, '', $baseUrl);
127
+            $baseUrl = str_replace('/'.$scriptName, '', $baseUrl);
128 128
         }
129 129
 
130 130
         $user_id = $event['member']['user_id'];
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,9 @@
 block discarded – undo
143 143
             'sender_id' => $user_id
144 144
         ));
145 145
         $check_widget = true;
146
-        if ($user_id == $this->user->data['user_id']) $check_widget = false;
146
+        if ($user_id == $this->user->data['user_id']) {
147
+        	$check_widget = false;
148
+        }
147 149
         $this->template->assign_vars(array(
148 150
             'U_USER_ID' => $user_id,
149 151
             'U_CHECK_FRIEND' => $check_friend,
Please login to merge, or discard this patch.
models/main_model.php 2 patches
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -12,35 +12,35 @@  discard block
 block discarded – undo
12 12
 class main_model
13 13
 {
14 14
 
15
-    /**
16
-     * @var config
17
-     */
18
-    protected $config;
19
-
20
-    /**
21
-     * @var driver_interface
22
-     */
23
-    protected $phpbb_db;
24
-
25
-    /**
26
-     * @var user
27
-     */
28
-    protected $user;
29
-
30
-    /**
31
-     * @var database
32
-     */
33
-    protected $db;
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected $friends_request_table;
39
-
40
-    /**
41
-     * @var string
42
-     */
43
-    protected $user_friends_table;
15
+	/**
16
+	 * @var config
17
+	 */
18
+	protected $config;
19
+
20
+	/**
21
+	 * @var driver_interface
22
+	 */
23
+	protected $phpbb_db;
24
+
25
+	/**
26
+	 * @var user
27
+	 */
28
+	protected $user;
29
+
30
+	/**
31
+	 * @var database
32
+	 */
33
+	protected $db;
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected $friends_request_table;
39
+
40
+	/**
41
+	 * @var string
42
+	 */
43
+	protected $user_friends_table;
44 44
 
45 45
 	/**
46 46
 	 * @var user_loader
@@ -48,32 +48,32 @@  discard block
 block discarded – undo
48 48
 	protected $user_loader;
49 49
 
50 50
 
51
-    public function __construct(
52
-        config $config,
53
-        driver_interface $phpbb_db,
54
-        user $user,
51
+	public function __construct(
52
+		config $config,
53
+		driver_interface $phpbb_db,
54
+		user $user,
55 55
 		user_loader $user_loader,
56
-        database $db,
57
-        $friends_request_table,
58
-        $user_friends_table
59
-    )
60
-    {
61
-        $this->config = $config;
62
-        $this->phpbb_db = $phpbb_db;
63
-        $this->user = $user;
64
-        $this->db = $db;
65
-        $this->friends_request_table = $friends_request_table;
66
-        $this->user_friends_table = $user_friends_table;
56
+		database $db,
57
+		$friends_request_table,
58
+		$user_friends_table
59
+	)
60
+	{
61
+		$this->config = $config;
62
+		$this->phpbb_db = $phpbb_db;
63
+		$this->user = $user;
64
+		$this->db = $db;
65
+		$this->friends_request_table = $friends_request_table;
66
+		$this->user_friends_table = $user_friends_table;
67 67
 		$this->user_loader = $user_loader;
68
-    }
69
-
70
-    /**
71
-     * get all friends
72
-     * @return array the list of friends
73
-     */
74
-    public function getFriends()
75
-    {
76
-        $sql = "
68
+	}
69
+
70
+	/**
71
+	 * get all friends
72
+	 * @return array the list of friends
73
+	 */
74
+	public function getFriends()
75
+	{
76
+		$sql = "
77 77
             SELECT u.user_id,
78 78
                    u.username,
79 79
                    u.username_clean,
@@ -87,32 +87,32 @@  discard block
 block discarded – undo
87 87
             WHERE " . $this->user_friends_table.".user_id = ".(int)$this->user->data['user_id']."
88 88
             GROUP BY u.user_id
89 89
         ";
90
-        $result = $this->phpbb_db->sql_query($sql);
91
-
92
-        $friends = array();
93
-        while ($row = $this->phpbb_db->sql_fetchrow($result)) {
94
-            $friends[] = array(
95
-                'user_id' => $row['user_id'],
96
-                'username' => $row['username_clean'],
97
-                'user_colour' => $row['user_colour'],
98
-                'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0,
90
+		$result = $this->phpbb_db->sql_query($sql);
91
+
92
+		$friends = array();
93
+		while ($row = $this->phpbb_db->sql_fetchrow($result)) {
94
+			$friends[] = array(
95
+				'user_id' => $row['user_id'],
96
+				'username' => $row['username_clean'],
97
+				'user_colour' => $row['user_colour'],
98
+				'user_status' => ($row['session_time'] >= (time() - ($this->config['load_online_time'] * 60))) ? 1 : 0,
99 99
 				'user_avatar' => $this->user_loader->get_avatar($row['user_id'], true, true),
100
-                'inbox' => $this->getInboxFromId($row['user_id'])
101
-            );
102
-        }
103
-        $this->phpbb_db->sql_freeresult();
104
-
105
-        return $friends;
106
-    }
107
-
108
-    /**
109
-     * checks if a user is friend with other user and vice-versa
110
-     * @param int $friend_id
111
-     * @return bool
112
-     */
113
-    public function checkFriend($friend_id)
114
-    {
115
-        $sql = "
100
+				'inbox' => $this->getInboxFromId($row['user_id'])
101
+			);
102
+		}
103
+		$this->phpbb_db->sql_freeresult();
104
+
105
+		return $friends;
106
+	}
107
+
108
+	/**
109
+	 * checks if a user is friend with other user and vice-versa
110
+	 * @param int $friend_id
111
+	 * @return bool
112
+	 */
113
+	public function checkFriend($friend_id)
114
+	{
115
+		$sql = "
116 116
 			SELECT COUNT(zebra_id) as friend_count
117 117
 			FROM " . ZEBRA_TABLE."
118 118
 			WHERE user_id = " . (int)$friend_id."
@@ -211,48 +211,48 @@  discard block
 block discarded – undo
211 211
 			LIMIT 1
212 212
 		";
213 213
 
214
-        $message = $this->db->select($sql, array(
215
-            ':id' => $id
216
-        ));
214
+		$message = $this->db->select($sql, array(
215
+			':id' => $id
216
+		));
217 217
 		$message = $message[0];
218 218
 		$message = $this->parseMessage($message, $message['type']);
219 219
 
220
-        return $message;
221
-    }
222
-
223
-    /**
224
-     * Returns a file by id
225
-     * @param $id File id
226
-     * @return mixed
227
-     */
228
-    public function getFileById($id)
229
-    {
230
-        $sql = "
220
+		return $message;
221
+	}
222
+
223
+	/**
224
+	 * Returns a file by id
225
+	 * @param $id File id
226
+	 * @return mixed
227
+	 */
228
+	public function getFileById($id)
229
+	{
230
+		$sql = "
231 231
 			SELECT *
232 232
 			FROM `files`
233 233
 			WHERE `id` = :id
234 234
 			LIMIT 1
235 235
 		";
236
-        $file = $this->db->select($sql, array(
237
-            ':id' => $id
238
-        ));
236
+		$file = $this->db->select($sql, array(
237
+			':id' => $id
238
+		));
239 239
 		$file = $file[0];
240 240
 		$file = $this->parseFile($file, $file['type']);
241 241
 
242
-        return $file;
243
-    }
242
+		return $file;
243
+	}
244 244
 
245
-    /**
246
-     * Get all message from an user
247
-     * @param int $friend_id
248
-     * @return array
249
-     */
250
-    public function getMessages($friend_id)
251
-    {
245
+	/**
246
+	 * Get all message from an user
247
+	 * @param int $friend_id
248
+	 * @return array
249
+	 */
250
+	public function getMessages($friend_id)
251
+	{
252 252
 		$this->user_loader->load_users([$this->user->data['user_id'], $friend_id]);
253 253
 
254
-        // get the sent messages
255
-        $sql = "SELECT *
254
+		// get the sent messages
255
+		$sql = "SELECT *
256 256
 				FROM `messages`
257 257
 				WHERE `sender_id` = :sender_id
258 258
 					AND `receiver_id` = :receiver_id
@@ -265,58 +265,58 @@  discard block
 block discarded – undo
265 265
 			ORDER BY `sentAt` ASC
266 266
 		";
267 267
 
268
-        $sentMessages = $this->db->select($sql, array(
269
-            ':sender_id' => $this->user->data['user_id'],
270
-            ':receiver_id' => $friend_id
271
-        ));
272
-        $getInbox = $this->db->select($sql, array(
273
-            ':sender_id' => $friend_id,
274
-            ':receiver_id' => $this->user->data['user_id']
275
-        ));
276
-
277
-        $sentFiles = $this->db->select($sqlFiles, array(
278
-            ':sender_id' => $this->user->data['user_id'],
279
-            ':receiver_id' => $friend_id
280
-        ));
281
-        $getFiles = $this->db->select($sqlFiles, array(
282
-            ':sender_id' => $friend_id,
283
-            ':receiver_id' => $this->user->data['user_id']
284
-        ));
285
-
286
-        $sent = array();
287
-        foreach ($sentMessages as $msg) {
288
-            $item = $this->parseMessage($msg, 'sent');
289
-            $sent[] = $item;
290
-        }
291
-        $inbox = array();
292
-        foreach ($getInbox as $msg) {
293
-            $item = $this->parseMessage($msg, 'inbox');
294
-            $inbox[] = $item;
295
-        }
296
-
297
-        foreach ($sentFiles as $file) {
298
-            $item = $this->parseFile($file, 'sent');
299
-            $sent[] = $item;
300
-        }
301
-
302
-        foreach ($getFiles as $file) {
303
-            $item = $this->parseFile($file, 'inbox');
304
-            $inbox[] = $item;
305
-        }
306
-
307
-        $unsorted_messages = array_merge($sent, $inbox);
308
-
309
-        uasort($unsorted_messages, function ($a, $b) {
310
-            return ($a['sentAt'] > $b['sentAt']) ? -1 : 1;
311
-        });
312
-
313
-        $sorted_messages = array();
314
-        foreach ($unsorted_messages as $msg) {
315
-            $sorted_messages[] = $msg;
316
-        }
317
-
318
-        return $sorted_messages;
319
-    }
268
+		$sentMessages = $this->db->select($sql, array(
269
+			':sender_id' => $this->user->data['user_id'],
270
+			':receiver_id' => $friend_id
271
+		));
272
+		$getInbox = $this->db->select($sql, array(
273
+			':sender_id' => $friend_id,
274
+			':receiver_id' => $this->user->data['user_id']
275
+		));
276
+
277
+		$sentFiles = $this->db->select($sqlFiles, array(
278
+			':sender_id' => $this->user->data['user_id'],
279
+			':receiver_id' => $friend_id
280
+		));
281
+		$getFiles = $this->db->select($sqlFiles, array(
282
+			':sender_id' => $friend_id,
283
+			':receiver_id' => $this->user->data['user_id']
284
+		));
285
+
286
+		$sent = array();
287
+		foreach ($sentMessages as $msg) {
288
+			$item = $this->parseMessage($msg, 'sent');
289
+			$sent[] = $item;
290
+		}
291
+		$inbox = array();
292
+		foreach ($getInbox as $msg) {
293
+			$item = $this->parseMessage($msg, 'inbox');
294
+			$inbox[] = $item;
295
+		}
296
+
297
+		foreach ($sentFiles as $file) {
298
+			$item = $this->parseFile($file, 'sent');
299
+			$sent[] = $item;
300
+		}
301
+
302
+		foreach ($getFiles as $file) {
303
+			$item = $this->parseFile($file, 'inbox');
304
+			$inbox[] = $item;
305
+		}
306
+
307
+		$unsorted_messages = array_merge($sent, $inbox);
308
+
309
+		uasort($unsorted_messages, function ($a, $b) {
310
+			return ($a['sentAt'] > $b['sentAt']) ? -1 : 1;
311
+		});
312
+
313
+		$sorted_messages = array();
314
+		foreach ($unsorted_messages as $msg) {
315
+			$sorted_messages[] = $msg;
316
+		}
317
+
318
+		return $sorted_messages;
319
+	}
320 320
 
321 321
 	/**
322 322
 	 * Parse message to specific array
@@ -359,15 +359,15 @@  discard block
 block discarded – undo
359 359
 		return $item;
360 360
 	}
361 361
 
362
-    /**
363
-     * Change messages status to read
364
-     * @param $friend_id
365
-     * @return int
366
-     */
367
-    public function updateMessagesStatus($friend_id)
368
-    {
362
+	/**
363
+	 * Change messages status to read
364
+	 * @param $friend_id
365
+	 * @return int
366
+	 */
367
+	public function updateMessagesStatus($friend_id)
368
+	{
369 369
 
370
-        $sql = "
370
+		$sql = "
371 371
 			UPDATE `messages`
372 372
 			SET `newMsg` = 0
373 373
 			WHERE `newMsg` = 1
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 
307 307
         $unsorted_messages = array_merge($sent, $inbox);
308 308
 
309
-        uasort($unsorted_messages, function ($a, $b) {
309
+        uasort($unsorted_messages, function($a, $b) {
310 310
             return ($a['sentAt'] > $b['sentAt']) ? -1 : 1;
311 311
         });
312 312
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	 */
347 347
 	protected function parseFile($file, $type) {
348 348
 		$item = array();
349
-		$item['id'] = 'f_' . $file['id'];
349
+		$item['id'] = 'f_'.$file['id'];
350 350
 		$item['sender_id'] = $file['sender_id'];
351 351
 		$item['sender_avatar'] = $this->user_loader->get_avatar($file['sender_id'], true, true);
352 352
 		$item['receiver_id'] = $file['receiver_id'];
Please login to merge, or discard this patch.