This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbec8a1
commit e3858b1
Showing
12 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Page | ||
x:Class="CherryMerryGram.Views.Chats.Chat" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:CherryMerryGram.Views.Chats" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<StackPanel> | ||
<StackPanel x:Name="TopBar" Orientation="Horizontal" VerticalAlignment="Top"> | ||
<TextBlock x:Name="ChatTitle" /> | ||
</StackPanel> | ||
<ListView x:Name="MessagesList" /> | ||
<StackPanel x:Name="UserActionsPanel" Orientation="Horizontal" VerticalAlignment="Bottom"> | ||
<TextBox x:Name="UserMessageInput" PlaceholderText="Enter your message"/> | ||
<Button x:Name="Stickers" Content="Stickers" Width="70" MaxHeight="25" MaxWidth="25" /> | ||
<Button x:Name="SendMessage" Content="Send" Width="70" MaxHeight="25" MaxWidth="25" Click="SendMessage_OnClick" /> | ||
</StackPanel> | ||
</StackPanel> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Microsoft.UI.Xaml.Controls; | ||
using System.Collections.Generic; | ||
using TdLib; | ||
using Microsoft.UI.Xaml; | ||
|
||
namespace CherryMerryGram.Views.Chats | ||
{ | ||
public sealed partial class Chat : Page | ||
{ | ||
private static TdClient _client = MainWindow._client; | ||
private static long ChatId; | ||
|
||
public Chat() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
public async void UpdateChat(long chatId, string Title) | ||
{ | ||
ChatId = chatId; | ||
var chat = _client.GetChatAsync(chatId: chatId); | ||
ChatTitle.Text = chat.Result.Title; | ||
|
||
var messages = GetMessages(); | ||
|
||
await foreach (var message in messages) | ||
{ | ||
var messageEntry = new ChatMessage(); | ||
messageEntry.UpdateMessage(message: message); | ||
MessagesList.Items.Add(messageEntry); | ||
} | ||
} | ||
|
||
private static async IAsyncEnumerable<TdApi.Messages> GetMessages() | ||
{ | ||
var messages = await _client.ExecuteAsync(new TdApi.GetChatHistory | ||
{ | ||
ChatId = ChatId, | ||
FromMessageId = 0, | ||
Offset = 0, | ||
Limit = 100 | ||
}); | ||
|
||
foreach (var message in messages.Messages_) | ||
{ | ||
yield return message; | ||
} | ||
} | ||
|
||
private async void SendMessage_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
await _client.ExecuteAsync(new TdApi.SendMessage | ||
{ | ||
ChatId = ChatId, | ||
InputMessageContent = new TdApi.InputMessageContent.InputMessageText | ||
{ | ||
Text = new TdApi.FormattedText | ||
{ | ||
Text = UserMessageInput.Text | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,42 @@ | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using TdLib; | ||
using WinRT; | ||
|
||
namespace CherryMerryGram.Views.Chats | ||
{ | ||
public sealed partial class ChatEntry : Page | ||
{ | ||
public ListView ChatPage; | ||
private static Chat _chat; | ||
|
||
private long ChatId; | ||
private string ChatTitle; | ||
|
||
public ChatEntry() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
public void UpdateChat(int chatId, string chatName) | ||
public void UpdateChat(long chatId, string chatName, TdApi.Message chatLastMessage ) | ||
{ | ||
ChatId = chatId; | ||
ChatTitle = chatName; | ||
textBlock_Chat_NameAndId.Text = $"{chatName} ({chatId})"; | ||
textBlock_Chat_LastMessage.Text = chatLastMessage.Content.ToString(); | ||
} | ||
|
||
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
textBlock_ChatId.Text = chatId.ToString(); | ||
textBlock_ChatName.Text = chatName; | ||
if (ChatPage != null && _chat != null) | ||
{ | ||
ChatPage.Items.Remove(_chat); | ||
_chat = null; | ||
} | ||
|
||
_chat = new Chat(); | ||
ChatPage.Items.Add(_chat); | ||
_chat.UpdateChat(ChatId, ChatTitle); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Page | ||
x:Class="CherryMerryGram.Views.Chats.ChatMessage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:CherryMerryGram.Views.Chats" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<StackPanel Orientation="Vertical"> | ||
<TextBlock x:Name="Username" Text="@username" /> | ||
</StackPanel> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.UI.Xaml.Controls; | ||
using TdLib; | ||
|
||
namespace CherryMerryGram.Views.Chats | ||
{ | ||
public sealed partial class ChatMessage : Page | ||
{ | ||
public ChatMessage() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
public void UpdateMessage(TdApi.Message message) | ||
{ | ||
Username.Text = message.AuthorSignature; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters