Merge pull request #117 from monich/chatType

Move chatTypeFromString from ChatListModel to TDLibWrapper
This commit is contained in:
Sebastian Wolf 2020-11-01 19:24:45 +01:00 committed by GitHub
commit 4938bbf361
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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: