Some additional preparations to send stickers

This commit is contained in:
Sebastian J. Wolf 2020-10-12 22:44:21 +02:00
parent df3f750c66
commit 256244a08e
9 changed files with 212 additions and 6 deletions

View file

@ -27,6 +27,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
src/fernschreiberutils.cpp \
src/notificationmanager.cpp \
src/processlauncher.cpp \
src/stickermanager.cpp \
src/tdlibreceiver.cpp \
src/tdlibwrapper.cpp
@ -111,6 +112,7 @@ HEADERS += \
src/fernschreiberutils.h \
src/notificationmanager.h \
src/processlauncher.h \
src/stickermanager.h \
src/tdlibreceiver.h \
src/tdlibsecrets.h \
src/tdlibwrapper.h

View file

@ -939,6 +939,20 @@ Page {
}
}
}
Item {
id: stickerPickerOverlayItem
anchors.fill: parent
visible: false
Rectangle {
id: stickerPickerOverlayBackground
anchors.fill: parent
color: Theme.overlayBackgroundColor
opacity: 0.7
}
}
}
Column {
@ -1038,11 +1052,20 @@ Page {
pageStack.push(documentPickerPage);
}
}
IconButton {
id: stickerAttachmentButton
icon.source: "../../images/icon-m-sticker.png"
HighlightImage {
source: "../../images/icon-m-sticker.png"
width: documentAttachmentButton.width
height: documentAttachmentButton.height
color: Theme.primaryColor
highlightColor: Theme.highlightColor
highlighted: stickerPickerOverlayItem.visible
MouseArea {
anchors.fill: parent
onClicked: {
// TODO
//console.log("RECENT STICKERS: " + JSON.stringify(stickerManager.getRecentStickers()));
//console.log("INSTALLED SETS: " + JSON.stringify(stickerManager.getInstalledStickerSets()));
stickerPickerOverlayItem.visible = !stickerPickerOverlayItem.visible;
}
}
}
}

View file

@ -94,6 +94,8 @@ Page {
function updateContent() {
tdLibWrapper.getChats();
tdLibWrapper.getRecentStickers();
tdLibWrapper.getInstalledStickerSets();
}
function initializePage() {

View file

@ -36,6 +36,7 @@
#include "notificationmanager.h"
#include "dbusadaptor.h"
#include "processlauncher.h"
#include "stickermanager.h"
int main(int argc, char *argv[])
{
@ -66,6 +67,9 @@ int main(int argc, char *argv[])
ProcessLauncher processLauncher;
context->setContextProperty("processLauncher", &processLauncher);
StickerManager stickerManager(tdLibWrapper);
context->setContextProperty("stickerManager", &stickerManager);
view->setSource(SailfishApp::pathTo("qml/harbour-fernschreiber.qml"));
view->show();
return app->exec();

96
src/stickermanager.cpp Normal file
View file

@ -0,0 +1,96 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
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 "stickermanager.h"
#include <QDebug>
#include <QListIterator>
#define LOG(x) qDebug() << "[StickerManager]" << x
StickerManager::StickerManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent)
{
LOG("Initializing...");
this->tdLibWrapper = tdLibWrapper;
connect(this->tdLibWrapper, SIGNAL(recentStickersUpdated(QVariantList)), this, SLOT(handleRecentStickersUpdated(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(stickersReceived(QVariantList)), this, SLOT(handleStickersReceived(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(installedStickerSetsUpdated(QVariantList)), this, SLOT(handleInstalledStickerSetsUpdated(QVariantList)));
connect(this->tdLibWrapper, SIGNAL(stickerSetsReceived(QVariantList)), this, SLOT(handleStickerSetsReceived(QVariantList)));
}
StickerManager::~StickerManager()
{
LOG("Destroying myself...");
}
QVariantList StickerManager::getRecentStickers()
{
return this->recentStickers;
}
QVariantList StickerManager::getInstalledStickerSets()
{
return this->installedStickerSets;
}
void StickerManager::handleRecentStickersUpdated(const QVariantList &stickerIds)
{
LOG("Receiving recent stickers...." << stickerIds);
this->recentStickerIds = stickerIds;
}
void StickerManager::handleStickersReceived(const QVariantList &stickers)
{
LOG("Receiving stickers...." << stickers);
QListIterator<QVariant> stickersIterator(stickers);
while (stickersIterator.hasNext()) {
QVariantMap newSticker = stickersIterator.next().toMap();
this->stickers.insert(newSticker.value("sticker").toMap().value("id").toString(), newSticker);
}
this->recentStickers.clear();
QListIterator<QVariant> stickerIdIterator(this->recentStickerIds);
while (stickerIdIterator.hasNext()) {
QString stickerId = stickerIdIterator.next().toString();
this->recentStickers.append(this->stickers.value(stickerId));
}
}
void StickerManager::handleInstalledStickerSetsUpdated(const QVariantList &stickerSetIds)
{
LOG("Receiving installed sticker IDs...." << stickerSetIds);
this->installedStickerSetIds = stickerSetIds;
}
void StickerManager::handleStickerSetsReceived(const QVariantList &stickerSets)
{
LOG("Receiving sticker sets...." << stickerSets);
QListIterator<QVariant> stickerSetsIterator(stickerSets);
while (stickerSetsIterator.hasNext()) {
QVariantMap newStickerSet = stickerSetsIterator.next().toMap();
this->stickerSets.insert(newStickerSet.value("id").toString(), newStickerSet);
}
this->installedStickerSets.clear();
QListIterator<QVariant> stickerSetIdIterator(this->installedStickerSetIds);
while (stickerSetIdIterator.hasNext()) {
QString stickerSetId = stickerSetIdIterator.next().toString();
this->installedStickerSets.append(this->stickerSets.value(stickerSetId));
}
}

61
src/stickermanager.h Normal file
View file

@ -0,0 +1,61 @@
/*
Copyright (C) 2020 Sebastian J. Wolf
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 STICKERMANAGER_H
#define STICKERMANAGER_H
#include <QObject>
#include <QVariantMap>
#include <QVariantList>
#include "tdlibwrapper.h"
class StickerManager : public QObject
{
Q_OBJECT
public:
explicit StickerManager(TDLibWrapper *tdLibWrapper, QObject *parent = nullptr);
~StickerManager();
Q_INVOKABLE QVariantList getRecentStickers();
Q_INVOKABLE QVariantList getInstalledStickerSets();
signals:
private slots:
void handleRecentStickersUpdated(const QVariantList &stickerIds);
void handleStickersReceived(const QVariantList &stickers);
void handleInstalledStickerSetsUpdated(const QVariantList &stickerSetIds);
void handleStickerSetsReceived(const QVariantList &stickerSets);
private:
TDLibWrapper *tdLibWrapper;
QVariantList recentStickers;
QVariantList recentStickerIds;
QVariantList installedStickerSets;
QVariantList installedStickerSetIds;
QVariantMap stickers;
QVariantMap stickerSets;
};
#endif // STICKERMANAGER_H

View file

@ -395,5 +395,5 @@ void TDLibReceiver::processUpdateInstalledStickerSets(const QVariantMap &receive
void TDLibReceiver::processStickerSets(const QVariantMap &receivedInformation)
{
LOG("Received some sticker sets...");
emit stickers(receivedInformation.value("sets").toList());
emit stickerSets(receivedInformation.value("sets").toList());
}

View file

@ -336,6 +336,23 @@ void TDLibWrapper::sendDocumentMessage(const QString &chatId, const QString &fil
this->sendRequest(requestObject);
}
void TDLibWrapper::sendStickerMessage(const QString &chatId, const QVariantMap &stickerInformation, const QString &replyToMessageId)
{
LOG("Sending sticker message" << chatId << stickerInformation << replyToMessageId);
QVariantMap requestObject;
requestObject.insert(_TYPE, "sendMessage");
requestObject.insert("chat_id", chatId);
if (replyToMessageId != "0") {
requestObject.insert("reply_to_message_id", replyToMessageId);
}
QVariantMap inputMessageContent;
inputMessageContent.insert(_TYPE, "inputMessageSticker");
inputMessageContent.insert("sticker", stickerInformation);
requestObject.insert("input_message_content", inputMessageContent);
this->sendRequest(requestObject);
}
void TDLibWrapper::getMessage(const QString &chatId, const QString &messageId)
{
LOG("Retrieving message" << chatId << messageId);

View file

@ -118,6 +118,7 @@ public:
Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendDocumentMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0");
Q_INVOKABLE void sendStickerMessage(const QString &chatId, const QVariantMap &stickerInformation, const QString &replyToMessageId = "0");
Q_INVOKABLE void getMessage(const QString &chatId, const QString &messageId);
Q_INVOKABLE void setOptionInteger(const QString &optionName, const int &optionValue);
Q_INVOKABLE void setChatNotificationSettings(const QString &chatId, const QVariantMap &notificationSettings);