Skip to content
Snippets Groups Projects
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
Branches
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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();
......
......@@ -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);
}
......
......@@ -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>
......
......@@ -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
......@@ -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);
};
}
}
......@@ -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;
}
......
......@@ -94,6 +94,8 @@ SmartPanel::SmartPanel()
return;
}
contact->_accountIdAssociated = accountId;
auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_callId = callId;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment