| 671 | } |
| 672 | |
| 673 | QString InterpretSendPath( |
| 674 | not_null<Window::SessionController*> window, |
| 675 | const QString &path) { |
| 676 | QFile f(path); |
| 677 | if (!f.open(QIODevice::ReadOnly)) { |
| 678 | return "App Error: Could not open interpret file: " + path; |
| 679 | } |
| 680 | const auto content = QString::fromUtf8(f.readAll()); |
| 681 | f.close(); |
| 682 | const auto lines = content.split('\n'); |
| 683 | auto toId = PeerId(0); |
| 684 | auto topicRootId = MsgId(0); |
| 685 | auto filePath = QString(); |
| 686 | auto caption = QString(); |
| 687 | for (const auto &line : lines) { |
| 688 | if (line.startsWith(u"from: "_q)) { |
| 689 | if (window->session().userId().bare |
| 690 | != base::StringViewMid( |
| 691 | line, |
| 692 | u"from: "_q.size()).toULongLong()) { |
| 693 | return "App Error: Wrong current user."; |
| 694 | } |
| 695 | } else if (line.startsWith(u"channel: "_q)) { |
| 696 | const auto channelId = base::StringViewMid( |
| 697 | line, |
| 698 | u"channel: "_q.size()).toULongLong(); |
| 699 | toId = peerFromChannel(channelId); |
| 700 | } else if (line.startsWith(u"topic: "_q)) { |
| 701 | const auto topicId = base::StringViewMid( |
| 702 | line, |
| 703 | u"topic: "_q.size()).toULongLong(); |
| 704 | topicRootId = MsgId(topicId); |
| 705 | } else if (line.startsWith(u"file: "_q)) { |
| 706 | const auto path = line.mid(u"file: "_q.size()); |
| 707 | if (!QFile(path).exists()) { |
| 708 | return "App Error: Could not find file with path: " + path; |
| 709 | } |
| 710 | filePath = path; |
| 711 | } else if (line.startsWith(u"caption: "_q)) { |
| 712 | caption = line.mid(u"caption: "_q.size()); |
| 713 | } else if (!caption.isEmpty()) { |
| 714 | caption += '\n' + line; |
| 715 | } else { |
| 716 | return "App Error: Invalid command: " + line; |
| 717 | } |
| 718 | } |
| 719 | const auto history = window->session().data().historyLoaded(toId); |
| 720 | const auto sendTo = [=](not_null<Data::Thread*> thread) { |
| 721 | window->showThread(thread); |
| 722 | const auto premium = thread->session().user()->isPremium(); |
| 723 | auto list = Storage::PrepareMediaList( |
| 724 | QStringList(filePath), |
| 725 | st::sendMediaPreviewSize, |
| 726 | premium); |
| 727 | if (!list.files.empty()) { |
| 728 | list.files.back().caption.text = caption; |
| 729 | thread->session().api().sendFiles( |
| 730 | std::move(list), |
no test coverage detected