Moved chatTypeFromString from ChatListModel to TDLibWrapper

So that it can be used elsewhere
This commit is contained in:
Slava Monich 2020-10-31 21:18:12 +02:00
parent 72315312d6
commit 4c2f9dba19
3 changed files with 11 additions and 17 deletions

View file

@ -43,13 +43,7 @@ namespace {
const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id"); const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id");
const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id"); const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id");
const QString IS_CHANNEL("is_channel"); const QString IS_CHANNEL("is_channel");
const QString _TYPE("@type"); const QString _TYPE("@type");
const QString TYPE_MESSAGE_TEXT("messageText");
const QString TYPE_CHAT_TYPE_PRIVATE("chatTypePrivate");
const QString TYPE_CHAT_TYPE_BASIC_GROUP("chatTypeBasicGroup");
const QString TYPE_CHAT_TYPE_SUPERGROUP("chatTypeSupergroup");
const QString TYPE_CHAT_TYPE_SECRET("chatTypeSecret");
} }
class ChatListModel::ChatData class ChatListModel::ChatData
@ -88,7 +82,6 @@ public:
bool updateLastReadInboxMessageId(qlonglong messageId); bool updateLastReadInboxMessageId(qlonglong messageId);
QVector<int> updateLastMessage(const QVariantMap &message); QVector<int> updateLastMessage(const QVariantMap &message);
QVector<int> updateGroup(const TDLibWrapper::Group *group); QVector<int> updateGroup(const TDLibWrapper::Group *group);
static TDLibWrapper::ChatType chatTypeFromString(const QString &type);
public: public:
QVariantMap chatData; QVariantMap chatData;
@ -109,7 +102,7 @@ ChatListModel::ChatData::ChatData(const QVariantMap &data, const QVariantMap &us
userInformation(userInfo) userInformation(userInfo)
{ {
const QVariantMap type(data.value(TYPE).toMap()); const QVariantMap type(data.value(TYPE).toMap());
switch (chatType = chatTypeFromString(type.value(_TYPE).toString())) { switch (chatType = TDLibWrapper::chatTypeFromString(type.value(_TYPE).toString())) {
case TDLibWrapper::ChatTypeBasicGroup: case TDLibWrapper::ChatTypeBasicGroup:
groupId = type.value(BASIC_GROUP_ID).toLongLong(); groupId = type.value(BASIC_GROUP_ID).toLongLong();
break; break;
@ -264,15 +257,6 @@ QVector<int> ChatListModel::ChatData::updateGroup(const TDLibWrapper::Group *gro
return changedRoles; return changedRoles;
} }
TDLibWrapper::ChatType ChatListModel::ChatData::chatTypeFromString(const QString &type)
{
return (type == TYPE_CHAT_TYPE_PRIVATE) ? TDLibWrapper::ChatTypePrivate :
(type == TYPE_CHAT_TYPE_BASIC_GROUP) ? TDLibWrapper::ChatTypeBasicGroup :
(type == TYPE_CHAT_TYPE_SUPERGROUP) ? TDLibWrapper::ChatTypeSupergroup :
(type == TYPE_CHAT_TYPE_SECRET) ? TDLibWrapper::ChatTypeSecret :
TDLibWrapper::ChatTypeUnknown;
}
ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) : showHiddenChats(false) ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) : showHiddenChats(false)
{ {
this->tdLibWrapper = tdLibWrapper; this->tdLibWrapper = tdLibWrapper;

View file

@ -1056,6 +1056,15 @@ const TDLibWrapper::Group* TDLibWrapper::getGroup(qlonglong groupId) const
return Q_NULLPTR; return Q_NULLPTR;
} }
TDLibWrapper::ChatType TDLibWrapper::chatTypeFromString(const QString &type)
{
return (type == QStringLiteral("chatTypePrivate")) ? ChatTypePrivate :
(type == QStringLiteral("chatTypeBasicGroup")) ? ChatTypeBasicGroup :
(type == QStringLiteral("chatTypeSupergroup")) ? ChatTypeSupergroup :
(type == QStringLiteral("chatTypeSecret")) ? ChatTypeSecret :
ChatTypeUnknown;
}
TDLibWrapper::ChatMemberStatus TDLibWrapper::chatMemberStatusFromString(const QString &status) TDLibWrapper::ChatMemberStatus TDLibWrapper::chatMemberStatusFromString(const QString &status)
{ {
// Most common ones first // Most common ones first

View file

@ -152,6 +152,7 @@ public:
public: public:
const Group* getGroup(qlonglong groupId) const; const Group* getGroup(qlonglong groupId) const;
static ChatType chatTypeFromString(const QString &type);
static ChatMemberStatus chatMemberStatusFromString(const QString &status); static ChatMemberStatus chatMemberStatusFromString(const QString &status);
signals: signals: