mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2024-11-22 09:15:18 +00:00
Update UserData based when notified over websocket
This commit is contained in:
parent
40d8a58a5a
commit
af99b39722
|
@ -114,6 +114,7 @@ public:
|
||||||
Q_PROPERTY(QList<QObject *> audioStreams READ audioStreams NOTIFY audioStreamsChanged)
|
Q_PROPERTY(QList<QObject *> audioStreams READ audioStreams NOTIFY audioStreamsChanged)
|
||||||
Q_PROPERTY(QList<QObject *> videoStreams READ videoStreams NOTIFY videoStreamsChanged)
|
Q_PROPERTY(QList<QObject *> videoStreams READ videoStreams NOTIFY videoStreamsChanged)
|
||||||
Q_PROPERTY(QList<QObject *> subtitleStreams READ subtitleStreams NOTIFY subtitleStreamsChanged)
|
Q_PROPERTY(QList<QObject *> subtitleStreams READ subtitleStreams NOTIFY subtitleStreamsChanged)
|
||||||
|
Q_PROPERTY(double primaryImageAspectRatio READ primaryImageAspectRatio NOTIFY primaryImageAspectRatioChanged)
|
||||||
Q_PROPERTY(QStringList artists READ artists NOTIFY artistsChanged)
|
Q_PROPERTY(QStringList artists READ artists NOTIFY artistsChanged)
|
||||||
// Why is this a QJsonObject? Well, because I couldn't be bothered to implement the deserialisations of
|
// Why is this a QJsonObject? Well, because I couldn't be bothered to implement the deserialisations of
|
||||||
// a QHash at the moment.
|
// a QHash at the moment.
|
||||||
|
@ -159,6 +160,7 @@ public:
|
||||||
QObjectList audioStreams() const { return m_audioStreams; }
|
QObjectList audioStreams() const { return m_audioStreams; }
|
||||||
QObjectList videoStreams() const { return m_videoStreams; }
|
QObjectList videoStreams() const { return m_videoStreams; }
|
||||||
QObjectList subtitleStreams() const { return m_subtitleStreams; }
|
QObjectList subtitleStreams() const { return m_subtitleStreams; }
|
||||||
|
double primaryImageAspectRatio() const { return m_data->primaryImageAspectRatio().value_or(1.0); }
|
||||||
QStringList artists() const { return m_data->artists(); }
|
QStringList artists() const { return m_data->artists(); }
|
||||||
QJsonObject imageTags() const { return m_data->imageTags(); }
|
QJsonObject imageTags() const { return m_data->imageTags(); }
|
||||||
QStringList backdropImageTags() const { return m_data->backdropImageTags(); }
|
QStringList backdropImageTags() const { return m_data->backdropImageTags(); }
|
||||||
|
@ -219,6 +221,7 @@ signals:
|
||||||
void audioStreamsChanged(QVariantList &newAudioStreams);
|
void audioStreamsChanged(QVariantList &newAudioStreams);
|
||||||
void videoStreamsChanged(QVariantList &newVideoStreams);
|
void videoStreamsChanged(QVariantList &newVideoStreams);
|
||||||
void subtitleStreamsChanged(QVariantList &newSubtitleStreams);
|
void subtitleStreamsChanged(QVariantList &newSubtitleStreams);
|
||||||
|
void primaryImageAspectRatioChanged(double newPrimaryImageAspectRatio);
|
||||||
void artistsChanged(const QStringList &newArtists);
|
void artistsChanged(const QStringList &newArtists);
|
||||||
void imageTagsChanged();
|
void imageTagsChanged();
|
||||||
void backdropImageTagsChanged();
|
void backdropImageTagsChanged();
|
||||||
|
|
|
@ -376,6 +376,9 @@ public:
|
||||||
}
|
}
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
QSharedPointer<Model::Item> itemAt(int index);
|
QSharedPointer<Model::Item> itemAt(int index);
|
||||||
|
private slots:
|
||||||
|
void onInsertItems(const QModelIndex &parent, int start, int end);
|
||||||
|
void onUserDataUpdated(const DTO::UserItemDataDto &newUserData);
|
||||||
};
|
};
|
||||||
#undef JFRN
|
#undef JFRN
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ void Item::setApiClient(ApiClient *apiClient) {
|
||||||
|
|
||||||
void Item::updateUserData(const QString &itemId, const DTO::UserItemDataDto &userData) {
|
void Item::updateUserData(const QString &itemId, const DTO::UserItemDataDto &userData) {
|
||||||
if (itemId == this->jellyfinId()) {
|
if (itemId == this->jellyfinId()) {
|
||||||
|
this->m_userData = QSharedPointer<DTO::UserItemDataDto>::create(userData);
|
||||||
emit userDataChanged(userData);
|
emit userDataChanged(userData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,9 @@ NextUpLoader::NextUpLoader(QObject *parent)
|
||||||
: NextUpLoaderBase(new Jellyfin::Loader::HTTP::GetNextUpLoader(), parent) {}
|
: NextUpLoaderBase(new Jellyfin::Loader::HTTP::GetNextUpLoader(), parent) {}
|
||||||
|
|
||||||
ItemModel::ItemModel(QObject *parent)
|
ItemModel::ItemModel(QObject *parent)
|
||||||
: ApiModel<Model::Item>(parent) { }
|
: ApiModel<Model::Item>(parent) {
|
||||||
|
connect(this, &QAbstractItemModel::rowsInserted, this, &ItemModel::onInsertItems);
|
||||||
|
}
|
||||||
|
|
||||||
QVariant ItemModel::data(const QModelIndex &index, int role) const {
|
QVariant ItemModel::data(const QModelIndex &index, int role) const {
|
||||||
if (role <= Qt::UserRole || !index.isValid()) return QVariant();
|
if (role <= Qt::UserRole || !index.isValid()) return QVariant();
|
||||||
|
@ -123,6 +125,26 @@ QSharedPointer<Model::Item> ItemModel::itemAt(int index) {
|
||||||
return m_array[index];
|
return m_array[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ItemModel::onInsertItems(const QModelIndex &parent, int start, int end) {
|
||||||
|
if (parent.isValid()) return;
|
||||||
|
qDebug() << "Connecting " << (end - start + 1) << "items!";
|
||||||
|
for (int i = start; i <= end; i++) {
|
||||||
|
connect(itemAt(i).data(), &Model::Item::userDataChanged, this, &ItemModel::onUserDataUpdated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemModel::onUserDataUpdated(const DTO::UserItemDataDto &newUserData) {
|
||||||
|
const QString &itemId = newUserData.itemId();
|
||||||
|
qDebug() << "ApiModel: item updated: " << itemId;
|
||||||
|
for (int i = 0; i < rowCount(QModelIndex()); i++) {
|
||||||
|
if (itemAt(i)->jellyfinId() == itemId) {
|
||||||
|
QModelIndex index = this->index(i);
|
||||||
|
emit this->dataChanged(index, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // NS ViewModel
|
} // NS ViewModel
|
||||||
|
|
||||||
} // NS Jellyfin
|
} // NS Jellyfin
|
||||||
|
|
|
@ -95,7 +95,7 @@ void WebSocket::textMessageReceived(const QString &message) {
|
||||||
setupKeepAlive(data.toInt());
|
setupKeepAlive(data.toInt());
|
||||||
} else if (messageType == QStringLiteral("GeneralCommand")) {
|
} else if (messageType == QStringLiteral("GeneralCommand")) {
|
||||||
try {
|
try {
|
||||||
DTO::GeneralCommand command = DTO::GeneralCommand::fromJson(messageRoot["Data"].toObject());
|
DTO::GeneralCommand command = DTO::GeneralCommand::fromJson(data.toObject());
|
||||||
|
|
||||||
// TODO: move command handling out of here
|
// TODO: move command handling out of here
|
||||||
switch(command.name()) {
|
switch(command.name()) {
|
||||||
|
@ -108,7 +108,7 @@ void WebSocket::textMessageReceived(const QString &message) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qCDebug(jellyfinWebSocket) << "Unhandled command: " << messageRoot["Data"];
|
qCDebug(jellyfinWebSocket) << "Unhandled command: " << data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,49 +117,28 @@ void WebSocket::textMessageReceived(const QString &message) {
|
||||||
}
|
}
|
||||||
} else if (messageType == QStringLiteral("Playstate")) {
|
} else if (messageType == QStringLiteral("Playstate")) {
|
||||||
try {
|
try {
|
||||||
DTO::PlaystateRequest request = PlaystateRequest::fromJson(messageRoot["Data"].toObject());
|
DTO::PlaystateRequest request = PlaystateRequest::fromJson(data.toObject());
|
||||||
emit m_apiClient->eventbus()->playstateCommandReceived(request);
|
emit m_apiClient->eventbus()->playstateCommandReceived(request);
|
||||||
} catch (QException &e) {
|
} catch (QException &e) {
|
||||||
qCWarning(jellyfinWebSocket()) << "Error while deserialzing PlaystateRequest " << e.what();
|
qCWarning(jellyfinWebSocket) << "Error while deserialzing PlaystateRequest " << e.what();
|
||||||
|
}
|
||||||
|
} else if(messageType == QStringLiteral("UserDataChanged")) {
|
||||||
|
QString userId = data.toObject()["UserId"].toString();
|
||||||
|
if (userId != m_apiClient->userId()) {
|
||||||
|
qCDebug(jellyfinWebSocket) << "Received UserDataCHanged for other user";
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
QList<DTO::UserItemDataDto> userDataList = Support::fromJsonValue<QList<DTO::UserItemDataDto>>(data.toObject()["UserDataList"]);
|
||||||
|
for (auto it = userDataList.cbegin(); it != userDataList.cend(); it++) {
|
||||||
|
emit m_apiClient->eventbus()->itemUserDataUpdated(it->itemId(), *it);
|
||||||
|
}
|
||||||
|
} catch (QException *e) {
|
||||||
|
qCWarning(jellyfinWebSocket) << "Unparseable UserData list received: " << e->what();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(jellyfinWebSocket) << messageType;
|
qCDebug(jellyfinWebSocket) << messageType;
|
||||||
}
|
}
|
||||||
bool ok;
|
|
||||||
/*MessageType messageType = static_cast<MessageType>(QMetaEnum::fromType<WebSocket::MessageType>().keyToValue(messageTypeStr.toLatin1(), &ok));
|
|
||||||
if (!ok) {
|
|
||||||
qWarning() << "Unknown message arrived: " << messageTypeStr;
|
|
||||||
if (messageRoot.contains("Data")) {
|
|
||||||
qDebug() << "with data: " << QJsonDocument(messageRoot["Data"].toObject()).toJson();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "Received message: " << messageTypeStr;
|
|
||||||
|
|
||||||
switch (messageType) {
|
|
||||||
case ForceKeepAlive:
|
|
||||||
setupKeepAlive(data.toInt(-1));
|
|
||||||
break;
|
|
||||||
case KeepAlive:
|
|
||||||
//TODO: do something?
|
|
||||||
break;
|
|
||||||
case UserDataChanged: {
|
|
||||||
QJsonObject data2 = data.toObject();
|
|
||||||
if (data2["UserId"] != m_apiClient->userId()) {
|
|
||||||
qDebug() << "Received UserDataCHanged for other user";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
QJsonArray userDataList = data2["UserDataList"].toArray();
|
|
||||||
for (QJsonValue val: userDataList) {
|
|
||||||
UserItemDataDto userData = UserItemDataDto::fromJson(val.toObject());
|
|
||||||
//m_apiClient->onUserDataChanged(userData->itemId(), userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebSocket::sendKeepAlive() {
|
void WebSocket::sendKeepAlive() {
|
||||||
|
|
Loading…
Reference in a new issue