Showing sorted contacts, wow!
This commit is contained in:
parent
fe8199a1eb
commit
9d75cbbedf
3 changed files with 58 additions and 2 deletions
|
@ -29,6 +29,12 @@ Page {
|
||||||
property var contacts;
|
property var contacts;
|
||||||
property bool isLoading: true;
|
property bool isLoading: true;
|
||||||
|
|
||||||
|
onStatusChanged: {
|
||||||
|
if (status === PageStatus.Active) {
|
||||||
|
newChatPage.contacts = tdLibWrapper.getContactsFullInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SilicaFlickable {
|
SilicaFlickable {
|
||||||
id: newChatContainer
|
id: newChatContainer
|
||||||
contentHeight: newChatPage.height
|
contentHeight: newChatPage.height
|
||||||
|
@ -50,7 +56,7 @@ Page {
|
||||||
clip: true
|
clip: true
|
||||||
height: newChatPageColumn.height - newChatPageHeader.height
|
height: newChatPageColumn.height - newChatPageHeader.height
|
||||||
width: newChatPageColumn.width
|
width: newChatPageColumn.width
|
||||||
opacity: newChatPage.isLoading ? 0 : 1
|
//opacity: newChatPage.isLoading ? 0 : 1
|
||||||
Behavior on opacity { FadeAnimation {} }
|
Behavior on opacity { FadeAnimation {} }
|
||||||
|
|
||||||
ViewPlaceholder {
|
ViewPlaceholder {
|
||||||
|
@ -80,7 +86,7 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
tdLibWrapper.createPrivateChat(user_id);
|
tdLibWrapper.createPrivateChat(modelData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,9 @@ namespace {
|
||||||
const QString STATUS("status");
|
const QString STATUS("status");
|
||||||
const QString ID("id");
|
const QString ID("id");
|
||||||
const QString TYPE("type");
|
const QString TYPE("type");
|
||||||
|
const QString LAST_NAME("last_name");
|
||||||
|
const QString FIRST_NAME("first_name");
|
||||||
|
const QString USERNAME("username");
|
||||||
const QString _TYPE("@type");
|
const QString _TYPE("@type");
|
||||||
const QString _EXTRA("@extra");
|
const QString _EXTRA("@extra");
|
||||||
}
|
}
|
||||||
|
@ -935,6 +938,49 @@ void TDLibWrapper::registerJoinChat()
|
||||||
this->joinChatRequested = false;
|
this->joinChatRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool compareUsers(const QVariant &user1, const QVariant &user2)
|
||||||
|
{
|
||||||
|
const QVariantMap userMap1 = user1.toMap();
|
||||||
|
const QVariantMap userMap2 = user2.toMap();
|
||||||
|
|
||||||
|
const QString lastName1 = userMap1.value(LAST_NAME).toString();
|
||||||
|
const QString lastName2 = userMap2.value(LAST_NAME).toString();
|
||||||
|
if (lastName1 < lastName2) {
|
||||||
|
return true;
|
||||||
|
} else if (lastName1 > lastName2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const QString firstName1 = userMap1.value(FIRST_NAME).toString();
|
||||||
|
const QString firstName2 = userMap2.value(FIRST_NAME).toString();
|
||||||
|
if (firstName1 < firstName2) {
|
||||||
|
return true;
|
||||||
|
} else if (firstName1 > firstName2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const QString userName1 = userMap1.value(USERNAME).toString();
|
||||||
|
const QString userName2 = userMap2.value(USERNAME).toString();
|
||||||
|
if (userName1 < userName2) {
|
||||||
|
return true;
|
||||||
|
} else if (userName1 > userName2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return userMap1.value(ID).toLongLong() < userMap2.value(ID).toLongLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantList TDLibWrapper::getContactsFullInfo()
|
||||||
|
{
|
||||||
|
QVariantList preparedContacts;
|
||||||
|
QListIterator<QString> userIdIterator(contacts);
|
||||||
|
while (userIdIterator.hasNext()) {
|
||||||
|
QString nextUserId = userIdIterator.next();
|
||||||
|
if (allUsers.contains(nextUserId)) {
|
||||||
|
preparedContacts.append(allUsers.value(nextUserId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::sort(preparedContacts.begin(), preparedContacts.end(), compareUsers);
|
||||||
|
return preparedContacts;
|
||||||
|
}
|
||||||
|
|
||||||
DBusAdaptor *TDLibWrapper::getDBusAdaptor()
|
DBusAdaptor *TDLibWrapper::getDBusAdaptor()
|
||||||
{
|
{
|
||||||
return this->dbusInterface->getDBusAdaptor();
|
return this->dbusInterface->getDBusAdaptor();
|
||||||
|
@ -1152,12 +1198,14 @@ void TDLibWrapper::handleUsersReceived(const QString &extra, const QVariantList
|
||||||
if (this->contactsRequested) {
|
if (this->contactsRequested) {
|
||||||
LOG("Received contacts list...");
|
LOG("Received contacts list...");
|
||||||
this->contactsRequested = false;
|
this->contactsRequested = false;
|
||||||
|
contacts.clear();
|
||||||
QListIterator<QVariant> userIdIterator(userIds);
|
QListIterator<QVariant> userIdIterator(userIds);
|
||||||
while (userIdIterator.hasNext()) {
|
while (userIdIterator.hasNext()) {
|
||||||
QString nextUserId = userIdIterator.next().toString();
|
QString nextUserId = userIdIterator.next().toString();
|
||||||
if (!this->hasUserInformation(nextUserId)) {
|
if (!this->hasUserInformation(nextUserId)) {
|
||||||
this->getUserFullInfo(nextUserId);
|
this->getUserFullInfo(nextUserId);
|
||||||
}
|
}
|
||||||
|
contacts.append(nextUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit usersReceived(extra, userIds, totalUsers);
|
emit usersReceived(extra, userIds, totalUsers);
|
||||||
|
|
|
@ -106,6 +106,7 @@ public:
|
||||||
Q_INVOKABLE void controlScreenSaver(bool enabled);
|
Q_INVOKABLE void controlScreenSaver(bool enabled);
|
||||||
Q_INVOKABLE bool getJoinChatRequested();
|
Q_INVOKABLE bool getJoinChatRequested();
|
||||||
Q_INVOKABLE void registerJoinChat();
|
Q_INVOKABLE void registerJoinChat();
|
||||||
|
Q_INVOKABLE QVariantList getContactsFullInfo();
|
||||||
|
|
||||||
DBusAdaptor *getDBusAdaptor();
|
DBusAdaptor *getDBusAdaptor();
|
||||||
|
|
||||||
|
@ -265,6 +266,7 @@ private:
|
||||||
QVariantMap allUsers;
|
QVariantMap allUsers;
|
||||||
QVariantMap allUserNames;
|
QVariantMap allUserNames;
|
||||||
QVariantMap chats;
|
QVariantMap chats;
|
||||||
|
QList<QString> contacts;
|
||||||
QVariantMap unreadMessageInformation;
|
QVariantMap unreadMessageInformation;
|
||||||
QVariantMap unreadChatInformation;
|
QVariantMap unreadChatInformation;
|
||||||
QHash<qlonglong,Group*> basicGroups;
|
QHash<qlonglong,Group*> basicGroups;
|
||||||
|
|
Loading…
Reference in a new issue