Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jami-libclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
savoirfairelinux
jami-libclient
Commits
9861c6d1
Commit
9861c6d1
authored
Oct 5, 2020
by
Ming Rui Zhang
Browse files
Options
Downloads
Patches
Plain Diff
newaccountmodel: add get best name and best id logic
Gitlab:
#439
Change-Id: I6c9e85aa939eaf0faf08fa39ac510d9fc68784cf
parent
b16c4ce8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/api/newaccountmodel.h
+12
-0
12 additions, 0 deletions
src/api/newaccountmodel.h
src/newaccountmodel.cpp
+65
-33
65 additions, 33 deletions
src/newaccountmodel.cpp
with
77 additions
and
33 deletions
src/api/newaccountmodel.h
+
12
−
0
View file @
9861c6d1
...
@@ -188,6 +188,18 @@ public:
...
@@ -188,6 +188,18 @@ public:
* @return vcard of the account
* @return vcard of the account
*/
*/
Q_INVOKABLE
QString
accountVCard
(
const
QString
&
accountId
,
bool
compressImage
=
true
)
const
;
Q_INVOKABLE
QString
accountVCard
(
const
QString
&
accountId
,
bool
compressImage
=
true
)
const
;
/**
* Get the best name for an account
* @param id
* @return best name of the account
*/
const
QString
bestNameForAccount
(
const
QString
&
accountID
);
/**
* Get the best id for an account
* @param id
* @return best id of the account
*/
const
QString
bestIdForAccount
(
const
QString
&
accountID
);
Q_SIGNALS
:
Q_SIGNALS
:
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src/newaccountmodel.cpp
+
65
−
33
View file @
9861c6d1
...
@@ -107,6 +107,13 @@ public:
...
@@ -107,6 +107,13 @@ public:
*/
*/
void
updateAccountDetails
(
account
::
Info
&
account
);
void
updateAccountDetails
(
account
::
Info
&
account
);
/**
* get a modifiable account informations associated to an accountId.
* @param accountId.
* @return a account::Info& structure.
*/
account
::
Info
&
getAccountInfo
(
const
QString
&
accountId
);
public
Q_SLOTS
:
public
Q_SLOTS
:
/**
/**
...
@@ -209,12 +216,7 @@ NewAccountModel::getAccountList() const
...
@@ -209,12 +216,7 @@ NewAccountModel::getAccountList() const
void
void
NewAccountModel
::
setAccountEnabled
(
const
QString
&
accountId
,
bool
enabled
)
const
NewAccountModel
::
setAccountEnabled
(
const
QString
&
accountId
,
bool
enabled
)
const
{
{
auto
account
=
pimpl_
->
accounts
.
find
(
accountId
);
auto
&
accountInfo
=
pimpl_
->
getAccountInfo
(
accountId
);
if
(
account
==
pimpl_
->
accounts
.
end
())
{
throw
std
::
out_of_range
(
"NewAccountModel::getAccountConfig, can't find "
+
accountId
.
toStdString
());
}
auto
&
accountInfo
=
account
->
second
.
first
;
accountInfo
.
enabled
=
enabled
;
accountInfo
.
enabled
=
enabled
;
ConfigurationManager
::
instance
().
sendRegister
(
accountId
,
enabled
);
ConfigurationManager
::
instance
().
sendRegister
(
accountId
,
enabled
);
}
}
...
@@ -223,11 +225,7 @@ void
...
@@ -223,11 +225,7 @@ void
NewAccountModel
::
setAccountConfig
(
const
QString
&
accountId
,
NewAccountModel
::
setAccountConfig
(
const
QString
&
accountId
,
const
account
::
ConfProperties_t
&
confProperties
)
const
const
account
::
ConfProperties_t
&
confProperties
)
const
{
{
auto
account
=
pimpl_
->
accounts
.
find
(
accountId
);
auto
&
accountInfo
=
pimpl_
->
getAccountInfo
(
accountId
);
if
(
account
==
pimpl_
->
accounts
.
end
())
{
throw
std
::
out_of_range
(
"NewAccountModel::save, can't find "
+
accountId
.
toStdString
());
}
auto
&
accountInfo
=
account
->
second
.
first
;
auto
&
configurationManager
=
ConfigurationManager
::
instance
();
auto
&
configurationManager
=
ConfigurationManager
::
instance
();
MapStringString
details
=
confProperties
.
toDetails
();
MapStringString
details
=
confProperties
.
toDetails
();
// Set values from Info. No need to include ID and TYPE. SIP accounts may modify the USERNAME
// Set values from Info. No need to include ID and TYPE. SIP accounts may modify the USERNAME
...
@@ -272,23 +270,13 @@ NewAccountModel::setAccountConfig(const QString& accountId,
...
@@ -272,23 +270,13 @@ NewAccountModel::setAccountConfig(const QString& accountId,
account
::
ConfProperties_t
account
::
ConfProperties_t
NewAccountModel
::
getAccountConfig
(
const
QString
&
accountId
)
const
NewAccountModel
::
getAccountConfig
(
const
QString
&
accountId
)
const
{
{
auto
account
=
pimpl_
->
accounts
.
find
(
accountId
);
return
getAccountInfo
(
accountId
).
confProperties
;
if
(
account
==
pimpl_
->
accounts
.
end
())
{
throw
std
::
out_of_range
(
"NewAccountModel::getAccountConfig, can't find "
+
accountId
.
toStdString
());
}
auto
&
accountInfo
=
account
->
second
.
first
;
return
accountInfo
.
confProperties
;
}
}
void
void
NewAccountModel
::
setAlias
(
const
QString
&
accountId
,
const
QString
&
alias
)
NewAccountModel
::
setAlias
(
const
QString
&
accountId
,
const
QString
&
alias
)
{
{
auto
account
=
pimpl_
->
accounts
.
find
(
accountId
);
auto
&
accountInfo
=
pimpl_
->
getAccountInfo
(
accountId
);
if
(
account
==
pimpl_
->
accounts
.
end
())
{
throw
std
::
out_of_range
(
"NewAccountModel::setAlias, can't find "
+
accountId
.
toStdString
());
}
auto
&
accountInfo
=
account
->
second
.
first
;
accountInfo
.
profileInfo
.
alias
=
alias
;
accountInfo
.
profileInfo
.
alias
=
alias
;
authority
::
storage
::
createOrUpdateProfile
(
accountInfo
.
id
,
accountInfo
.
profileInfo
);
authority
::
storage
::
createOrUpdateProfile
(
accountInfo
.
id
,
accountInfo
.
profileInfo
);
...
@@ -299,11 +287,7 @@ NewAccountModel::setAlias(const QString& accountId, const QString& alias)
...
@@ -299,11 +287,7 @@ NewAccountModel::setAlias(const QString& accountId, const QString& alias)
void
void
NewAccountModel
::
setAvatar
(
const
QString
&
accountId
,
const
QString
&
avatar
)
NewAccountModel
::
setAvatar
(
const
QString
&
accountId
,
const
QString
&
avatar
)
{
{
auto
account
=
pimpl_
->
accounts
.
find
(
accountId
);
auto
&
accountInfo
=
pimpl_
->
getAccountInfo
(
accountId
);
if
(
account
==
pimpl_
->
accounts
.
end
())
{
throw
std
::
out_of_range
(
"NewAccountModel::setAvatar, can't find "
+
accountId
.
toStdString
());
}
auto
&
accountInfo
=
account
->
second
.
first
;
accountInfo
.
profileInfo
.
avatar
=
avatar
;
accountInfo
.
profileInfo
.
avatar
=
avatar
;
authority
::
storage
::
createOrUpdateProfile
(
accountInfo
.
id
,
accountInfo
.
profileInfo
);
authority
::
storage
::
createOrUpdateProfile
(
accountInfo
.
id
,
accountInfo
.
profileInfo
);
...
@@ -513,6 +497,17 @@ NewAccountModelPimpl::updateAccountDetails(account::Info& accountInfo)
...
@@ -513,6 +497,17 @@ NewAccountModelPimpl::updateAccountDetails(account::Info& accountInfo)
accountInfo
.
status
=
lrc
::
api
::
account
::
to_status
(
daemonStatus
);
accountInfo
.
status
=
lrc
::
api
::
account
::
to_status
(
daemonStatus
);
}
}
account
::
Info
&
NewAccountModelPimpl
::
getAccountInfo
(
const
QString
&
accountId
)
{
auto
account
=
accounts
.
find
(
accountId
);
if
(
account
==
accounts
.
end
())
{
throw
std
::
out_of_range
(
"NewAccountModelPimpl::getAccountInfo, can't find "
+
accountId
.
toStdString
());
}
return
account
->
second
.
first
;
}
void
void
NewAccountModelPimpl
::
slotAccountStatusChanged
(
const
QString
&
accountID
,
NewAccountModelPimpl
::
slotAccountStatusChanged
(
const
QString
&
accountID
,
const
api
::
account
::
Status
status
)
const
api
::
account
::
Status
status
)
...
@@ -1105,12 +1100,49 @@ NewAccountModel::setTopAccount(const QString& accountId)
...
@@ -1105,12 +1100,49 @@ NewAccountModel::setTopAccount(const QString& accountId)
QString
QString
NewAccountModel
::
accountVCard
(
const
QString
&
accountId
,
bool
compressImage
)
const
NewAccountModel
::
accountVCard
(
const
QString
&
accountId
,
bool
compressImage
)
const
{
{
auto
account
=
pimpl_
->
accounts
.
find
(
accountId
);
return
authority
::
storage
::
vcard
::
profileToVcard
(
getAccountInfo
(
accountId
).
profileInfo
,
if
(
account
==
pimpl_
->
accounts
.
end
())
{
compressImage
);
return
{};
}
}
auto
&
accountInfo
=
account
->
second
.
first
;
return
authority
::
storage
::
vcard
::
profileToVcard
(
accountInfo
.
profileInfo
,
compressImage
);
const
QString
NewAccountModel
::
bestNameForAccount
(
const
QString
&
accountID
)
{
// Order: Alias, registeredName, uri
auto
&
accountInfo
=
getAccountInfo
(
accountID
);
auto
alias
=
accountInfo
.
profileInfo
.
alias
.
simplified
();
auto
registeredName
=
accountInfo
.
registeredName
.
simplified
();
auto
infoHash
=
accountInfo
.
profileInfo
.
uri
.
simplified
();
if
(
alias
.
isEmpty
())
{
if
(
registeredName
.
isEmpty
())
return
infoHash
;
else
return
registeredName
;
}
return
alias
;
}
const
QString
NewAccountModel
::
bestIdForAccount
(
const
QString
&
accountID
)
{
// Order: RegisteredName, uri after best name
// return empty string if duplicated with best name
auto
&
accountInfo
=
getAccountInfo
(
accountID
);
auto
alias
=
accountInfo
.
profileInfo
.
alias
.
simplified
();
auto
registeredName
=
accountInfo
.
registeredName
.
simplified
();
auto
infoHash
=
accountInfo
.
profileInfo
.
uri
.
simplified
();
if
(
alias
.
isEmpty
())
{
if
(
!
registeredName
.
isEmpty
())
return
infoHash
;
}
else
if
(
registeredName
.
isEmpty
())
{
return
infoHash
;
}
else
if
(
registeredName
!=
alias
)
{
return
registeredName
;
}
return
QString
();
}
}
}
// namespace lrc
}
// namespace lrc
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment