This repository was archived by the owner on Oct 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 12 files changed +174
-22
lines changed Expand file tree Collapse file tree 12 files changed +174
-22
lines changed Original file line number Diff line number Diff line change 7
7
</configSections >
8
8
<userSettings >
9
9
<CherryMerryGram .cherrymerrygram_config>
10
- <setting name =" appId" serializeAs =" String" >
11
- <value />
12
- </setting >
13
10
</CherryMerryGram .cherrymerrygram_config>
14
11
</userSettings >
15
12
</configuration >
Original file line number Diff line number Diff line change 20
20
<ItemGroup >
21
21
<None Remove =" Views\AccountView.xaml" />
22
22
<None Remove =" Views\ChatsView.xaml" />
23
+ <None Remove =" Views\Chats\Chat.xaml" />
23
24
<None Remove =" Views\Chats\ChatEntry.xaml" />
25
+ <None Remove =" Views\Chats\ChatMessage.xaml" />
24
26
<None Remove =" Views\HelpView.xaml" />
25
27
<None Remove =" Views\LoginView.xaml" />
26
28
<None Remove =" Views\SettingsView.xaml" />
52
54
<ItemGroup Condition =" '$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'" >
53
55
<ProjectCapability Include =" Msix" />
54
56
</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 >
55
67
<ItemGroup >
56
68
<Page Update =" Views\LoginView.xaml" >
57
69
<Generator >MSBuild:Compile</Generator >
Original file line number Diff line number Diff line change @@ -51,11 +51,11 @@ private static async Task ProcessUpdates(TdApi.Update update)
51
51
var filesLocation = Path . Combine ( AppContext . BaseDirectory , "db" ) ;
52
52
await _client . ExecuteAsync ( new TdApi . SetTdlibParameters
53
53
{
54
- ApiId = _config . ApiId ,
55
- ApiHash = _config . ApiHash ,
54
+ ApiId = Config . Config . ApiId ,
55
+ ApiHash = Config . Config . ApiHash ,
56
56
DeviceModel = "PC" ,
57
57
SystemLanguageCode = "en" ,
58
- ApplicationVersion = _config . ApplicationVersion ,
58
+ ApplicationVersion = Config . Config . ApplicationVersion ,
59
59
DatabaseDirectory = filesLocation ,
60
60
FilesDirectory = filesLocation ,
61
61
} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ namespace CherryMerryGram.Views
8
8
public sealed partial class AccountView : Page
9
9
{
10
10
private static readonly TdClient _client = MainWindow . _client ;
11
- private static MainWindow _app ;
12
11
13
12
private string _displayName ;
14
13
private string _username ;
@@ -17,8 +16,6 @@ public sealed partial class AccountView : Page
17
16
public AccountView ( )
18
17
{
19
18
this . InitializeComponent ( ) ;
20
-
21
- //_app = new MainWindow();
22
19
23
20
InitializeAllVariables ( ) ;
24
21
}
@@ -42,7 +39,6 @@ private async void InitializeAllVariables()
42
39
private async void Button_LogOut_OnClick ( object sender , RoutedEventArgs e )
43
40
{
44
41
await _client . ExecuteAsync ( new TdApi . LogOut ( ) ) ;
45
- _app . UpdateWindow ( ) ;
46
42
}
47
43
}
48
44
}
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 9
9
mc : Ignorable =" d"
10
10
Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}" >
11
11
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 >
16
18
</Page >
Original file line number Diff line number Diff line change
1
+ using Microsoft . UI . Xaml ;
1
2
using Microsoft . UI . Xaml . Controls ;
3
+ using TdLib ;
4
+ using WinRT ;
2
5
3
6
namespace CherryMerryGram . Views . Chats
4
7
{
5
8
public sealed partial class ChatEntry : Page
6
9
{
10
+ public ListView ChatPage ;
11
+ private static Chat _chat ;
12
+
13
+ private long ChatId ;
14
+ private string ChatTitle ;
15
+
7
16
public ChatEntry ( )
8
17
{
9
18
this . InitializeComponent ( ) ;
10
19
}
11
20
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 )
13
30
{
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 ) ;
16
40
}
17
41
}
18
42
}
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 10
10
Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}" >
11
11
12
12
<StackPanel Orientation =" Horizontal" >
13
- <ListView x : Name =" ChatList " Width =" 250px " >
14
- </ ListView >
13
+ <ListView x : Name =" ChatsList " Width =" 500px " / >
14
+ <ListView x : Name = " Chat " / >
15
15
</StackPanel >
16
16
</Page >
Original file line number Diff line number Diff line change @@ -25,9 +25,9 @@ private async void GenerateChatEntries()
25
25
await foreach ( var chat in chats )
26
26
{
27
27
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 ) ;
31
31
}
32
32
}
33
33
You can’t perform that action at this time.
0 commit comments