Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 1 | /**************************************************************************
|
| 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 |
|
| 25 | using namespace RingClientUWP::Views;
|
| 26 | using namespace RingClientUWP::ViewModel;
|
| 27 |
|
| 28 | using namespace Platform;
|
| 29 | using namespace Windows::Foundation;
|
| 30 | using namespace Windows::Foundation::Collections;
|
| 31 | using namespace Windows::UI::Xaml;
|
| 32 | using namespace Windows::UI::Xaml::Controls;
|
| 33 | using namespace Windows::UI::Xaml::Controls::Primitives;
|
| 34 | using namespace Windows::UI::Xaml::Data;
|
| 35 | using namespace Windows::UI::Xaml::Documents;
|
| 36 | using namespace Windows::UI::Xaml::Input;
|
| 37 | using namespace Windows::UI::Xaml::Media;
|
| 38 | using namespace Windows::UI::Xaml::Navigation;
|
| 39 |
|
| 40 | MessageTextPage::MessageTextPage()
|
| 41 | {
|
| 42 | InitializeComponent();
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 43 |
|
| 44 | /* connect delegates. */ // may be useless
|
| 45 | RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
|
| 46 | String^ from, String^ payload) {
|
| 47 | });
|
| 48 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 49 | }
|
| 50 |
|
| 51 | void
|
| 52 | RingClientUWP::Views::MessageTextPage::OnNavigatedTo(NavigationEventArgs ^ e)
|
| 53 | {
|
| 54 | updatePageContent();
|
| 55 | }
|
| 56 |
|
| 57 | void
|
| 58 | RingClientUWP::Views::MessageTextPage::updatePageContent()
|
| 59 | {
|
| 60 | auto contact = ContactsViewModel::instance->selectedContact;
|
| 61 | if (!contact)
|
| 62 | return;
|
| 63 |
|
| 64 | _title_->Text = contact->name_;
|
| 65 |
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 66 | _messagesList_->ItemsSource = contact->_conversation->_messages;
|
| 67 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 68 | }
|
| 69 |
|
| 70 | void
|
| 71 | RingClientUWP::Views::MessageTextPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 72 | {
|
| 73 | sendMessage();
|
| 74 | }
|
| 75 |
|
| 76 | void
|
| 77 | RingClientUWP::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 |
|
| 84 | void
|
| 85 | RingClientUWP::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 |
|
Nicolas Jager | 655df54 | 2016-08-31 10:24:47 -0400 | [diff] [blame^] | 96 | RingD::instance->sendAccountTextMessage(txt);
|
| 97 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 98 | }
|