diff --git a/Contact.cpp b/Contact.cpp index 5b06a12493637ac63c905ff8d7f6f48f48372a59..50c142cf6e3254b1dd25fa7002303138f6822878 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 524697ccfef614f14c1493b5fa84b507bc2daece..aa2671d62486a91ce89d05f795a1c8b47575dca3 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 554073fe18cfe2059b4b2224f34edc63191ee0e8..f19f44fc4524986bae42c3806ee808bc1c202fdc 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 2e9271e7df67a5c41fda269213208efce33a49ac..3435963cd41ff20d5199596d2594474b57c15b6c 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 6f8d60a78dc153e30dd8d1d2b040da673922511a..e018cbdbead68f773d5a00e54c021aec20ab32b5 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 1edbd739581ca78d7d08f913e45dc665c2cc1ce7..8b902776009cda45dfe6c700c9ea6d82423aeb55 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 16e79b90768713252793dbadc17f51d1eb0d8195..5ba2219e4559b9997b119e88e0c95b44ccbf7aa2 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 34f911638f4325bb0f67e263c91cfeca313b7aca..5d83d3239a1120e1c2048fd7647536cb8e03a90f 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;