Start with @-mentioning in own messages
This commit is contained in:
parent
cc08ee3997
commit
f7296daf4e
5 changed files with 222 additions and 0 deletions
|
@ -28,6 +28,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
|
||||||
src/dbusinterface.cpp \
|
src/dbusinterface.cpp \
|
||||||
src/emojisearchworker.cpp \
|
src/emojisearchworker.cpp \
|
||||||
src/fernschreiberutils.cpp \
|
src/fernschreiberutils.cpp \
|
||||||
|
src/knownusersmodel.cpp \
|
||||||
src/mceinterface.cpp \
|
src/mceinterface.cpp \
|
||||||
src/notificationmanager.cpp \
|
src/notificationmanager.cpp \
|
||||||
src/processlauncher.cpp \
|
src/processlauncher.cpp \
|
||||||
|
@ -151,6 +152,7 @@ HEADERS += \
|
||||||
src/debuglogjs.h \
|
src/debuglogjs.h \
|
||||||
src/emojisearchworker.h \
|
src/emojisearchworker.h \
|
||||||
src/fernschreiberutils.h \
|
src/fernschreiberutils.h \
|
||||||
|
src/knownusersmodel.h \
|
||||||
src/mceinterface.h \
|
src/mceinterface.h \
|
||||||
src/notificationmanager.h \
|
src/notificationmanager.h \
|
||||||
src/processlauncher.h \
|
src/processlauncher.h \
|
||||||
|
|
|
@ -268,6 +268,12 @@ Page {
|
||||||
} else {
|
} else {
|
||||||
chatPage.emojiProposals = null;
|
chatPage.emojiProposals = null;
|
||||||
}
|
}
|
||||||
|
if (currentWord.length > 1 && currentWord.charAt(0) === '@') {
|
||||||
|
knownUsersRepeater.model = knownUsersProxyModel;
|
||||||
|
knownUsersProxyModel.setFilterWildcard("*" + currentWord.substring(1) + "*");
|
||||||
|
} else {
|
||||||
|
knownUsersRepeater.model = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceMessageText(text, cursorPosition, newText) {
|
function replaceMessageText(text, cursorPosition, newText) {
|
||||||
|
@ -1186,6 +1192,83 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
id: atMentionColumn
|
||||||
|
width: parent.width
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
visible: knownUsersRepeater.count > 0 ? true : false
|
||||||
|
opacity: knownUsersRepeater.count > 0 ? 1 : 0
|
||||||
|
Behavior on opacity { NumberAnimation {} }
|
||||||
|
spacing: Theme.paddingMedium
|
||||||
|
|
||||||
|
Flickable {
|
||||||
|
width: parent.width
|
||||||
|
height: atMentionResultRow.height + Theme.paddingSmall
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
contentWidth: atMentionResultRow.width
|
||||||
|
clip: true
|
||||||
|
Row {
|
||||||
|
id: atMentionResultRow
|
||||||
|
spacing: Theme.paddingMedium
|
||||||
|
Repeater {
|
||||||
|
id: knownUsersRepeater
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: knownUserItem
|
||||||
|
height: singleAtMentionRow.height
|
||||||
|
width: singleAtMentionRow.width
|
||||||
|
|
||||||
|
property string atMentionText: "@" + (user_name ? user_name : user_id + "(" + title + ")");
|
||||||
|
|
||||||
|
Row {
|
||||||
|
id: singleAtMentionRow
|
||||||
|
spacing: Theme.paddingSmall
|
||||||
|
|
||||||
|
Item {
|
||||||
|
width: Theme.fontSizeHuge
|
||||||
|
height: Theme.fontSizeHuge
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
ProfileThumbnail {
|
||||||
|
id: atMentionThumbnail
|
||||||
|
replacementStringHint: title
|
||||||
|
width: parent.width
|
||||||
|
height: parent.width
|
||||||
|
photoData: photo_small
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Text {
|
||||||
|
text: Emoji.emojify(title, Theme.fontSizeExtraSmall)
|
||||||
|
textFormat: Text.StyledText
|
||||||
|
color: Theme.primaryColor
|
||||||
|
font.pixelSize: Theme.fontSizeExtraSmall
|
||||||
|
font.bold: true
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
id: userHandleText
|
||||||
|
text: user_handle
|
||||||
|
textFormat: Text.StyledText
|
||||||
|
color: Theme.primaryColor
|
||||||
|
font.pixelSize: Theme.fontSizeExtraSmall
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: {
|
||||||
|
replaceMessageText(newMessageTextField.text, newMessageTextField.cursorPosition, knownUserItem.atMentionText);
|
||||||
|
knownUsersRepeater.model = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: Theme.paddingSmall
|
spacing: Theme.paddingSmall
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include "stickermanager.h"
|
#include "stickermanager.h"
|
||||||
#include "tgsplugin.h"
|
#include "tgsplugin.h"
|
||||||
#include "fernschreiberutils.h"
|
#include "fernschreiberutils.h"
|
||||||
|
#include "knownusersmodel.h"
|
||||||
|
|
||||||
// The default filter can be overridden by QT_LOGGING_RULES envinronment variable, e.g.
|
// The default filter can be overridden by QT_LOGGING_RULES envinronment variable, e.g.
|
||||||
// QT_LOGGING_RULES="fernschreiber.*=true" harbour-fernschreiber
|
// QT_LOGGING_RULES="fernschreiber.*=true" harbour-fernschreiber
|
||||||
|
@ -96,6 +97,14 @@ int main(int argc, char *argv[])
|
||||||
StickerManager stickerManager(tdLibWrapper);
|
StickerManager stickerManager(tdLibWrapper);
|
||||||
context->setContextProperty("stickerManager", &stickerManager);
|
context->setContextProperty("stickerManager", &stickerManager);
|
||||||
|
|
||||||
|
KnownUsersModel knownUsersModel(tdLibWrapper, view.data());
|
||||||
|
context->setContextProperty("knownUsersModel", &knownUsersModel);
|
||||||
|
QSortFilterProxyModel knownUsersProxyModel(view.data());
|
||||||
|
knownUsersProxyModel.setSourceModel(&knownUsersModel);
|
||||||
|
knownUsersProxyModel.setFilterRole(KnownUsersModel::RoleFilter);
|
||||||
|
knownUsersProxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
context->setContextProperty("knownUsersProxyModel", &knownUsersProxyModel);
|
||||||
|
|
||||||
view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml"));
|
view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml"));
|
||||||
view->show();
|
view->show();
|
||||||
return app->exec();
|
return app->exec();
|
||||||
|
|
71
src/knownusersmodel.cpp
Normal file
71
src/knownusersmodel.cpp
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
||||||
|
|
||||||
|
This file is part of Fernschreiber.
|
||||||
|
|
||||||
|
Fernschreiber is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Fernschreiber is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "knownusersmodel.h"
|
||||||
|
|
||||||
|
#define DEBUG_MODULE KnwonUsersModel
|
||||||
|
#include "debuglog.h"
|
||||||
|
|
||||||
|
KnownUsersModel::KnownUsersModel(TDLibWrapper *tdLibWrapper, QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
this->tdLibWrapper = tdLibWrapper;
|
||||||
|
|
||||||
|
connect(this->tdLibWrapper, SIGNAL(userUpdated(QString, QVariantMap)), this, SLOT(handleUserUpdated(QString, QVariantMap)));
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> KnownUsersModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int,QByteArray> roles;
|
||||||
|
roles.insert(KnownUserRole::RoleDisplay, "display");
|
||||||
|
roles.insert(KnownUserRole::RoleUserId, "user_id");
|
||||||
|
roles.insert(KnownUserRole::RoleTitle, "title");
|
||||||
|
roles.insert(KnownUserRole::RoleUsername, "user_name");
|
||||||
|
roles.insert(KnownUserRole::RoleUserHandle, "user_handle");
|
||||||
|
roles.insert(KnownUserRole::RolePhotoSmall, "photo_small");
|
||||||
|
roles.insert(KnownUserRole::RoleFilter, "filter");
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KnownUsersModel::rowCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return this->knownUsers.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant KnownUsersModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (index.isValid()) {
|
||||||
|
QVariantMap requestedUser = knownUsers.values().value(index.row()).toMap();
|
||||||
|
switch (static_cast<KnownUserRole>(role)) {
|
||||||
|
case KnownUserRole::RoleDisplay: return requestedUser;
|
||||||
|
case KnownUserRole::RoleUserId: return requestedUser.value("id");
|
||||||
|
case KnownUserRole::RoleTitle: return QString(requestedUser.value("first_name").toString() + " " + requestedUser.value("last_name").toString()).trimmed();
|
||||||
|
case KnownUserRole::RoleUsername: return requestedUser.value("username");
|
||||||
|
case KnownUserRole::RoleUserHandle: return QString("@" + (requestedUser.value("username").toString().isEmpty() ? requestedUser.value("id").toString() : requestedUser.value("username").toString()));
|
||||||
|
case KnownUserRole::RolePhotoSmall: return requestedUser.value("profile_photo").toMap().value("small");
|
||||||
|
case KnownUserRole::RoleFilter: return QString(requestedUser.value("first_name").toString() + " " + requestedUser.value("last_name").toString() + " " + requestedUser.value("username").toString()).trimmed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void KnownUsersModel::handleUserUpdated(const QString &userId, const QVariantMap &userInformation)
|
||||||
|
{
|
||||||
|
this->knownUsers.insert(userId, userInformation);
|
||||||
|
}
|
57
src/knownusersmodel.h
Normal file
57
src/knownusersmodel.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
||||||
|
|
||||||
|
This file is part of Fernschreiber.
|
||||||
|
|
||||||
|
Fernschreiber is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Fernschreiber is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KNOWNUSERSMODEL_H
|
||||||
|
#define KNOWNUSERSMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QVariantList>
|
||||||
|
#include "tdlibwrapper.h"
|
||||||
|
|
||||||
|
class KnownUsersModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum KnownUserRole {
|
||||||
|
RoleDisplay = Qt::DisplayRole,
|
||||||
|
RoleUserId,
|
||||||
|
RoleTitle,
|
||||||
|
RoleUsername,
|
||||||
|
RoleUserHandle,
|
||||||
|
RolePhotoSmall,
|
||||||
|
RoleFilter
|
||||||
|
};
|
||||||
|
|
||||||
|
KnownUsersModel(TDLibWrapper *tdLibWrapper, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
virtual QHash<int,QByteArray> roleNames() const override;
|
||||||
|
virtual int rowCount(const QModelIndex &) const override;
|
||||||
|
virtual QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void handleUserUpdated(const QString &userId, const QVariantMap &userInformation);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TDLibWrapper *tdLibWrapper;
|
||||||
|
QVariantMap knownUsers;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // KNOWNUSERSMODEL_H
|
Loading…
Reference in a new issue