From abaff46d69da2fbbbaa844329bf2694f5b1f6962 Mon Sep 17 00:00:00 2001
From: John <johnz@posteo.net>
Date: Sat, 6 Jul 2019 17:43:20 +0200
Subject: [PATCH 1/2] telegram-desktop: update to 1.7.14.

---
 srcpkgs/telegram-desktop/files/Telegram.cmake |   8 +-
 .../files/ThirdParty-qtlottie.cmake           |  42 -----
 ...-Qt-color-API-only-in-official-build.patch | 175 ++++++++++++++++++
 .../0002-remove-execinfo-include.patch        |  12 ++
 srcpkgs/telegram-desktop/template             |  28 +--
 5 files changed, 202 insertions(+), 63 deletions(-)
 delete mode 100644 srcpkgs/telegram-desktop/files/ThirdParty-qtlottie.cmake
 create mode 100644 srcpkgs/telegram-desktop/patches/0001-Use-private-Qt-color-API-only-in-official-build.patch
 create mode 100644 srcpkgs/telegram-desktop/patches/0002-remove-execinfo-include.patch

diff --git a/srcpkgs/telegram-desktop/files/Telegram.cmake b/srcpkgs/telegram-desktop/files/Telegram.cmake
index 3cc9dd1ca32..cd08360ebfb 100644
--- a/srcpkgs/telegram-desktop/files/Telegram.cmake
+++ b/srcpkgs/telegram-desktop/files/Telegram.cmake
@@ -46,6 +46,8 @@ pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libavutil libswresample
 pkg_check_modules(LIBDRM REQUIRED libdrm)
 pkg_check_modules(LIBVA REQUIRED libva libva-drm libva-x11)
 pkg_check_modules(MINIZIP REQUIRED minizip)
+pkg_check_modules(LIBLZ4 REQUIRED liblz4)
+pkg_check_modules(RLOTTIE REQUIRED rlottie)
 
 set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/ThirdParty)
 list(APPEND THIRD_PARTY_INCLUDE_DIRS
@@ -58,7 +60,6 @@ list(APPEND THIRD_PARTY_INCLUDE_DIRS
 
 add_subdirectory(${THIRD_PARTY_DIR}/crl)
 add_subdirectory(${THIRD_PARTY_DIR}/libtgvoip)
-add_subdirectory(${THIRD_PARTY_DIR}/qtlottie)
 
 set(TELEGRAM_SOURCES_DIR ${CMAKE_SOURCE_DIR}/SourceFiles)
 set(TELEGRAM_RESOURCES_DIR ${CMAKE_SOURCE_DIR}/Resources)
@@ -92,9 +93,11 @@ file(GLOB FLAT_SOURCE_FILES
 	SourceFiles/core/*.cpp
 	SourceFiles/data/*.cpp
 	SourceFiles/dialogs/*.cpp
+	SourceFiles/ffmpeg/*.cpp
 	SourceFiles/inline_bots/*.cpp
 	SourceFiles/intro/*.cpp
 	SourceFiles/lang/*.cpp
+	SourceFiles/lottie/*.cpp
 	SourceFiles/main/*.cpp
 	SourceFiles/mtproto/*.cpp
 	SourceFiles/overview/*.cpp
@@ -161,7 +164,6 @@ set(TELEGRAM_INCLUDE_DIRS
 set(TELEGRAM_LINK_LIBRARIES
 	xxhash
 	crl
-	qtlottie
 	tgvoip
 	OpenSSL::Crypto
 	OpenSSL::SSL
@@ -177,6 +179,8 @@ set(TELEGRAM_LINK_LIBRARIES
 	${OPENAL_LIBRARY}
 	${X11_X11_LIB}
 	${ZLIB_LIBRARY_RELEASE}
+	${LIBLZ4_LIBRARIES}
+	${RLOTTIE_LIBRARIES}
 )
 
 if(ENABLE_CRASH_REPORTS)
diff --git a/srcpkgs/telegram-desktop/files/ThirdParty-qtlottie.cmake b/srcpkgs/telegram-desktop/files/ThirdParty-qtlottie.cmake
deleted file mode 100644
index ac8494b5993..00000000000
--- a/srcpkgs/telegram-desktop/files/ThirdParty-qtlottie.cmake
+++ /dev/null
@@ -1,42 +0,0 @@
-project(qtlottie)
-
-set(CMAKE_CXX_STANDARD 17)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-list(APPEND CMAKE_MODULE_PATH
-	${CMAKE_SOURCE_DIR}/gyp
-)
-
-find_package(Qt5 REQUIRED COMPONENTS Core Gui)
-
-foreach(__qt_module IN ITEMS QtCore QtGui)
-	list(APPEND QT_PRIVATE_INCLUDE_DIRS
-		${QT_INCLUDE_DIR}/${__qt_module}/${Qt5_VERSION}
-		${QT_INCLUDE_DIR}/${__qt_module}/${Qt5_VERSION}/${__qt_module}
-	)
-endforeach()
-
-file(GLOB QTLOTTIE_SOURCE_FILES
-	src/bodymovin/*.cpp
-	src/imports/rasterrenderer/rasterrenderer.cpp
-	../../SourceFiles/lottie/*.cpp
-)
-
-add_library(${PROJECT_NAME} STATIC ${QTLOTTIE_SOURCE_FILES})
-
-include(PrecompiledHeader)
-add_precompiled_header(${PROJECT_NAME} ../../SourceFiles/lottie/lottie_pch.h)
-
-target_include_directories(${PROJECT_NAME} PUBLIC
-	src
-	src/bodymovin
-	src/imports
-	${CMAKE_SOURCE_DIR}/SourceFiles
-	${CMAKE_SOURCE_DIR}/ThirdParty/GSL/include
-	${CMAKE_SOURCE_DIR}/ThirdParty/variant/include
-	${QT_PRIVATE_INCLUDE_DIRS}
-)
-set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC_MOC_OPTIONS -bqtlottie_pch/lottie_pch.h)
-target_compile_definitions(${PROJECT_NAME} PUBLIC BODYMOVIN_LIBRARY)
-target_link_libraries(${PROJECT_NAME} crl Qt5::Core Qt5::Widgets)
diff --git a/srcpkgs/telegram-desktop/patches/0001-Use-private-Qt-color-API-only-in-official-build.patch b/srcpkgs/telegram-desktop/patches/0001-Use-private-Qt-color-API-only-in-official-build.patch
new file mode 100644
index 00000000000..5e8a93f96f4
--- /dev/null
+++ b/srcpkgs/telegram-desktop/patches/0001-Use-private-Qt-color-API-only-in-official-build.patch
@@ -0,0 +1,175 @@
+From 0710dde4d5526454318b2748331e887c01ecfdce Mon Sep 17 00:00:00 2001
+From: John Preston <johnprestonmail@gmail.com>
+Date: Tue, 9 Jul 2019 13:43:57 +0200
+Subject: [PATCH 1/2] Use private Qt color API only in official build.
+
+Fixes #6219.
+---
+ .../SourceFiles/ffmpeg/ffmpeg_utility.cpp     | 100 ++++++++++++------
+ Telegram/gyp/lib_ffmpeg.gyp                   |   6 +-
+ 2 files changed, 71 insertions(+), 35 deletions(-)
+
+diff --git Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
+index 5d0e50926..3775f7503 100644
+--- Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
++++ Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
+@@ -11,7 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
+ #include "logs.h"
+ 
+ #include <QImage>
++
++#ifdef TDESKTOP_OFFICIAL_TARGET
+ #include <private/qdrawhelper_p.h>
++#endif // TDESKTOP_OFFICIAL_TARGET
+ 
+ extern "C" {
+ #include <libavutil/opt.h>
+@@ -44,6 +47,58 @@ void AlignedImageBufferCleanupHandler(void* data) {
+ 		&& !(image.bytesPerLine() % kAlignImageBy);
+ }
+ 
++void UnPremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
++#ifdef TDESKTOP_OFFICIAL_TARGET
++	const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
++	const auto convert = layout->convertFromARGB32PM;
++#else // TDESKTOP_OFFICIAL_TARGET
++	const auto layout = nullptr;
++	const auto convert = [](
++			uint *dst,
++			const uint *src,
++			int count,
++			std::nullptr_t,
++			std::nullptr_t) {
++		for (auto i = 0; i != count; ++i) {
++			dst[i] = qUnpremultiply(src[i]);
++		}
++	};
++#endif // TDESKTOP_OFFICIAL_TARGET
++
++	convert(
++		reinterpret_cast<uint*>(dst),
++		reinterpret_cast<const uint*>(src),
++		intsCount,
++		layout,
++		nullptr);
++}
++
++void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
++#ifdef TDESKTOP_OFFICIAL_TARGET
++	const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
++	const auto convert = layout->convertToARGB32PM;
++#else // TDESKTOP_OFFICIAL_TARGET
++	const auto layout = nullptr;
++	const auto convert = [](
++			uint *dst,
++			const uint *src,
++			int count,
++			std::nullptr_t,
++			std::nullptr_t) {
++		for (auto i = 0; i != count; ++i) {
++			dst[i] = qPremultiply(src[i]);
++		}
++	};
++#endif // TDESKTOP_OFFICIAL_TARGET
++
++	convert(
++		reinterpret_cast<uint*>(dst),
++		reinterpret_cast<const uint*>(src),
++		intsCount,
++		layout,
++		nullptr);
++}
++
+ } // namespace
+ 
+ IOPointer MakeIOPointer(
+@@ -360,58 +415,35 @@ void UnPremultiply(QImage &to, const QImage &from) {
+ 	if (!GoodStorageForFrame(to, from.size())) {
+ 		to = CreateFrameStorage(from.size());
+ 	}
+-
+-	const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
+-	const auto convert = layout->convertFromARGB32PM;
+ 	const auto fromPerLine = from.bytesPerLine();
+ 	const auto toPerLine = to.bytesPerLine();
+ 	const auto width = from.width();
++	const auto height = from.height();
++	auto fromBytes = from.bits();
++	auto toBytes = to.bits();
+ 	if (fromPerLine != width * 4 || toPerLine != width * 4) {
+-		auto fromBytes = from.bits();
+-		auto toBytes = to.bits();
+-		for (auto i = 0; i != to.height(); ++i) {
+-			convert(
+-				reinterpret_cast<uint*>(toBytes),
+-				reinterpret_cast<const uint*>(fromBytes),
+-				width,
+-				layout,
+-				nullptr);
++		for (auto i = 0; i != height; ++i) {
++			UnPremultiplyLine(toBytes, fromBytes, width);
+ 			fromBytes += fromPerLine;
+ 			toBytes += toPerLine;
+ 		}
+ 	} else {
+-		convert(
+-			reinterpret_cast<uint*>(to.bits()),
+-			reinterpret_cast<const uint*>(from.bits()),
+-			from.width() * from.height(),
+-			layout,
+-			nullptr);
++		UnPremultiplyLine(toBytes, fromBytes, width * height);
+ 	}
+ }
+ 
+ void PremultiplyInplace(QImage &image) {
+-	const auto layout = &qPixelLayouts[QImage::Format_ARGB32];
+-	const auto convert = layout->convertToARGB32PM;
+ 	const auto perLine = image.bytesPerLine();
+ 	const auto width = image.width();
++	const auto height = image.height();
++	auto bytes = image.bits();
+ 	if (perLine != width * 4) {
+-		auto bytes = image.bits();
+-		for (auto i = 0; i != image.height(); ++i) {
+-			convert(
+-				reinterpret_cast<uint*>(bytes),
+-				reinterpret_cast<const uint*>(bytes),
+-				width,
+-				layout,
+-				nullptr);
++		for (auto i = 0; i != height; ++i) {
++			PremultiplyLine(bytes, bytes, width);
+ 			bytes += perLine;
+ 		}
+ 	} else {
+-		convert(
+-			reinterpret_cast<uint*>(image.bits()),
+-			reinterpret_cast<const uint*>(image.bits()),
+-			image.width() * image.height(),
+-			layout,
+-			nullptr);
++		PremultiplyLine(bytes, bytes, width * height);
+ 	}
+ }
+ 
+diff --git Telegram/gyp/lib_ffmpeg.gyp Telegram/gyp/lib_ffmpeg.gyp
+index 9971d76ae..b9ada5362 100644
+--- Telegram/gyp/lib_ffmpeg.gyp
++++ Telegram/gyp/lib_ffmpeg.gyp
+@@ -46,7 +46,11 @@
+       '<(src_loc)/ffmpeg/ffmpeg_utility.cpp',
+       '<(src_loc)/ffmpeg/ffmpeg_utility.h',
+     ],
+-    'conditions': [[ 'build_macold', {
++    'conditions': [[ '"<(official_build_target)" != ""', {
++      'defines': [
++        'TDESKTOP_OFFICIAL_TARGET=<(official_build_target)',
++      ],
++    }], [ 'build_macold', {
+       'xcode_settings': {
+         'OTHER_CPLUSPLUSFLAGS': [ '-nostdinc++' ],
+       },
+-- 
+2.22.0
+
diff --git a/srcpkgs/telegram-desktop/patches/0002-remove-execinfo-include.patch b/srcpkgs/telegram-desktop/patches/0002-remove-execinfo-include.patch
new file mode 100644
index 00000000000..700f0e65cbd
--- /dev/null
+++ b/srcpkgs/telegram-desktop/patches/0002-remove-execinfo-include.patch
@@ -0,0 +1,12 @@
+diff --git Telegram/SourceFiles/platform/linux/specific_linux.h Telegram/SourceFiles/platform/linux/specific_linux.h
+index 14485149e..9af2a64c0 100644
+--- Telegram/SourceFiles/platform/linux/specific_linux.h
++++ Telegram/SourceFiles/platform/linux/specific_linux.h
+@@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
+ 
+ #include "platform/platform_specific.h"
+ 
+-#include <execinfo.h>
+ #include <signal.h>
+ 
+ namespace Data {
diff --git a/srcpkgs/telegram-desktop/template b/srcpkgs/telegram-desktop/template
index 53e3eab8354..f1443933130 100644
--- a/srcpkgs/telegram-desktop/template
+++ b/srcpkgs/telegram-desktop/template
@@ -1,13 +1,12 @@
 # Template file for 'telegram-desktop'
 pkgname=telegram-desktop
-version=1.7.10
+version=1.7.14
 revision=1
-_libtgvoip_commit=a19a0aff644127d8089f6a4ac18119ec5247dbd0
+_libtgvoip_commit=0e92a22746d15157bea46faddd61b79e9964275a
 _GSL_commit=d846fe50a3f0bb7767c7e087a05f4be95f4da0ec
 _variant_commit=550ac2f159ca883d360c196149b466955c77a573
-_crl_commit=d259aebc11df52cb6ff8c738580dc4d8f245d681
+_crl_commit=9ea870038a2a667add7f621be6252db909068386
 _Catch_commit=5ca44b68721833ae3731802ed99af67c6f38a53a
-_qtlottie_commit=eeeb4edb2a087c3f8175dafafcad330864d3efc0
 wrksrc="tdesktop-${version}"
 build_wrksrc="Telegram"
 build_style=cmake
@@ -18,7 +17,7 @@ hostmakedepends="pkg-config qt5-qmake qt5-host-tools python"
 makedepends="alsa-lib-devel ffmpeg-devel gtk+3-devel libappindicator-devel
  libdbusmenu-glib-devel libopenal-devel minizip-devel opus-devel xxHash-devel
  $(vopt_if pulseaudio 'pulseaudio-devel') qt5-devel range-v3 libva-devel
- rapidjson"
+ rapidjson liblz4-devel rlottie-devel"
 depends="qt5-imageformats qt5>=5.11.3<5.11.4"
 short_desc="Telegram Desktop messaging app"
 maintainer="John <johnz@posteo.net>"
@@ -30,15 +29,13 @@ distfiles="https://github.com/telegramdesktop/tdesktop/archive/v${version}.tar.g
  https://github.com/Microsoft/GSL/archive/${_GSL_commit}.tar.gz
  https://github.com/mapbox/variant/archive/${_variant_commit}.tar.gz
  https://github.com/telegramdesktop/crl/archive/${_crl_commit}.tar.gz
- https://github.com/catchorg/Catch2/archive/${_Catch_commit}.tar.gz
- https://github.com/telegramdesktop/qtlottie/archive/${_qtlottie_commit}.tar.gz"
-checksum="54032b9dd864424eac2a1a95f3f4254666fc99745b90be10195eb10052ed5d67
- d839ab5a3358e171116b322e0053f441e023c9ced9aec3f0388969c2fce7ac43
+ https://github.com/catchorg/Catch2/archive/${_Catch_commit}.tar.gz"
+checksum="a52ab6efb4dc7579f05543df3fc3814baa09c0644e00ca30e37a9c6f99a5d164
+ ee45011d0eda61f188d9f7f077efa64551913c2c7e7250b40f3c7c3a330cd5cc
  be81db4ab1b57102a0fa1cd0c4a6469294eb9daf24294347592245b754f65ff6
  aa794dfefe0a90501587e36d977b958d0df888503117a8d9aa43dc14f8526d9d
- f5ea3aeeda0290a44ac49b6300b033d171e67a5b27039fea2f8ae0cb3fc71253
- d24e6d9df2b8aa5739d3b9077c6b0ff0ef4d5ef8acc52c3a57e32893854d8d18
- 7084bceb5644a3bb07266d03a645bb66feba19eb840616e3db395036d845c0bb"
+ 5844fbd5647c1605d8f7b1391e583e484054884cc1a71681e3abeb153b8ec5b4
+ d24e6d9df2b8aa5739d3b9077c6b0ff0ef4d5ef8acc52c3a57e32893854d8d18"
 
 build_options="clang pulseaudio"
 build_options_default="pulseaudio"
@@ -59,10 +56,6 @@ case $XBPS_TARGET_MACHINE in
 	mips*) broken="unsupported";;
 esac
 
-case $XBPS_TARGET_MACHINE in
-	*-musl) makedepends+=" libexecinfo-devel" ;;
-esac
-
 case "$XBPS_TARGET_MACHINE" in
 	arm*|mips*)
 		makedepends+=" libatomic-devel"
@@ -94,15 +87,12 @@ post_extract() {
 	mv ../crl-${_crl_commit} ${wrksrc}/${build_wrksrc}/ThirdParty/crl
 	rmdir ${wrksrc}/${build_wrksrc}/ThirdParty/Catch
 	mv ../Catch2-${_Catch_commit} ${wrksrc}/${build_wrksrc}/ThirdParty/Catch
-	rmdir ${wrksrc}/${build_wrksrc}/ThirdParty/qtlottie
-	mv ../qtlottie-${_qtlottie_commit} ${wrksrc}/${build_wrksrc}/ThirdParty/qtlottie
 
 	cp ${FILESDIR}/Telegram.cmake ${build_wrksrc}/CMakeLists.txt
 	cp ${FILESDIR}/ThirdParty-crl.cmake ${build_wrksrc}/ThirdParty/crl/CMakeLists.txt
 	cp ${FILESDIR}/ThirdParty-libtgvoip.cmake ${build_wrksrc}/ThirdParty/libtgvoip/CMakeLists.txt
 	cp ${FILESDIR}/ThirdParty-libtgvoip-webrtc.cmake \
 		${build_wrksrc}/ThirdParty/libtgvoip/webrtc_dsp/CMakeLists.txt
-	cp ${FILESDIR}/ThirdParty-qtlottie.cmake ${build_wrksrc}/ThirdParty/qtlottie/CMakeLists.txt
 
 	mkdir -p ${build_wrksrc}/cmake
 	cp ${FILESDIR}/FindBreakpad.cmake ${build_wrksrc}/cmake

From ad35e90994d2dffa3719d8f2bbae0cf36bb8828c Mon Sep 17 00:00:00 2001
From: John <johnz@posteo.net>
Date: Tue, 9 Jul 2019 20:16:27 +0200
Subject: [PATCH 2/2] New package: rlottie-0.0.20160709

---
 common/shlibs            |  1 +
 srcpkgs/rlottie-devel    |  1 +
 srcpkgs/rlottie/template | 30 ++++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
 create mode 120000 srcpkgs/rlottie-devel
 create mode 100644 srcpkgs/rlottie/template

diff --git a/common/shlibs b/common/shlibs
index 8778f7b818e..7629d868216 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -3476,6 +3476,7 @@ libgtk-4.so.0.9400.0 gtk4-3.94.0_1
 libmodule.so.4 libmodule-4.1.0_1
 libgnustep-gui.so.0.27 gnustep-gui-0.27.0_1
 libmhash.so.2 mhash-0.9.9.9_1
+librlottie.so.0 rlottie-0.0.20160709_1
 libfstrm.so.0 fstrm-0.5.0_1
 libknot.so.9 libknot-2.8.2_1
 libdnssec.so.7 libknot-2.8.2_1
diff --git a/srcpkgs/rlottie-devel b/srcpkgs/rlottie-devel
new file mode 120000
index 00000000000..9a74e44f789
--- /dev/null
+++ b/srcpkgs/rlottie-devel
@@ -0,0 +1 @@
+rlottie
\ No newline at end of file
diff --git a/srcpkgs/rlottie/template b/srcpkgs/rlottie/template
new file mode 100644
index 00000000000..774b5074352
--- /dev/null
+++ b/srcpkgs/rlottie/template
@@ -0,0 +1,30 @@
+# Template file for 'rlottie'
+pkgname=rlottie
+_commit=9be18fbd4047467495af5bd6d83f5b91bc063ea2
+version=0.0.20160709
+revision=1
+wrksrc="rlottie-${_commit}"
+build_style=cmake
+short_desc="Platform independent standalone library that plays Lottie Animation"
+maintainer="John <johnz@posteo.net>"
+license="LGPL-2.1-or-later, FTL, MIT, JSON, BSD-3-Clause"
+homepage="https://github.com/Samsung/rlottie"
+distfiles="https://github.com/Samsung/rlottie/archive/${_commit}.tar.gz"
+checksum=d34b3f6acc224a494fae7f2c6c9c231f26652ee50d1493f12a577ce33eff21d3
+
+post_install() {
+	vlicense licenses/COPYING.PIX
+	vlicense licenses/COPYING.RPD
+	vlicense licenses/COPYING.STB
+}
+
+rlottie-devel_package() {
+	depends="${sourcepkg}>=${version}_${revision}"
+	short_desc+=" - development files"
+	pkg_install() {
+		vmove usr/include
+		vmove usr/lib/cmake
+		vmove usr/lib/pkgconfig
+		vmove usr/lib/librlottie.so
+	}
+}
