Commit d8e22fd1 authored by Nicolas Jager's avatar Nicolas Jager
Browse files

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
parent 4115278f
...@@ -65,6 +65,8 @@ Contact::Contact(String^ name, ...@@ -65,6 +65,8 @@ Contact::Contact(String^ name,
notificationNewMessage = Windows::UI::Xaml::Visibility::Visible; notificationNewMessage = Windows::UI::Xaml::Visibility::Visible;
NotifyPropertyChanged("unreadMessages"); NotifyPropertyChanged("unreadMessages");
} }
_accountIdAssociated = "";
} }
void void
...@@ -87,6 +89,7 @@ Contact::ToJsonObject() ...@@ -87,6 +89,7 @@ Contact::ToJsonObject()
contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_)); contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_));
contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_)); contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_));
contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_)); contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_));
contactObject->SetNamedValue(accountIdAssociatedKey, JsonValue::CreateStringValue(_accountIdAssociated));
JsonObject^ jsonObject = ref new JsonObject(); JsonObject^ jsonObject = ref new JsonObject();
jsonObject->SetNamedValue(contactKey, contactObject); jsonObject->SetNamedValue(contactKey, contactObject);
......
...@@ -29,6 +29,7 @@ String^ GUIDKey = "guid"; ...@@ -29,6 +29,7 @@ String^ GUIDKey = "guid";
String^ unreadMessagesKey = "unreadmessages"; String^ unreadMessagesKey = "unreadmessages";
String^ contactKey = "contact"; String^ contactKey = "contact";
String^ contactListKey = "contactlist"; String^ contactListKey = "contactlist";
String^ accountIdAssociatedKey = "accountIdAssociated";
namespace RingClientUWP namespace RingClientUWP
{ {
...@@ -88,6 +89,7 @@ public: ...@@ -88,6 +89,7 @@ public:
NotifyPropertyChanged("_contactBarHeight"); NotifyPropertyChanged("_contactBarHeight");
} }
} }
property String^ _accountIdAssociated;
internal: internal:
void saveConversationToFile(); void saveConversationToFile();
......
...@@ -149,6 +149,7 @@ ContactsViewModel::Destringify(String^ data) ...@@ -149,6 +149,7 @@ ContactsViewModel::Destringify(String^ data)
String^ ringid; String^ ringid;
String^ guid; String^ guid;
unsigned int unreadmessages; unsigned int unreadmessages;
String^ accountIdAssociated;
JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray()); JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray());
for (unsigned int i = 0; i < contactlist->Size; i++) { for (unsigned int i = 0; i < contactlist->Size; i++) {
...@@ -161,8 +162,11 @@ ContactsViewModel::Destringify(String^ data) ...@@ -161,8 +162,11 @@ ContactsViewModel::Destringify(String^ data)
ringid = contactObject->GetNamedString(ringIDKey); ringid = contactObject->GetNamedString(ringIDKey);
guid = contactObject->GetNamedString(GUIDKey); guid = contactObject->GetNamedString(GUIDKey);
unreadmessages = static_cast<uint16_t>(contactObject->GetNamedNumber(unreadMessagesKey)); unreadmessages = static_cast<uint16_t>(contactObject->GetNamedNumber(unreadMessagesKey));
accountIdAssociated = contactObject->GetNamedString(accountIdAssociatedKey);
} }
auto contact = ref new Contact(name, ringid, guid, unreadmessages); auto contact = ref new Contact(name, ringid, guid, unreadmessages);
contact->_accountIdAssociated = accountIdAssociated;
contactsList_->Append(contact); contactsList_->Append(contact);
contactAdded(contact); contactAdded(contact);
} }
......
...@@ -107,6 +107,12 @@ ...@@ -107,6 +107,12 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<DataTemplate x:Key="_AssociableAccountsListDataTemplate_"
x:DataType="local:Account">
<Grid>
<TextBlock Text="{x:Bind name_}"/>
</Grid>
</DataTemplate>
</Page.Resources> </Page.Resources>
<Grid Background="#FFF2F2F2"> <Grid Background="#FFF2F2F2">
...@@ -128,6 +134,15 @@ ...@@ -128,6 +134,15 @@
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="20" FontSize="20"
Margin="20,0" /> 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>
</StackPanel> </StackPanel>
......
...@@ -44,6 +44,10 @@ MessageTextPage::MessageTextPage() ...@@ -44,6 +44,10 @@ MessageTextPage::MessageTextPage()
{ {
InitializeComponent(); 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 */ /* connect to delegates */
RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId, RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
String^ fromRingId, String^ payload) { String^ fromRingId, String^ payload) {
...@@ -59,14 +63,39 @@ RingClientUWP::Views::MessageTextPage::updatePageContent() ...@@ -59,14 +63,39 @@ RingClientUWP::Views::MessageTextPage::updatePageContent()
auto item = SmartPanelItemsViewModel::instance->_selectedItem; auto item = SmartPanelItemsViewModel::instance->_selectedItem;
auto contact = item->_contact; auto contact = item->_contact;
if (!contact)
if (!contact) /* should never happen */
return; return;
/* show the name of contact on the page */
_title_->Text = contact->name_; _title_->Text = contact->name_;
/* show messages */
_messagesList_->ItemsSource = contact->_conversation->_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(); scrollDown();
} }
void RingClientUWP::Views::MessageTextPage::scrollDown() void RingClientUWP::Views::MessageTextPage::scrollDown()
...@@ -143,3 +172,10 @@ void RingClientUWP::Views::MessageTextPage::OnincomingMessage(Platform::String ^ ...@@ -143,3 +172,10 @@ void RingClientUWP::Views::MessageTextPage::OnincomingMessage(Platform::String ^
{ {
scrollDown(); 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
...@@ -50,6 +50,8 @@ private: ...@@ -50,6 +50,8 @@ private:
void _messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); void _messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
void sendMessage(); void sendMessage();
void OnincomingMessage(Platform::String ^callId, Platform::String ^payload); void OnincomingMessage(Platform::String ^callId, Platform::String ^payload);
void OnSelectionChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^e);
}; };
} }
} }
...@@ -233,7 +233,16 @@ void RingClientUWP::RingD::placeCall(Contact^ contact) ...@@ -233,7 +233,16 @@ void RingClientUWP::RingD::placeCall(Contact^ contact)
{ {
MSG_("!--->> placeCall"); MSG_("!--->> placeCall");
auto to = contact->ringID_; 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 to2 = Utils::toString(to);
auto accountId2 = Utils::toString(accountId); auto accountId2 = Utils::toString(accountId);
...@@ -845,6 +854,7 @@ RingClientUWP::CallStatus RingClientUWP::RingD::translateCallStatus(String^ stat ...@@ -845,6 +854,7 @@ RingClientUWP::CallStatus RingClientUWP::RingD::translateCallStatus(String^ stat
if (state == "CONNECTING") if (state == "CONNECTING")
return CallStatus::SEARCHING; return CallStatus::SEARCHING;
return CallStatus::NONE; return CallStatus::NONE;
} }
......
...@@ -94,6 +94,8 @@ SmartPanel::SmartPanel() ...@@ -94,6 +94,8 @@ SmartPanel::SmartPanel()
return; return;
} }
contact->_accountIdAssociated = accountId;
auto item = SmartPanelItemsViewModel::instance->findItem(contact); auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_callId = callId; item->_callId = callId;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment