Fix playing music from a different account.

This commit is contained in:
John Preston 2020-06-25 15:12:50 +04:00
parent c60b9cfa4d
commit 90a9cb4f8d
6 changed files with 59 additions and 27 deletions

View File

@ -251,11 +251,6 @@ MainWidget::MainWidget(
connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled()));
connect(_history, &HistoryWidget::cancelled, [=] { handleHistoryBack(); });
Media::Player::instance()->updatedNotifier(
) | rpl::start_with_next([=](const Media::Player::TrackState &state) {
handleAudioUpdate(state);
}, lifetime());
subscribe(session().calls().currentCallChanged(), [=](Calls::Call *call) {
setCurrentCall(call);
});
@ -268,6 +263,16 @@ MainWidget::MainWidget(
_exportTopBar->finishAnimating();
}
Media::Player::instance()->updatedNotifier(
) | rpl::start_with_next([=](const Media::Player::TrackState &state) {
handleAudioUpdate(state);
}, lifetime());
handleAudioUpdate(Media::Player::instance()->getState(AudioMsgId::Type::Song));
handleAudioUpdate(Media::Player::instance()->getState(AudioMsgId::Type::Voice));
if (_player) {
_player->finishAnimating();
}
subscribe(_controller->dialogsListFocused(), [this](bool) {
updateDialogsWidthAnimated();
});

View File

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_domain.h" // Domain::activeSessionValue.
#include "mainwindow.h"
#include "main/main_session.h"
#include "main/main_account.h" // session->account().sessionChanges().
#include "main/main_session_settings.h"
namespace Media {
@ -126,13 +127,6 @@ Instance::Instance()
resumeOnCall(AudioMsgId::Type::Song);
}
});
} else {
const auto reset = [&](AudioMsgId::Type type) {
const auto data = getData(type);
*data = Data(type, data->overview);
};
reset(AudioMsgId::Type::Voice);
reset(AudioMsgId::Type::Song);
}
}, _lifetime);
@ -180,17 +174,45 @@ void Instance::setCurrent(const AudioMsgId &audioId) {
? audioId.audio()->owner().message(audioId.contextId())
: nullptr;
if (item) {
data->history = item->history()->migrateToOrMe();
data->migrated = data->history->migrateFrom();
setHistory(data, item->history());
} else {
data->history = nullptr;
data->migrated = nullptr;
data->session = nullptr;
}
_trackChangedNotifier.notify(data->type, true);
refreshPlaylist(data);
}
}
void Instance::setHistory(not_null<Data*> data, History *history) {
if (history) {
data->history = history->migrateToOrMe();
data->migrated = data->history->migrateFrom();
setSession(data, &history->session());
} else {
data->history = data->migrated = nullptr;
setSession(data, nullptr);
}
}
void Instance::setSession(not_null<Data*> data, Main::Session *session) {
if (data->session == session) {
return;
}
data->playlistLifetime.destroy();
data->sessionLifetime.destroy();
data->session = session;
if (session) {
session->account().sessionChanges(
) | rpl::start_with_next([=] {
setSession(data, nullptr);
}, data->sessionLifetime);
} else {
*data = Data(data->type, data->overview);
}
}
void Instance::clearStreamed(not_null<Data*> data, bool savePosition) {
if (!data->streamed || data->streamed->clearing) {
return;
@ -263,6 +285,7 @@ bool Instance::validPlaylist(not_null<Data*> data) {
}
void Instance::validatePlaylist(not_null<Data*> data) {
data->playlistLifetime.destroy();
if (const auto key = playlistKey(data)) {
data->playlistRequestedKey = key;
SharedMediaMergedViewer(

View File

@ -180,9 +180,11 @@ private:
std::optional<SliceKey> playlistRequestedKey;
std::optional<int> playlistIndex;
rpl::lifetime playlistLifetime;
rpl::lifetime sessionLifetime;
rpl::event_stream<> playlistChanges;
History *history = nullptr;
History *migrated = nullptr;
Main::Session *session = nullptr;
bool repeatEnabled = false;
bool isPlaying = false;
bool resumeOnCallEnd = false;
@ -252,6 +254,10 @@ private:
void requestRoundVideoResize() const;
void requestRoundVideoRepaint() const;
void setHistory(not_null<Data*> data, History *history);
void setSession(not_null<Data*> data, Main::Session *session);
Data _songData;
Data _voiceData;

View File

@ -43,8 +43,8 @@ Panel::Panel(
not_null<Window::SessionController*> window)
: RpWidget(parent)
, AbstractController(window)
, _showTimer([this] { startShow(); })
, _hideTimer([this] { startHideChecked(); })
, _showTimer([=] { startShow(); })
, _hideTimer([=] { startHideChecked(); })
, _scroll(this, st::mediaPlayerScroll) {
hide();
updateSize();
@ -210,7 +210,7 @@ void Panel::ensureCreated() {
_refreshListLifetime = instance()->playlistChanges(
AudioMsgId::Type::Song
) | rpl::start_with_next([this] {
) | rpl::start_with_next([=] {
refreshList();
});
refreshList();
@ -229,6 +229,12 @@ void Panel::refreshList() {
const auto current = instance()->current(AudioMsgId::Type::Song);
const auto contextId = current.contextId();
const auto peer = [&]() -> PeerData* {
if (const auto document = current.audio()) {
if (&document->session() != &session()) {
// Different account is playing music.
return nullptr;
}
}
const auto item = contextId
? session().data().message(contextId)
: nullptr;

View File

@ -3557,11 +3557,7 @@ void OverlayWidget::setSession(not_null<Main::Session*> session) {
}, _sessionLifetime);
session->account().sessionChanges(
) | rpl::start_with_next_done([=](Main::Session *value) {
if (value != session) {
clearSession();
}
}, [=] {
) | rpl::start_with_next([=] {
clearSession();
}, _sessionLifetime);
}

View File

@ -879,11 +879,7 @@ Pip::Pip(
setupStreaming();
_data->session().account().sessionChanges(
) | rpl::start_with_next_done([=](Main::Session *session) {
if (!session) {
_destroy();
}
}, [=] {
) | rpl::start_with_next([=] {
_destroy();
}, _panel.lifetime());
}