Skip to content
Snippets Groups Projects
Commit fe8b931d authored by Ming Rui Zhang's avatar Ming Rui Zhang
Browse files

sip: use best id as the filter for sip call transfer contact picker

Display name is not a good filter since sip accounts may have
the same display name

Change-Id: Id1033816c496dd702874f646efcba7914cb2342d
parent bd96da9c
No related branches found
No related tags found
No related merge requests found
...@@ -31,9 +31,7 @@ ContactAdapter::ContactAdapter(QObject* parent, LRCInstance* instance) ...@@ -31,9 +31,7 @@ ContactAdapter::ContactAdapter(QObject* parent, LRCInstance* instance)
QVariant QVariant
ContactAdapter::getContactSelectableModel(int type) ContactAdapter::getContactSelectableModel(int type)
{ {
/* // Called from qml every time contact picker refreshes.
* Called from qml every time contact picker refreshes.
*/
listModeltype_ = static_cast<SmartListModel::Type>(type); listModeltype_ = static_cast<SmartListModel::Type>(type);
if (listModeltype_ == SmartListModel::Type::CONVERSATION) { if (listModeltype_ == SmartListModel::Type::CONVERSATION) {
...@@ -46,9 +44,7 @@ ContactAdapter::getContactSelectableModel(int type) ...@@ -46,9 +44,7 @@ ContactAdapter::getContactSelectableModel(int type)
} }
selectableProxyModel_->setSourceModel(smartListModel_.get()); selectableProxyModel_->setSourceModel(smartListModel_.get());
/* // Adjust filter.
* Adjust filter.
*/
switch (listModeltype_) { switch (listModeltype_) {
case SmartListModel::Type::CONVERSATION: case SmartListModel::Type::CONVERSATION:
selectableProxyModel_->setPredicate([this](const QModelIndex& index, const QRegExp&) { selectableProxyModel_->setPredicate([this](const QModelIndex& index, const QRegExp&) {
...@@ -63,16 +59,21 @@ ContactAdapter::getContactSelectableModel(int type) ...@@ -63,16 +59,21 @@ ContactAdapter::getContactSelectableModel(int type)
break; break;
case SmartListModel::Type::TRANSFER: case SmartListModel::Type::TRANSFER:
selectableProxyModel_->setPredicate([this](const QModelIndex& index, const QRegExp& regexp) { selectableProxyModel_->setPredicate([this](const QModelIndex& index, const QRegExp& regexp) {
/* // Exclude current sip callee and filtered contact.
* Regex to remove current callee. bool match = true;
*/ const auto& conv = lrcInstance_->getConversationFromConvUid(
QRegExp matchExcept = QRegExp(QString("\\b(?!" + calleeDisplayName_ + "\\b)\\w+")); lrcInstance_->getCurrentConvUid());
bool match = false; if (!conv.participants.isEmpty()) {
bool match_non_self = matchExcept.indexIn( QString calleeDisplayId = lrcInstance_->getAccountInfo(lrcInstance_->getCurrAccId())
index.data(SmartListModel::Role::DisplayName).toString()) .contactModel->bestIdForContact(conv.participants[0]);
!= -1;
if (match_non_self) { QRegExp matchExcept = QRegExp(QString("\\b(?!" + calleeDisplayId + "\\b)\\w+"));
match = regexp.indexIn(index.data(SmartListModel::Role::DisplayName).toString()) match = matchExcept.indexIn(index.data(SmartListModel::Role::DisplayID).toString())
!= -1;
}
if (match) {
match = regexp.indexIn(index.data(SmartListModel::Role::DisplayID).toString())
!= -1; != -1;
} }
return match && !index.parent().isValid(); return match && !index.parent().isValid();
...@@ -112,9 +113,7 @@ ContactAdapter::contactSelected(int index) ...@@ -112,9 +113,7 @@ ContactAdapter::contactSelected(int index)
if (contactIndex.isValid()) { if (contactIndex.isValid()) {
switch (listModeltype_) { switch (listModeltype_) {
case SmartListModel::Type::CONFERENCE: { case SmartListModel::Type::CONFERENCE: {
/* // Conference.
* Conference.
*/
const auto sectionName = contactIndex.data(SmartListModel::Role::SectionName) const auto sectionName = contactIndex.data(SmartListModel::Role::SectionName)
.value<QString>(); .value<QString>();
if (!sectionName.isEmpty()) { if (!sectionName.isEmpty()) {
...@@ -143,9 +142,7 @@ ContactAdapter::contactSelected(int index) ...@@ -143,9 +142,7 @@ ContactAdapter::contactSelected(int index)
} }
} break; } break;
case SmartListModel::Type::TRANSFER: { case SmartListModel::Type::TRANSFER: {
/* // SIP Transfer.
* SIP Transfer.
*/
const auto contactUri = contactIndex.data(SmartListModel::Role::URI).value<QString>(); const auto contactUri = contactIndex.data(SmartListModel::Role::URI).value<QString>();
if (convInfo.uid.isEmpty()) { if (convInfo.uid.isEmpty()) {
...@@ -156,19 +153,16 @@ ContactAdapter::contactSelected(int index) ...@@ -156,19 +153,16 @@ ContactAdapter::contactSelected(int index)
QString destCallId; QString destCallId;
try { try {
/* // Check if the call exist - (check non-finished calls).
* Check if the call exist - (check non-finished calls).
*/
const auto callInfo = callModel->getCallFromURI(contactUri, true); const auto callInfo = callModel->getCallFromURI(contactUri, true);
destCallId = callInfo.id; destCallId = callInfo.id;
} catch (std::exception& e) { } catch (std::exception& e) {
qDebug().noquote() << e.what(); qDebug().noquote() << e.what();
destCallId = ""; destCallId = "";
} }
/*
* If no second call -> blind transfer. // If no second call -> blind transfer.
* If there is a second call -> attended transfer. // If there is a second call -> attended transfer.
*/
if (destCallId.size() == 0) { if (destCallId.size() == 0) {
callModel->transfer(callId, "sip:" + contactUri); callModel->transfer(callId, "sip:" + contactUri);
callModel->hangUp(callId); callModel->hangUp(callId);
...@@ -195,9 +189,3 @@ ContactAdapter::contactSelected(int index) ...@@ -195,9 +189,3 @@ ContactAdapter::contactSelected(int index)
} }
} }
} }
void
ContactAdapter::setCalleeDisplayName(const QString& name)
{
calleeDisplayName_ = name;
}
...@@ -81,14 +81,10 @@ protected: ...@@ -81,14 +81,10 @@ protected:
Q_INVOKABLE QVariant getContactSelectableModel(int type); Q_INVOKABLE QVariant getContactSelectableModel(int type);
Q_INVOKABLE void setSearchFilter(const QString& filter); Q_INVOKABLE void setSearchFilter(const QString& filter);
Q_INVOKABLE void contactSelected(int index); Q_INVOKABLE void contactSelected(int index);
Q_INVOKABLE void setCalleeDisplayName(const QString& name);
private: private:
SmartListModel::Type listModeltype_; SmartListModel::Type listModeltype_;
// For sip call transfer, to exclude current sip callee.
QString calleeDisplayName_;
// SmartListModel is the source model of SelectableProxyModel. // SmartListModel is the source model of SelectableProxyModel.
std::unique_ptr<SmartListModel> smartListModel_; std::unique_ptr<SmartListModel> smartListModel_;
std::unique_ptr<SelectableProxyModel> selectableProxyModel_; std::unique_ptr<SelectableProxyModel> selectableProxyModel_;
......
...@@ -344,9 +344,5 @@ Rectangle { ...@@ -344,9 +344,5 @@ Rectangle {
} }
} }
onBestNameChanged: {
ContactAdapter.setCalleeDisplayName(bestName)
}
color: "black" color: "black"
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment