Skip to content

Commit

Permalink
Set emoji status
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed Nov 7, 2024
1 parent 140233c commit 8ad9b39
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Telegram/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public static IEnumerable<AlternativeVideo> FindAlternatives(this GalleryMedia v

public static int GetNamedInt32(this JsonObject obj, string name, int defaultValue)
{
return (int)obj.GetNamedNumber(name);
return (int)obj.GetNamedNumber(name, defaultValue);
}

public static bool HasExtension(this IStorageFile file, params string[] extensions)
Expand Down
22 changes: 21 additions & 1 deletion Telegram/Strings/en/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// <auto-generatedInfo>
// This code was generated by TdParseOptions (http://github.com/UnigramDev/UnigramUtils/)
//
// Generated: 11/04/2024 23:44:32
// Generated: 11/05/2024 17:16:33
// </auto-generatedInfo>
// --------------------------------------------------------------------------------------------------
namespace Telegram
Expand Down Expand Up @@ -3200,6 +3200,26 @@ public static class R
/// </summary>
public static string BotEditIntro => Resource.GetString("BotEditIntro");

/// <summary>
/// Localized resource similar to "Confirm"
/// </summary>
public static string BotEmojiStatusConfirm => Resource.GetString("BotEmojiStatusConfirm");

/// <summary>
/// Localized resource similar to "Do you want to set this emoji status suggested by **{0}**?"
/// </summary>
public static string BotEmojiStatusText => Resource.GetString("BotEmojiStatusText");

/// <summary>
/// Localized resource similar to "Do you want to set this emoji status suggested by **{0}** for {1}?"
/// </summary>
public static string BotEmojiStatusTextFor => Resource.GetString("BotEmojiStatusTextFor");

/// <summary>
/// Localized resource similar to "Set Emoji Status"
/// </summary>
public static string BotEmojiStatusTitle => Resource.GetString("BotEmojiStatusTitle");

/// <summary>
/// Localized resource similar to "Help"
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions Telegram/Strings/en/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,18 @@ from **{0}**.</value>
<data name="BotEditIntro" xml:space="preserve">
<value>Edit Intro</value>
</data>
<data name="BotEmojiStatusConfirm" xml:space="preserve">
<value>Confirm</value>
</data>
<data name="BotEmojiStatusText" xml:space="preserve">
<value>Do you want to set this emoji status suggested by **{0}**?</value>
</data>
<data name="BotEmojiStatusTextFor" xml:space="preserve">
<value>Do you want to set this emoji status suggested by **{0}** for {1}?</value>
</data>
<data name="BotEmojiStatusTitle" xml:space="preserve">
<value>Set Emoji Status</value>
</data>
<data name="BotHelp" xml:space="preserve">
<value>Help</value>
</data>
Expand Down
7 changes: 7 additions & 0 deletions Telegram/Telegram.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@
<Compile Include="Views\Popups\ChooseDateTimeToast.xaml.cs">
<DependentUpon>ChooseDateTimeToast.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Popups\EmojiStatusPopup.xaml.cs">
<DependentUpon>EmojiStatusPopup.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Premium\Popups\ChangePrivacyPopup.xaml.cs">
<DependentUpon>ChangePrivacyPopup.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -3087,6 +3090,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Popups\EmojiStatusPopup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Premium\Popups\ChangePrivacyPopup.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
101 changes: 101 additions & 0 deletions Telegram/Views/Popups/EmojiStatusPopup.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<controls:ContentPopup x:Class="Telegram.Views.Popups.EmojiStatusPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:controls="using:Telegram.Controls"
mc:Ignorable="d"
Padding="24,0,24,24"
IsDismissButtonVisible="True">

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Margin="0,24,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:AnimatedImage x:Name="Animated"
Width="120"
Height="120"
FrameSize="120,120"
DecodeFrameType="Logical"
IsViewportAware="True"
LoopCount="1"
Margin="0,-16,0,8" />

<TextBlock x:Name="Title"
Text="{CustomResource BotEmojiStatusTitle}"
Style="{StaticResource PopupTextBlockStyle}"
TextAlignment="Center"
VerticalAlignment="Top"
Grid.Row="1" />
<TextBlock x:Name="Subtitle"
Style="{StaticResource BodyTextBlockStyle}"
TextAlignment="Center"
Margin="12,0,12,24"
Grid.Row="2" />

<Grid Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="1"
HorizontalAlignment="Center"
CornerRadius="14"
Margin="0,0,0,24"
Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<controls:ProfilePicture x:Name="Photo"
Width="28"
Height="28" />

<TextBlock x:Name="TitleText"
Style="{StaticResource BodyTextBlockStyle}"
FontFamily="{ThemeResource EmojiThemeFontFamily}"
VerticalAlignment="Center"
Margin="8,1,4,3"
Grid.Column="1" />

<controls:CustomEmojiIcon x:Name="Status"
Margin="0,0,8,0"
Grid.Column="2" />
</Grid>

</Grid>

<Grid x:Name="PurchasePanel"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Grid.Row="1">
<controls:BadgeButton x:Name="PurchaseCommand"
Click="Purchase_Click"
Style="{StaticResource AccentButtonStyle}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
FontWeight="SemiBold"
BorderThickness="1"
Height="32">
<Grid>
<TextBlock x:Name="PurchaseText"
Text="{CustomResource BotEmojiStatusConfirm}"
VerticalAlignment="Center"
Margin="0,3,0,5" />
<muxc:ProgressRing x:Name="PurchaseRing"
Visibility="Collapsed"
Foreground="#FFFFFF"
Width="20"
Height="20" />
</Grid>
</controls:BadgeButton>
</Grid>
</Grid>
</controls:ContentPopup>
121 changes: 121 additions & 0 deletions Telegram/Views/Popups/EmojiStatusPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// Copyright Fela Ameghino 2015-2024
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using System;
using Telegram.Common;
using Telegram.Controls;
using Telegram.Controls.Media;
using Telegram.Converters;
using Telegram.Navigation;
using Telegram.Navigation.Services;
using Telegram.Services;
using Telegram.Streams;
using Telegram.Td.Api;
using Telegram.Views.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Media;

namespace Telegram.Views.Popups
{
public sealed partial class EmojiStatusPopup : ContentPopup
{
private readonly IClientService _clientService;
private readonly INavigationService _navigationService;

private readonly StarTransaction _transaction;

private readonly long _customEmojiId;
private readonly int _expirationDate;

private readonly UserGift _gift;

public EmojiStatusPopup(IClientService clientService, INavigationService navigationService, long sourceUserId, Sticker sticker, int expirationDate)
{
InitializeComponent();

_clientService = clientService;
_navigationService = navigationService;

if (sticker.FullType is StickerFullTypeCustomEmoji customEmoji)
{
_customEmojiId = customEmoji.CustomEmojiId;
_expirationDate = expirationDate;
}

Animated.Source = new DelayedFileSource(clientService, sticker);
Status.Source = new DelayedFileSource(clientService, sticker);

if (clientService.TryGetUser(sourceUserId, out User user))
{
var diff = expirationDate - DateTime.Now.ToTimestamp();
if (diff > 0)
{
TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.BotEmojiStatusTextFor, user.FirstName, Locale.FormatTtl(diff)));
}
else
{
TextBlockHelper.SetMarkdown(Subtitle, string.Format(Strings.BotEmojiStatusText, user.FirstName));
}
}

if (clientService.TryGetUser(clientService.Options.MyId, out User self))
{
Photo.SetUser(clientService, self, 28);
TitleText.Text = self.FullName();
}
}

private bool _submitted;

private async void Purchase_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (_submitted)
{
return;
}

_submitted = true;

PurchaseRing.Visibility = Windows.UI.Xaml.Visibility.Visible;

var visual1 = ElementComposition.GetElementVisual(PurchaseText);
var visual2 = ElementComposition.GetElementVisual(PurchaseRing);

ElementCompositionPreview.SetIsTranslationEnabled(PurchaseText, true);
ElementCompositionPreview.SetIsTranslationEnabled(PurchaseRing, true);

var translate1 = visual1.Compositor.CreateScalarKeyFrameAnimation();
translate1.InsertKeyFrame(0, 0);
translate1.InsertKeyFrame(1, -32);

var translate2 = visual1.Compositor.CreateScalarKeyFrameAnimation();
translate2.InsertKeyFrame(0, 32);
translate2.InsertKeyFrame(1, 0);

visual1.StartAnimation("Translation.Y", translate1);
visual2.StartAnimation("Translation.Y", translate2);

//await Task.Delay(2000);

if (_clientService.IsPremium)
{
var result = await _clientService.SendAsync(new SetEmojiStatus(new EmojiStatus(_customEmojiId, _expirationDate)));
Hide(result is Ok
? ContentDialogResult.Primary
: ContentDialogResult.Secondary);
}
else
{
Hide();
_navigationService.ShowPromo(new PremiumSourceFeature(new PremiumFeatureEmojiStatus()));
}
//ViewModel.Submit();
}
}
}
Loading

0 comments on commit 8ad9b39

Please sign in to comment.