From d8e22fd135af1aaec4f1f60bc766b87d51e05da5 Mon Sep 17 00:00:00 2001 From: Nicolas Jager <nicolas.jager@savoirfairelinux.com> Date: Sun, 30 Oct 2016 09:41:10 -0400 Subject: [PATCH] contact : associating accountId used to connecting with - set the account Id to connect with the contact, and store the data in contacts.json Change-Id: I059cf6352a3492d59473fe759bc260e983336c23 Tuleap: #1281 --- Contact.cpp | 3 +++ Contact.h | 2 ++ ContactsViewModel.cpp | 4 ++++ MessageTextPage.xaml | 15 +++++++++++++++ MessageTextPage.xaml.cpp | 38 +++++++++++++++++++++++++++++++++++++- MessageTextPage.xaml.h | 2 ++ RingD.cpp | 12 +++++++++++- SmartPanel.xaml.cpp | 2 ++ 8 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Contact.cpp b/Contact.cpp index 5b06a12..50c142c 100644 --- a/Contact.cpp +++ b/Contact.cpp @@ -65,6 +65,8 @@ Contact::Contact(String^ name, notificationNewMessage = Windows::UI::Xaml::Visibility::Visible; NotifyPropertyChanged("unreadMessages"); } + + _accountIdAssociated = ""; } void @@ -87,6 +89,7 @@ Contact::ToJsonObject() contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_)); contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_)); contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_)); + contactObject->SetNamedValue(accountIdAssociatedKey, JsonValue::CreateStringValue(_accountIdAssociated)); JsonObject^ jsonObject = ref new JsonObject(); jsonObject->SetNamedValue(contactKey, contactObject); diff --git a/Contact.h b/Contact.h index 524697c..aa2671d 100644 --- a/Contact.h +++ b/Contact.h @@ -29,6 +29,7 @@ String^ GUIDKey = "guid"; String^ unreadMessagesKey = "unreadmessages"; String^ contactKey = "contact"; String^ contactListKey = "contactlist"; +String^ accountIdAssociatedKey = "accountIdAssociated"; namespace RingClientUWP { @@ -88,6 +89,7 @@ public: NotifyPropertyChanged("_contactBarHeight"); } } + property String^ _accountIdAssociated; internal: void saveConversationToFile(); diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 554073f..f19f44f 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -149,6 +149,7 @@ ContactsViewModel::Destringify(String^ data) String^ ringid; String^ guid; unsigned int unreadmessages; + String^ accountIdAssociated; JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray()); for (unsigned int i = 0; i < contactlist->Size; i++) { @@ -161,8 +162,11 @@ ContactsViewModel::Destringify(String^ data) ringid = contactObject->GetNamedString(ringIDKey); guid = contactObject->GetNamedString(GUIDKey); unreadmessages = static_cast<uint16_t>(contactObject->GetNamedNumber(unreadMessagesKey)); + accountIdAssociated = contactObject->GetNamedString(accountIdAssociatedKey); + } auto contact = ref new Contact(name, ringid, guid, unreadmessages); + contact->_accountIdAssociated = accountIdAssociated; contactsList_->Append(contact); contactAdded(contact); } diff --git a/MessageTextPage.xaml b/MessageTextPage.xaml index 2e9271e..3435963 100644 --- a/MessageTextPage.xaml +++ b/MessageTextPage.xaml @@ -107,6 +107,12 @@ </Setter.Value> </Setter> </Style> + <DataTemplate x:Key="_AssociableAccountsListDataTemplate_" + x:DataType="local:Account"> + <Grid> + <TextBlock Text="{x:Bind name_}"/> + </Grid> + </DataTemplate> </Page.Resources> <Grid Background="#FFF2F2F2"> @@ -128,6 +134,15 @@ VerticalAlignment="Center" FontSize="20" Margin="20,0" /> + <ComboBox x:Name="_associableAccountsList_"> + <ComboBox.ItemTemplate> + <DataTemplate x:DataType="local:Account"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{x:Bind name_, Mode=OneWay}" /> + </StackPanel> + </DataTemplate> + </ComboBox.ItemTemplate> + </ComboBox> </StackPanel> </StackPanel> diff --git a/MessageTextPage.xaml.cpp b/MessageTextPage.xaml.cpp index 6f8d60a..e018cbd 100644 --- a/MessageTextPage.xaml.cpp +++ b/MessageTextPage.xaml.cpp @@ -44,6 +44,10 @@ MessageTextPage::MessageTextPage() { InitializeComponent(); + /* bind the source to account only able to be used to contact the contact */ + _associableAccountsList_->ItemsSource = AccountsViewModel::instance->accountsList; + _associableAccountsList_->SelectionChanged += ref new Windows::UI::Xaml::Controls::SelectionChangedEventHandler(this, &RingClientUWP::Views::MessageTextPage::OnSelectionChanged); + /* connect to delegates */ RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId, String^ fromRingId, String^ payload) { @@ -59,14 +63,39 @@ RingClientUWP::Views::MessageTextPage::updatePageContent() auto item = SmartPanelItemsViewModel::instance->_selectedItem; auto contact = item->_contact; - if (!contact) + + + if (!contact) /* should never happen */ return; + + /* show the name of contact on the page */ _title_->Text = contact->name_; + /* show messages */ _messagesList_->ItemsSource = contact->_conversation->_messages; + /* select the associated accountId stored with the contact */ + auto accountIdAssociated = contact->_accountIdAssociated; + auto list = AccountsViewModel::instance->accountsList; + unsigned int index = 0; + bool found = true; + + for (auto item : list) + if (item->accountID_ == accountIdAssociated) { + found = list->IndexOf(item, &index); + break; + } + + + if (found) + _associableAccountsList_->SelectedIndex = index; + else + ERR_("mismatch between accountIdAssociated and associable accounts!"); + + /* scroll to the last message on the page*/ scrollDown(); + } void RingClientUWP::Views::MessageTextPage::scrollDown() @@ -143,3 +172,10 @@ void RingClientUWP::Views::MessageTextPage::OnincomingMessage(Platform::String ^ { scrollDown(); } + + +void RingClientUWP::Views::MessageTextPage::OnSelectionChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^e) +{ + auto account = dynamic_cast<Account^>(_associableAccountsList_->SelectedItem); + SmartPanelItemsViewModel::instance->_selectedItem->_contact->_accountIdAssociated = account->accountID_; +} \ No newline at end of file diff --git a/MessageTextPage.xaml.h b/MessageTextPage.xaml.h index 1edbd73..8b90277 100644 --- a/MessageTextPage.xaml.h +++ b/MessageTextPage.xaml.h @@ -50,6 +50,8 @@ private: void _messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); void sendMessage(); void OnincomingMessage(Platform::String ^callId, Platform::String ^payload); + void OnSelectionChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^e); + }; } } diff --git a/RingD.cpp b/RingD.cpp index 16e79b9..5ba2219 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -233,7 +233,16 @@ void RingClientUWP::RingD::placeCall(Contact^ contact) { MSG_("!--->> placeCall"); auto to = contact->ringID_; - auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_; + String^ accountId; + + if (contact->_accountIdAssociated->IsEmpty()) { + accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_; + MSG_("adding account id to contact"); + contact->_accountIdAssociated = accountId; + } + else { + accountId = contact->_accountIdAssociated; + } auto to2 = Utils::toString(to); auto accountId2 = Utils::toString(accountId); @@ -845,6 +854,7 @@ RingClientUWP::CallStatus RingClientUWP::RingD::translateCallStatus(String^ stat if (state == "CONNECTING") return CallStatus::SEARCHING; + return CallStatus::NONE; } diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 34f9116..5d83d32 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -94,6 +94,8 @@ SmartPanel::SmartPanel() return; } + contact->_accountIdAssociated = accountId; + auto item = SmartPanelItemsViewModel::instance->findItem(contact); item->_callId = callId; -- GitLab