コード例 #1
0
ファイル: message_handler.py プロジェクト: lmyfzx/pychat
	def edit_message_edit(self, data, message):
		action = Actions.EDIT_MESSAGE
		message.giphy = None
		tags = data[VarNames.MESSAGE_TAGS]
		files = UploadedFile.objects.filter(id__in=data.get(VarNames.FILES), user_id=self.user_id)
		if files or tags:
			update_symbols(files, tags, message)
		if tags:
			db_tags = MessageMention.objects.filter(message_id=message.id)
			update_or_create = []
			update_or_create_dict = {}
			for db_tag in db_tags:
				if tags.get(db_tag.symbol) and tags.get(db_tag.symbol) != db_tag.user_id:
					update_or_create.append(MessageMention(message_id=message.id, symbol=db_tag.symbol, user_id=tags[db_tag.symbol]))
					update_or_create_dict[db_tag.symbol] = True
			if update_or_create:
				MessageMention.objects.bulk_update(update_or_create)
			create_tags = []
			for (k, v) in tags.items():
				if not update_or_create_dict.get(k):
					create_tags.append(MessageMention(message_id=message.id, symbol=k, user_id=v))
			if create_tags:
				MessageMention.objects.bulk_create(create_tags)

		if files:
			up_files_to_img(files, message.id)
		if message.symbol:  # fetch all, including that we just store
			db_images = Image.objects.filter(message_id=message.id)
			prep_files = MessagesCreator.prepare_img_video(db_images, message.id)
		else:
			prep_files = None
		Message.objects.filter(id=message.id).update(content=message.content, symbol=message.symbol, giphy=None, edited_times=get_milliseconds())
		self.publish(self.message_creator.create_send_message(message, action, prep_files, tags), message.room_id)
コード例 #2
0
 def edit_message_edit(self, data, message):
     action = Actions.EDIT_MESSAGE
     message.giphy = None
     files = UploadedFile.objects.filter(id__in=data.get(VarNames.FILES),
                                         user_id=self.user_id)
     if files:
         update_symbols(files, message)
         up_files_to_img(files, message.id)
     if message.symbol:  # fetch all, including that we just store
         db_images = Image.objects.filter(message_id=message.id)
         prep_files = MessagesCreator.prepare_img_video(
             db_images, message.id)
     else:
         prep_files = None
     Message.objects.filter(id=message.id).update(
         content=message.content,
         symbol=message.symbol,
         giphy=None,
         edited_times=message.edited_times)
     self.publish(self.create_send_message(message, action, prep_files),
                  message.room_id)