Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit e3858b1

Browse files
committed
added sending message
1 parent bbec8a1 commit e3858b1

12 files changed

+174
-22
lines changed

App.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
</configSections>
88
<userSettings>
99
<CherryMerryGram.cherrymerrygram_config>
10-
<setting name="appId" serializeAs="String">
11-
<value />
12-
</setting>
1310
</CherryMerryGram.cherrymerrygram_config>
1411
</userSettings>
1512
</configuration>

CherryMerryGram.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
<ItemGroup>
2121
<None Remove="Views\AccountView.xaml" />
2222
<None Remove="Views\ChatsView.xaml" />
23+
<None Remove="Views\Chats\Chat.xaml" />
2324
<None Remove="Views\Chats\ChatEntry.xaml" />
25+
<None Remove="Views\Chats\ChatMessage.xaml" />
2426
<None Remove="Views\HelpView.xaml" />
2527
<None Remove="Views\LoginView.xaml" />
2628
<None Remove="Views\SettingsView.xaml" />
@@ -52,6 +54,16 @@
5254
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
5355
<ProjectCapability Include="Msix" />
5456
</ItemGroup>
57+
<ItemGroup>
58+
<Page Update="Views\Chats\ChatMessage.xaml">
59+
<Generator>MSBuild:Compile</Generator>
60+
</Page>
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Page Update="Views\Chats\Chat.xaml">
64+
<Generator>MSBuild:Compile</Generator>
65+
</Page>
66+
</ItemGroup>
5567
<ItemGroup>
5668
<Page Update="Views\LoginView.xaml">
5769
<Generator>MSBuild:Compile</Generator>

MainWindow.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ private static async Task ProcessUpdates(TdApi.Update update)
5151
var filesLocation = Path.Combine(AppContext.BaseDirectory, "db");
5252
await _client.ExecuteAsync(new TdApi.SetTdlibParameters
5353
{
54-
ApiId = _config.ApiId,
55-
ApiHash = _config.ApiHash,
54+
ApiId = Config.Config.ApiId,
55+
ApiHash = Config.Config.ApiHash,
5656
DeviceModel = "PC",
5757
SystemLanguageCode = "en",
58-
ApplicationVersion = _config.ApplicationVersion,
58+
ApplicationVersion = Config.Config.ApplicationVersion,
5959
DatabaseDirectory = filesLocation,
6060
FilesDirectory = filesLocation,
6161
});

Views/AccountView.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace CherryMerryGram.Views
88
public sealed partial class AccountView : Page
99
{
1010
private static readonly TdClient _client = MainWindow._client;
11-
private static MainWindow _app;
1211

1312
private string _displayName;
1413
private string _username;
@@ -17,8 +16,6 @@ public sealed partial class AccountView : Page
1716
public AccountView()
1817
{
1918
this.InitializeComponent();
20-
21-
//_app = new MainWindow();
2219

2320
InitializeAllVariables();
2421
}
@@ -42,7 +39,6 @@ private async void InitializeAllVariables()
4239
private async void Button_LogOut_OnClick(object sender, RoutedEventArgs e)
4340
{
4441
await _client.ExecuteAsync(new TdApi.LogOut());
45-
_app.UpdateWindow();
4642
}
4743
}
4844
}

Views/Chats/Chat.xaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Page
3+
x:Class="CherryMerryGram.Views.Chats.Chat"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:CherryMerryGram.Views.Chats"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d"
10+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11+
12+
<StackPanel>
13+
<StackPanel x:Name="TopBar" Orientation="Horizontal" VerticalAlignment="Top">
14+
<TextBlock x:Name="ChatTitle" />
15+
</StackPanel>
16+
<ListView x:Name="MessagesList" />
17+
<StackPanel x:Name="UserActionsPanel" Orientation="Horizontal" VerticalAlignment="Bottom">
18+
<TextBox x:Name="UserMessageInput" PlaceholderText="Enter your message"/>
19+
<Button x:Name="Stickers" Content="Stickers" Width="70" MaxHeight="25" MaxWidth="25" />
20+
<Button x:Name="SendMessage" Content="Send" Width="70" MaxHeight="25" MaxWidth="25" Click="SendMessage_OnClick" />
21+
</StackPanel>
22+
</StackPanel>
23+
</Page>

Views/Chats/Chat.xaml.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
using System.Collections.Generic;
3+
using TdLib;
4+
using Microsoft.UI.Xaml;
5+
6+
namespace CherryMerryGram.Views.Chats
7+
{
8+
public sealed partial class Chat : Page
9+
{
10+
private static TdClient _client = MainWindow._client;
11+
private static long ChatId;
12+
13+
public Chat()
14+
{
15+
this.InitializeComponent();
16+
}
17+
18+
public async void UpdateChat(long chatId, string Title)
19+
{
20+
ChatId = chatId;
21+
var chat = _client.GetChatAsync(chatId: chatId);
22+
ChatTitle.Text = chat.Result.Title;
23+
24+
var messages = GetMessages();
25+
26+
await foreach (var message in messages)
27+
{
28+
var messageEntry = new ChatMessage();
29+
messageEntry.UpdateMessage(message: message);
30+
MessagesList.Items.Add(messageEntry);
31+
}
32+
}
33+
34+
private static async IAsyncEnumerable<TdApi.Messages> GetMessages()
35+
{
36+
var messages = await _client.ExecuteAsync(new TdApi.GetChatHistory
37+
{
38+
ChatId = ChatId,
39+
FromMessageId = 0,
40+
Offset = 0,
41+
Limit = 100
42+
});
43+
44+
foreach (var message in messages.Messages_)
45+
{
46+
yield return message;
47+
}
48+
}
49+
50+
private async void SendMessage_OnClick(object sender, RoutedEventArgs e)
51+
{
52+
await _client.ExecuteAsync(new TdApi.SendMessage
53+
{
54+
ChatId = ChatId,
55+
InputMessageContent = new TdApi.InputMessageContent.InputMessageText
56+
{
57+
Text = new TdApi.FormattedText
58+
{
59+
Text = UserMessageInput.Text
60+
}
61+
}
62+
});
63+
}
64+
}
65+
}

Views/Chats/ChatEntry.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
mc:Ignorable="d"
1010
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
1111

12-
<StackPanel>
13-
<TextBlock x:Name="textBlock_ChatName" Text="ChatName" />
14-
<TextBlock x:Name="textBlock_ChatId" Text="ChatId" />
15-
</StackPanel>
12+
<Button Width="250px" MaxWidth="490px" MaxHeight="50px" Click="ButtonBase_OnClick">
13+
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Center">
14+
<TextBlock x:Name="textBlock_Chat_NameAndId" Text="ChatName (chatId)" />
15+
<TextBlock x:Name="textBlock_Chat_LastMessage" Text="LastMessage" />
16+
</StackPanel>
17+
</Button>
1618
</Page>

Views/Chats/ChatEntry.xaml.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
1+
using Microsoft.UI.Xaml;
12
using Microsoft.UI.Xaml.Controls;
3+
using TdLib;
4+
using WinRT;
25

36
namespace CherryMerryGram.Views.Chats
47
{
58
public sealed partial class ChatEntry : Page
69
{
10+
public ListView ChatPage;
11+
private static Chat _chat;
12+
13+
private long ChatId;
14+
private string ChatTitle;
15+
716
public ChatEntry()
817
{
918
this.InitializeComponent();
1019
}
1120

12-
public void UpdateChat(int chatId, string chatName)
21+
public void UpdateChat(long chatId, string chatName, TdApi.Message chatLastMessage )
22+
{
23+
ChatId = chatId;
24+
ChatTitle = chatName;
25+
textBlock_Chat_NameAndId.Text = $"{chatName} ({chatId})";
26+
textBlock_Chat_LastMessage.Text = chatLastMessage.Content.ToString();
27+
}
28+
29+
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
1330
{
14-
textBlock_ChatId.Text = chatId.ToString();
15-
textBlock_ChatName.Text = chatName;
31+
if (ChatPage != null && _chat != null)
32+
{
33+
ChatPage.Items.Remove(_chat);
34+
_chat = null;
35+
}
36+
37+
_chat = new Chat();
38+
ChatPage.Items.Add(_chat);
39+
_chat.UpdateChat(ChatId, ChatTitle);
1640
}
1741
}
1842
}

Views/Chats/ChatMessage.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Page
3+
x:Class="CherryMerryGram.Views.Chats.ChatMessage"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:local="using:CherryMerryGram.Views.Chats"
7+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d"
10+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
11+
12+
<StackPanel Orientation="Vertical">
13+
<TextBlock x:Name="Username" Text="@username" />
14+
</StackPanel>
15+
</Page>

Views/Chats/ChatMessage.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
using TdLib;
3+
4+
namespace CherryMerryGram.Views.Chats
5+
{
6+
public sealed partial class ChatMessage : Page
7+
{
8+
public ChatMessage()
9+
{
10+
this.InitializeComponent();
11+
}
12+
13+
public void UpdateMessage(TdApi.Message message)
14+
{
15+
Username.Text = message.AuthorSignature;
16+
}
17+
}
18+
}

Views/ChatsView.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
1111

1212
<StackPanel Orientation="Horizontal">
13-
<ListView x:Name="ChatList" Width="250px">
14-
</ListView>
13+
<ListView x:Name="ChatsList" Width="500px" />
14+
<ListView x:Name="Chat" />
1515
</StackPanel>
1616
</Page>

Views/ChatsView.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ private async void GenerateChatEntries()
2525
await foreach (var chat in chats)
2626
{
2727
var chatEntry = new ChatEntry();
28-
int chatId = unchecked((int)chat.Id);
29-
chatEntry.UpdateChat(chatId, chat.Title);
30-
ChatList.Items.Add(chatEntry);
28+
chatEntry.UpdateChat(chat.Id, chat.Title, chat.LastMessage);
29+
chatEntry.ChatPage = Chat;
30+
ChatsList.Items.Add(chatEntry);
3131
}
3232
}
3333

0 commit comments

Comments
 (0)