mirror of https://github.com/procxx/kepka.git
				
				
				
			Refacotred HistoryWidget::sendFileConfirmed.
- New way to edit media in message. - Added some "const". - Fixed uploading state in albums when edit media.
This commit is contained in:
		
							parent
							
								
									9d789c2657
								
							
						
					
					
						commit
						0e7ce97da7
					
				|  | @ -4241,6 +4241,8 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 	file->edit = isEditing; | 	file->edit = isEditing; | ||||||
| 	Auth().uploader().upload(newId, file); | 	Auth().uploader().upload(newId, file); | ||||||
| 
 | 
 | ||||||
|  | 	const auto itemToEdit = isEditing ? App::histItemById(newId) : nullptr; | ||||||
|  | 
 | ||||||
| 	const auto history = Auth().data().history(file->to.peer); | 	const auto history = Auth().data().history(file->to.peer); | ||||||
| 	const auto peer = history->peer; | 	const auto peer = history->peer; | ||||||
| 
 | 
 | ||||||
|  | @ -4261,14 +4263,12 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 	TextUtilities::Trim(caption); | 	TextUtilities::Trim(caption); | ||||||
| 	auto localEntities = TextUtilities::EntitiesToMTP(caption.entities); | 	auto localEntities = TextUtilities::EntitiesToMTP(caption.entities); | ||||||
| 
 | 
 | ||||||
| 	if (isEditing) { | 	if (itemToEdit) { | ||||||
| 		if (const auto itemToEdit = App::histItemById(newId)) { |  | ||||||
| 		itemToEdit->setIsEditingMedia(true); | 		itemToEdit->setIsEditingMedia(true); | ||||||
| 		if (const auto id = itemToEdit->groupId()) { | 		if (const auto id = itemToEdit->groupId()) { | ||||||
| 			groupId = id.value; | 			groupId = id.value; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	auto flags = NewMessageFlags(peer) | 	auto flags = NewMessageFlags(peer) | ||||||
| 		| MTPDmessage::Flag::f_entities | 		| MTPDmessage::Flag::f_entities | ||||||
|  | @ -4276,8 +4276,8 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 	if (file->to.replyTo) { | 	if (file->to.replyTo) { | ||||||
| 		flags |= MTPDmessage::Flag::f_reply_to_msg_id; | 		flags |= MTPDmessage::Flag::f_reply_to_msg_id; | ||||||
| 	} | 	} | ||||||
| 	bool channelPost = peer->isChannel() && !peer->isMegagroup(); | 	const auto channelPost = peer->isChannel() && !peer->isMegagroup(); | ||||||
| 	bool silentPost = channelPost && file->to.silent; | 	const auto silentPost = channelPost && file->to.silent; | ||||||
| 	if (channelPost) { | 	if (channelPost) { | ||||||
| 		flags |= MTPDmessage::Flag::f_views; | 		flags |= MTPDmessage::Flag::f_views; | ||||||
| 		flags |= MTPDmessage::Flag::f_post; | 		flags |= MTPDmessage::Flag::f_post; | ||||||
|  | @ -4293,22 +4293,19 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 	if (groupId) { | 	if (groupId) { | ||||||
| 		flags |= MTPDmessage::Flag::f_grouped_id; | 		flags |= MTPDmessage::Flag::f_grouped_id; | ||||||
| 	} | 	} | ||||||
| 	auto messageFromId = channelPost ? 0 : Auth().userId(); | 	const auto messageFromId = channelPost ? 0 : Auth().userId(); | ||||||
| 	auto messagePostAuthor = channelPost | 	const auto messagePostAuthor = channelPost | ||||||
| 		? App::peerName(Auth().user()) | 		? App::peerName(Auth().user()) | ||||||
| 		: QString(); | 		: QString(); | ||||||
| 	const auto messageType = isEditing |  | ||||||
| 		? NewMessageExisting |  | ||||||
| 		: NewMessageUnread; |  | ||||||
| 
 | 
 | ||||||
| 	if (file->type == SendMediaType::Photo) { | 	if (file->type == SendMediaType::Photo) { | ||||||
| 		auto photoFlags = MTPDmessageMediaPhoto::Flag::f_photo | 0; | 		const auto photoFlags = MTPDmessageMediaPhoto::Flag::f_photo | 0; | ||||||
| 		auto photo = MTP_messageMediaPhoto( | 		const auto photo = MTP_messageMediaPhoto( | ||||||
| 			MTP_flags(photoFlags), | 			MTP_flags(photoFlags), | ||||||
| 			file->photo, | 			file->photo, | ||||||
| 			MTPint()); | 			MTPint()); | ||||||
| 		history->addNewMessage( | 
 | ||||||
| 			MTP_message( | 		const auto mtpMessage = MTP_message( | ||||||
| 			MTP_flags(flags), | 			MTP_flags(flags), | ||||||
| 			MTP_int(newId.msg), | 			MTP_int(newId.msg), | ||||||
| 			MTP_int(messageFromId), | 			MTP_int(messageFromId), | ||||||
|  | @ -4324,16 +4321,21 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 			MTP_int(1), | 			MTP_int(1), | ||||||
| 			MTPint(), | 			MTPint(), | ||||||
| 			MTP_string(messagePostAuthor), | 			MTP_string(messagePostAuthor), | ||||||
| 				MTP_long(groupId)), | 			MTP_long(groupId)); | ||||||
| 			messageType); | 
 | ||||||
|  | 		if (itemToEdit) { | ||||||
|  | 			itemToEdit->applyEdition(mtpMessage.c_message()); | ||||||
|  | 		} else { | ||||||
|  | 			history->addNewMessage(mtpMessage, NewMessageUnread); | ||||||
|  | 		} | ||||||
| 	} else if (file->type == SendMediaType::File) { | 	} else if (file->type == SendMediaType::File) { | ||||||
| 		auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0; | 		const auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0; | ||||||
| 		auto document = MTP_messageMediaDocument( | 		const auto document = MTP_messageMediaDocument( | ||||||
| 			MTP_flags(documentFlags), | 			MTP_flags(documentFlags), | ||||||
| 			file->document, | 			file->document, | ||||||
| 			MTPint()); | 			MTPint()); | ||||||
| 		history->addNewMessage( | 
 | ||||||
| 			MTP_message( | 		const auto mtpMessage = MTP_message( | ||||||
| 			MTP_flags(flags), | 			MTP_flags(flags), | ||||||
| 			MTP_int(newId.msg), | 			MTP_int(newId.msg), | ||||||
| 			MTP_int(messageFromId), | 			MTP_int(messageFromId), | ||||||
|  | @ -4349,14 +4351,19 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 			MTP_int(1), | 			MTP_int(1), | ||||||
| 			MTPint(), | 			MTPint(), | ||||||
| 			MTP_string(messagePostAuthor), | 			MTP_string(messagePostAuthor), | ||||||
| 				MTP_long(groupId)), | 			MTP_long(groupId)); | ||||||
| 			messageType); | 
 | ||||||
|  | 		if (itemToEdit) { | ||||||
|  | 			itemToEdit->applyEdition(mtpMessage.c_message()); | ||||||
|  | 		} else { | ||||||
|  | 			history->addNewMessage(mtpMessage, NewMessageUnread); | ||||||
|  | 		} | ||||||
| 	} else if (file->type == SendMediaType::Audio) { | 	} else if (file->type == SendMediaType::Audio) { | ||||||
| 		if (!peer->isChannel() || peer->isMegagroup()) { | 		if (!peer->isChannel() || peer->isMegagroup()) { | ||||||
| 			flags |= MTPDmessage::Flag::f_media_unread; | 			flags |= MTPDmessage::Flag::f_media_unread; | ||||||
| 		} | 		} | ||||||
| 		auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0; | 		const auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0; | ||||||
| 		auto document = MTP_messageMediaDocument( | 		const auto document = MTP_messageMediaDocument( | ||||||
| 			MTP_flags(documentFlags), | 			MTP_flags(documentFlags), | ||||||
| 			file->document, | 			file->document, | ||||||
| 			MTPint()); | 			MTPint()); | ||||||
|  | @ -4378,7 +4385,8 @@ void HistoryWidget::sendFileConfirmed( | ||||||
| 				MTPint(), | 				MTPint(), | ||||||
| 				MTP_string(messagePostAuthor), | 				MTP_string(messagePostAuthor), | ||||||
| 				MTP_long(groupId)), | 				MTP_long(groupId)), | ||||||
| 			messageType); | 			NewMessageUnread); | ||||||
|  | 		// Voices can't be edited.
 | ||||||
| 	} else { | 	} else { | ||||||
| 		Unexpected("Type in sendFilesConfirmed."); | 		Unexpected("Type in sendFilesConfirmed."); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue