account: refactor account selection
Change-Id: Ib45a5388d6e6860970c1dd2a31709d0aaea123d2
Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
diff --git a/src/utils.h b/src/utils.h
index 28290ee..2ca45c9 100755
--- a/src/utils.h
+++ b/src/utils.h
@@ -46,6 +46,22 @@
return [@(contact.profileInfo.uri.c_str()) removeEmptyLinesAtBorders];
}
+static inline NSString* bestIDForAccount(const lrc::api::account::Info& account)
+{
+ if (!account.registeredName.empty()) {
+ return [@(account.registeredName.c_str()) removeEmptyLinesAtBorders];
+ }
+ return [@(account.profileInfo.uri.c_str()) removeEmptyLinesAtBorders];
+}
+
+static inline NSString* bestNameForAccount(const lrc::api::account::Info& account)
+{
+ if (account.profileInfo.alias.empty()) {
+ return bestIDForAccount(account);
+ }
+ return @(account.profileInfo.alias.c_str());
+}
+
static inline NSString* bestNameForConversation(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model)
{
auto contact = model.owner.contactModel->getContact(conv.participants[0]);