 				Dep.depend()
 				return openedRooms[typeName].ready
 		}
+
+	getOpenedRoomByRid = (rid) ->
+		for typeName, openedRoom of openedRooms
+			if openedRoom.rid is rid
+				return openedRoom
 
 	getDomOfRoom = (typeName, rid) ->
 		room = openedRooms[typeName]

	updateUserStatus: updateUserStatus
	onlineUsers: onlineUsers
	updateMentionsMarksOfRoom: updateMentionsMarksOfRoom

Meteor.startup ->
	ChatMessage.find().observe
		removed: (record) ->
			if RoomManager.getOpenedRoomByRid(record.rid)?
				recordBefore = ChatMessage.findOne {ts: {$lt: record.ts}}, {sort: {ts: -1}}
				if recordBefore?
					ChatMessage.update {_id: recordBefore._id}, {$set: {tick: new Date}}

				recordAfter = ChatMessage.findOne {ts: {$gt: record.ts}}, {sort: {ts: 1}}
				if recordAfter?
					ChatMessage.update {_id: recordAfter._id}, {$set: {tick: new Date}}


onDeleteMessageStream = (msg) ->
