blob: 3def2afedfb1707aa93cc9709c2ab3dd28785146 [file] [log] [blame]
Nicolas Jager8a85e1f2016-08-15 15:11:06 -04001/**************************************************************************
2* Copyright (C) 2016 by Savoir-faire Linux *
3* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
4* *
5* This program is free software; you can redistribute it and/or modify *
6* it under the terms of the GNU General Public License as published by *
7* the Free Software Foundation; either version 3 of the License, or *
8* (at your option) any later version. *
9* *
10* This program is distributed in the hope that it will be useful, *
11* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13* GNU General Public License for more details. *
14* *
15* You should have received a copy of the GNU General Public License *
16* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17**************************************************************************/
18#include "pch.h"
19
20#include "ContactsViewModel.h"
21#include "MainPage.xaml.h"
22
23#include "MessageTextPage.xaml.h"
24
25using namespace RingClientUWP::Views;
26using namespace RingClientUWP::ViewModel;
27
28using namespace Platform;
29using namespace Windows::Foundation;
30using namespace Windows::Foundation::Collections;
31using namespace Windows::UI::Xaml;
32using namespace Windows::UI::Xaml::Controls;
33using namespace Windows::UI::Xaml::Controls::Primitives;
34using namespace Windows::UI::Xaml::Data;
35using namespace Windows::UI::Xaml::Documents;
36using namespace Windows::UI::Xaml::Input;
37using namespace Windows::UI::Xaml::Media;
38using namespace Windows::UI::Xaml::Navigation;
39
40MessageTextPage::MessageTextPage()
41{
42 InitializeComponent();
Nicolas Jager93abfea2016-08-30 12:33:07 -040043
44 /* connect delegates. */ // may be useless
45 RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
46 String^ from, String^ payload) {
47 });
48
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040049}
50
51void
52RingClientUWP::Views::MessageTextPage::OnNavigatedTo(NavigationEventArgs ^ e)
53{
54 updatePageContent();
55}
56
57void
58RingClientUWP::Views::MessageTextPage::updatePageContent()
59{
60 auto contact = ContactsViewModel::instance->selectedContact;
61 if (!contact)
62 return;
63
64 _title_->Text = contact->name_;
65
Nicolas Jager93abfea2016-08-30 12:33:07 -040066 _messagesList_->ItemsSource = contact->_conversation->_messages;
67
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040068}
69
70void
71RingClientUWP::Views::MessageTextPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
72{
73 sendMessage();
74}
75
76void
77RingClientUWP::Views::MessageTextPage::_messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
78{
79 if (e->Key == Windows::System::VirtualKey::Enter) {
80 sendMessage();
81 }
82}
83
84void
85RingClientUWP::Views::MessageTextPage::sendMessage()
86{
87 auto contact = ContactsViewModel::instance->selectedContact;
88 auto txt = _messageTextBox_->Text;
89
90 /* empty the textbox */
91 _messageTextBox_->Text = "";
92
93 if (!contact || txt->IsEmpty())
94 return;
95
96}