Skip to content

Commit

Permalink
Improve updates build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 18, 2023
1 parent a2fe91a commit c765c41
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
42 changes: 31 additions & 11 deletions Telegram/SourceFiles/support/support_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ For license and copyright information please follow this link:

#include "dialogs/dialogs_key.h"
#include "data/data_drafts.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "data/data_changes.h"
Expand Down Expand Up @@ -555,6 +557,7 @@ QString InterpretSendPath(
f.close();
const auto lines = content.split('\n');
auto toId = PeerId(0);
auto topicRootId = MsgId(0);
auto filePath = QString();
auto caption = QString();
for (const auto &line : lines) {
Expand All @@ -570,6 +573,11 @@ QString InterpretSendPath(
line,
u"channel: "_q.size()).toULongLong();
toId = peerFromChannel(channelId);
} else if (line.startsWith(u"topic: "_q)) {
const auto topicId = base::StringViewMid(
line,
u"topic: "_q.size()).toULongLong();
topicRootId = MsgId(topicId);
} else if (line.startsWith(u"file: "_q)) {
const auto path = line.mid(u"file: "_q.size());
if (!QFile(path).exists()) {
Expand All @@ -585,21 +593,33 @@ QString InterpretSendPath(
}
}
const auto history = window->session().data().historyLoaded(toId);
const auto sendTo = [=](not_null<Data::Thread*> thread) {
window->showThread(thread);
const auto premium = thread->session().user()->isPremium();
thread->session().api().sendFiles(
Storage::PrepareMediaList(
QStringList(filePath),
st::sendMediaPreviewSize,
premium),
SendMediaType::File,
{ caption },
nullptr,
Api::SendAction(thread));
};
if (!history) {
return "App Error: Could not find channel with id: "
+ QString::number(peerToChannel(toId).bare);
} else if (const auto forum = history->asForum()) {
forum->requestTopic(topicRootId, [=] {
if (const auto forum = history->asForum()) {
if (const auto topic = forum->topicFor(topicRootId)) {
sendTo(topic);
}
}
});
} else if (!topicRootId) {
sendTo(history);
}
window->showPeerHistory(history);
const auto premium = window->session().user()->isPremium();
history->session().api().sendFiles(
Storage::PrepareMediaList(
QStringList(filePath),
st::sendMediaPreviewSize,
premium),
SendMediaType::File,
{ caption },
nullptr,
Api::SendAction(history));
return QString();
}

Expand Down
19 changes: 11 additions & 8 deletions Telegram/build/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
nextUuid = False
building = True
composing = False
conf = 'Release'
for arg in sys.argv:
if nextLast:
lastCommit = arg
Expand All @@ -32,6 +33,8 @@
nextDate = True
elif arg == 'request_uuid':
nextUuid = True
elif arg == 'debug':
conf = 'Debug'

def finish(code, error = ''):
if error != '':
Expand All @@ -53,9 +56,9 @@ def finish(code, error = ''):
archive = 'tdesktop_macOS_' + today + '.zip'

if building:
print('Building Release version for OS X 10.12+..')
print('Building ' + conf + ' version for OS X 10.12+..')

if os.path.exists('../out/Release/' + outputFolder):
if os.path.exists('../out/' + conf + '/' + outputFolder):
finish(1, 'Todays updates version exists.')

if uuid == '':
Expand All @@ -65,11 +68,11 @@ def finish(code, error = ''):

os.chdir('../out')
if uuid == '':
result = subprocess.call('cmake --build . --config Release --target Telegram', shell=True)
result = subprocess.call('cmake --build . --config ' + conf + ' --target Telegram', shell=True)
if result != 0:
finish(1, 'While building Telegram.')

os.chdir('Release')
os.chdir(conf);
if uuid == '':
if not os.path.exists('Telegram.app'):
finish(1, 'Telegram.app not found.')
Expand Down Expand Up @@ -193,7 +196,7 @@ def finish(code, error = ''):
print('NB! Notarization log not found.')
finish(0)

commandPath = scriptPath + '/../../out/Release/' + outputFolder + '/command.txt'
commandPath = scriptPath + '/../../out/' + conf + '/' + outputFolder + '/command.txt'

if composing:
templatePath = scriptPath + '/../../../DesktopPrivate/updates_template.txt'
Expand Down Expand Up @@ -235,7 +238,7 @@ def finish(code, error = ''):
for line in template:
if line.startswith('//'):
continue
line = line.replace('{path}', scriptPath + '/../../out/Release/' + outputFolder + '/' + archive)
line = line.replace('{path}', scriptPath + '/../../out/' + conf + '/' + outputFolder + '/' + archive)
line = line.replace('{caption}', 'TDesktop at ' + today.replace('_', '.') + ':\n\n' + changelog)
f.write(line)
print('\n\nEdit:\n')
Expand All @@ -262,9 +265,9 @@ def finish(code, error = ''):
print('vi ' + commandPath)
finish(1, 'Too large.')

if not os.path.exists('../out/Release/' + outputFolder + '/' + archive):
if not os.path.exists('../out/' + conf + '/' + outputFolder + '/' + archive):
finish(1, 'Not built yet.')

subprocess.call(scriptPath + '/../../out/Release/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/Release/' + outputFolder + '/command.txt', shell=True)
subprocess.call(scriptPath + '/../../out/' + conf + '/Telegram.app/Contents/MacOS/Telegram -sendpath interpret://' + scriptPath + '/../../out/' + conf + '/' + outputFolder + '/command.txt', shell=True)

finish(0)

0 comments on commit c765c41

Please sign in to comment.