Code Duplication    Length = 18-19 lines in 2 locations

chat/tornadoapp.py 2 locations

@@ 625-643 (lines=19) @@
622
			self.async_redis_publisher.hset(connection_id, self.id, WebRtcRedisStates.READY)
623
			self.publish({
624
				VarNames.EVENT: Actions.ACCEPT_FILE,
625
				VarNames.CONNECTION_ID: connection_id,
626
				VarNames.WEBRTC_OPPONENT_ID: self.id,
627
				VarNames.HANDLER_NAME: HandlerNames.PEER_CONNECTION,
628
			}, sender_ws_id)
629
		else:
630
			raise ValidationError("Invalid channel status")
631
632
	# todo
633
	# we can use channel_status = self.sync_redis.shgetall(connection_id)
634
	# and then self.async_redis_publisher.hset(connection_id, self.id, WebRtcRedisStates.READY)
635
	# if we shgetall and only then do async hset
636
	# we can catch an issue when 2 concurrent users accepted the call
637
	# but we didn't  send them ACCEPT_CALL as they both were in status 'offered'
638
	def accept_call(self, in_message):
639
		connection_id = in_message[VarNames.CONNECTION_ID]
640
		self_status = self.sync_redis.shget(connection_id, self.id)
641
		if self_status == WebRtcRedisStates.RESPONDED:
642
			self.sync_redis.hset(connection_id, self.id, WebRtcRedisStates.READY)
643
			channel_status = self.sync_redis.shgetall(connection_id)
644
			del channel_status[self.id]
645
			message = {
646
				VarNames.EVENT: Actions.ACCEPT_CALL,
@@ 536-553 (lines=18) @@
533
534
	def parse_imgs(self, imgs, mess_id):
535
		res_imgs = []
536
		if not imgs:
537
			return res_imgs
538
		fetch = False
539
		for k in imgs:
540
			b64 = imgs[k].get(VarNames.IMG_B64)
541
			if b64:
542
				img = extract_photo(imgs[k][VarNames.IMG_B64], imgs[k][VarNames.IMG_FILE_NAME])
543
				res_imgs.append(Image(message_id=mess_id, img=img, symbol=k))
544
			else:
545
				fetch = True
546
		self.merge_came_imgs_with_db(fetch, mess_id, res_imgs)
547
		return res_imgs
548
549
	def merge_came_imgs_with_db(self, fetch, mess_id, res_imgs):
550
		fetched_messages = None
551
		if fetch:
552
			fetched_messages = Image.objects.filter(message_id=mess_id)
553
		if res_imgs:
554
			Image.objects.bulk_create(res_imgs)
555
		if fetched_messages:
556
			for m in fetched_messages: