mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	closes #6136
This commit is contained in:
		| @@ -21,17 +21,31 @@ SocketModules.settings = {}; | |||||||
| /* Chat */ | /* Chat */ | ||||||
|  |  | ||||||
| SocketModules.chats.getRaw = function (socket, data, callback) { | SocketModules.chats.getRaw = function (socket, data, callback) { | ||||||
| 	if (!data || !data.hasOwnProperty('mid') || !data.hasOwnProperty('roomId')) { | 	if (!data || !data.hasOwnProperty('mid')) { | ||||||
| 		return callback(new Error('[[error:invalid-data]]')); | 		return callback(new Error('[[error:invalid-data]]')); | ||||||
| 	} | 	} | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function (next) { | 		function (next) { | ||||||
| 			Messaging.isUserInRoom(socket.uid, data.roomId, next); | 			Messaging.getMessageField(data.mid, 'roomId', next); | ||||||
| 		}, | 		}, | ||||||
| 		function (inRoom, next) { | 		function (roomId, next) { | ||||||
| 			if (!inRoom) { | 			async.parallel({ | ||||||
|  | 				isAdmin: function (next) { | ||||||
|  | 					user.isAdministrator(socket.uid, next); | ||||||
|  | 				}, | ||||||
|  | 				hasMessage: function (next) { | ||||||
|  | 					db.isSortedSetMember('uid:' + socket.uid + ':chat:room:' + roomId + ':mids', data.mid, next); | ||||||
|  | 				}, | ||||||
|  | 				inRoom: function (next) { | ||||||
|  | 					Messaging.isUserInRoom(socket.uid, roomId, next); | ||||||
|  | 				}, | ||||||
|  | 			}, next); | ||||||
|  | 		}, | ||||||
|  | 		function (results, next) { | ||||||
|  | 			if (!results.isAdmin && (!results.inRoom || !results.hasMessage)) { | ||||||
| 				return next(new Error('[[error:not-allowed]]')); | 				return next(new Error('[[error:not-allowed]]')); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			Messaging.getMessageField(data.mid, 'content', next); | 			Messaging.getMessageField(data.mid, 'content', next); | ||||||
| 		}, | 		}, | ||||||
| 	], callback); | 	], callback); | ||||||
|   | |||||||
| @@ -243,7 +243,7 @@ describe('Messaging Library', function () { | |||||||
| 				assert.equal(messageData.content, 'first chat message'); | 				assert.equal(messageData.content, 'first chat message'); | ||||||
| 				assert(messageData.fromUser); | 				assert(messageData.fromUser); | ||||||
| 				assert(messageData.roomId, roomId); | 				assert(messageData.roomId, roomId); | ||||||
| 				socketModules.chats.getRaw({ uid: fooUid }, { roomId: roomId, mid: messageData.mid }, function (err, raw) { | 				socketModules.chats.getRaw({ uid: fooUid }, { mid: messageData.mid }, function (err, raw) { | ||||||
| 					assert.ifError(err); | 					assert.ifError(err); | ||||||
| 					assert.equal(raw, 'first chat message'); | 					assert.equal(raw, 'first chat message'); | ||||||
| 					setTimeout(done, 300); | 					setTimeout(done, 300); | ||||||
| @@ -275,12 +275,29 @@ describe('Messaging Library', function () { | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should return not in room error', function (done) { | 		it('should return not allowed error if mid is not in room', function (done) { | ||||||
| 			socketModules.chats.getRaw({ uid: 0 }, { roomId: roomId, mid: 1 }, function (err) { | 			var myRoomId; | ||||||
|  | 			User.create({ username: 'dummy' }, function (err, uid) { | ||||||
|  | 				assert.ifError(err); | ||||||
|  | 				socketModules.chats.newRoom({ uid: bazUid }, { touid: uid }, function (err, _roomId) { | ||||||
|  | 					myRoomId = _roomId; | ||||||
|  | 					assert.ifError(err); | ||||||
|  | 					assert(myRoomId); | ||||||
|  | 					socketModules.chats.getRaw({ uid: bazUid }, { mid: 1 }, function (err) { | ||||||
| 						assert.equal(err.message, '[[error:not-allowed]]'); | 						assert.equal(err.message, '[[error:not-allowed]]'); | ||||||
|  | 						socketModules.chats.send({ uid: bazUid }, { roomId: myRoomId, message: 'admin will see this' }, function (err, message) { | ||||||
|  | 							assert.ifError(err); | ||||||
|  | 							socketModules.chats.getRaw({ uid: fooUid }, { mid: message.mid }, function (err, raw) { | ||||||
|  | 								assert.ifError(err); | ||||||
|  | 								assert.equal(raw, 'admin will see this'); | ||||||
| 								done(); | 								done(); | ||||||
| 							}); | 							}); | ||||||
| 						}); | 						}); | ||||||
|  | 					}); | ||||||
|  | 				}); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  |  | ||||||
| 		it('should notify offline users of message', function (done) { | 		it('should notify offline users of message', function (done) { | ||||||
| 			Messaging.notificationSendDelay = 100; | 			Messaging.notificationSendDelay = 100; | ||||||
| @@ -507,7 +524,7 @@ describe('Messaging Library', function () { | |||||||
| 		it('should edit message', function (done) { | 		it('should edit message', function (done) { | ||||||
| 			socketModules.chats.edit({ uid: fooUid }, { mid: mid, roomId: roomId, message: 'message edited' }, function (err) { | 			socketModules.chats.edit({ uid: fooUid }, { mid: mid, roomId: roomId, message: 'message edited' }, function (err) { | ||||||
| 				assert.ifError(err); | 				assert.ifError(err); | ||||||
| 				socketModules.chats.getRaw({ uid: fooUid }, { roomId: roomId, mid: mid }, function (err, raw) { | 				socketModules.chats.getRaw({ uid: fooUid }, { mid: mid }, function (err, raw) { | ||||||
| 					assert.ifError(err); | 					assert.ifError(err); | ||||||
| 					assert.equal(raw, 'message edited'); | 					assert.equal(raw, 'message edited'); | ||||||
| 					done(); | 					done(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user