Make sure track path is saved to track view so sending it back won't crash. Keep track of users for requests to implement limited amounts of requests. Implement requesting with limits.
This commit is contained in:
@@ -150,7 +150,7 @@ std::list<AudioTrack> GroovePlayerMgr::getNextVoteBatch(Wt::Dbo::Session* sessio
|
||||
if(requestQueue.size() > 0)
|
||||
{
|
||||
//There's a request. Pick one up front and put as third item.
|
||||
AudioTrack selected = requestQueue.front();
|
||||
AudioTrack selected = requestQueue.front().first;
|
||||
getPictureFromTrack(&selected);
|
||||
selectedTracks.push_back(selected);
|
||||
}
|
||||
@@ -308,7 +308,7 @@ void GroovePlayerMgr::grooveEventLoop()
|
||||
if(requestQueue.size() > 0)
|
||||
{
|
||||
//If winning track was a request, now you can remove it from request queue.
|
||||
if(requestQueue.front().trackFingerprint == winner.trackFingerprint)
|
||||
if(requestQueue.front().first.trackFingerprint == winner.trackFingerprint)
|
||||
{
|
||||
requestQueue.pop_front();
|
||||
}
|
||||
@@ -325,7 +325,7 @@ void GroovePlayerMgr::grooveEventLoop()
|
||||
//Pick request song if there are any.
|
||||
if(requestQueue.size() > 0)
|
||||
{
|
||||
winner = requestQueue.front();
|
||||
winner = requestQueue.front().first;
|
||||
requestQueue.pop_front();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
User userInvolved;
|
||||
std::list<AudioTrack> tracksInvolved;
|
||||
};
|
||||
std::list<AudioTrack> requestQueue;
|
||||
std::list<std::pair<AudioTrack,User>> requestQueue;
|
||||
std::list<PlayerEvent> lastInternalEvents;
|
||||
Wt::Dbo::backend::Sqlite3* sqliteConnection;
|
||||
Wt::Dbo::FixedSqlConnectionPool* connectionPool;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WAnimation>
|
||||
#include <Wt/WBootstrapTheme>
|
||||
#include <regex>
|
||||
|
||||
struct WebInterface::internal
|
||||
{
|
||||
@@ -75,6 +76,7 @@ void WebInterface::playPauseActionFromServer(User userPausing, bool pause)
|
||||
void WebInterface::songChangedFromServer(AudioTrack nextTrack)
|
||||
{
|
||||
priv_int->playerUI->updateDetailsFromServer(nextTrack);
|
||||
priv_int->playerUI->requestPane->updateRequestButtonState();
|
||||
triggerUpdate();
|
||||
}
|
||||
|
||||
@@ -114,5 +116,6 @@ void WebInterface::voteTracksUpdatedFromServer(std::list<AudioTrack> voteableTra
|
||||
|
||||
std::string WebInterface::getNotificationJs(std::string notificationText)
|
||||
{
|
||||
return std::string("function notifyMe(a,b){var c=\"")+notificationText+std::string("\";if('Notification'in window)if('granted'===Notification.permission){new Notification(c)}else'denied'!==Notification.permission&&Notification.requestPermission(function(a){if('granted'===a){new Notification(c)}});else;}");
|
||||
std::string escapedText = std::regex_replace(notificationText,std::regex("\""),"'");
|
||||
return std::string("function notifyMe(a,b){var c=\"")+escapedText+std::string("\";if('Notification'in window)if('granted'===Notification.permission){new Notification(c)}else'denied'!==Notification.permission&&Notification.requestPermission(function(a){if('granted'===a){new Notification(c)}});else;}");
|
||||
}
|
||||
|
||||
@@ -54,7 +54,45 @@ RequestInterface::RequestInterface(WebInterface* app)
|
||||
|
||||
void RequestInterface::trackRequestClicked(AudioTrack track)
|
||||
{
|
||||
//TODO
|
||||
if(getRequestCountForUser(app->currentUser) < 3)
|
||||
{
|
||||
GroovePlayerMgr::getInstance()->requestQueue.push_back(std::pair<AudioTrack,User>(track,app->currentUser));
|
||||
//Now check if this is this user's last request and disable buttons.
|
||||
updateRequestButtonState();
|
||||
}
|
||||
}
|
||||
|
||||
void RequestInterface::updateRequestButtonState()
|
||||
{
|
||||
if(getRequestCountForUser(app->currentUser) < 3)
|
||||
{
|
||||
//enable buttons
|
||||
for(RequestItem* item : foundItems)
|
||||
{
|
||||
if(item != nullptr) item->voteBtn->setEnabled(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//disable buttons
|
||||
for(RequestItem* item : foundItems)
|
||||
{
|
||||
if(item != nullptr) item->voteBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int RequestInterface::getRequestCountForUser(User user)
|
||||
{
|
||||
int count = 0;
|
||||
for(std::pair<AudioTrack,User> request : GroovePlayerMgr::getInstance()->requestQueue)
|
||||
{
|
||||
if(request.second.username == user.username)
|
||||
{
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void RequestInterface::searchClicked()
|
||||
@@ -101,6 +139,7 @@ void RequestInterface::searchClicked()
|
||||
if(!left) rowCount += 1;
|
||||
left = !left;
|
||||
}
|
||||
updateRequestButtonState();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -77,6 +77,8 @@ public:
|
||||
|
||||
void trackRequestClicked(AudioTrack track);
|
||||
void searchClicked();
|
||||
int getRequestCountForUser(User user);
|
||||
void updateRequestButtonState();
|
||||
};
|
||||
|
||||
#endif // REQUESTINTERFACE_H
|
||||
|
||||
@@ -67,6 +67,7 @@ void TrackDetails::updateWithTrackDetails(AudioTrack track)
|
||||
trackAlbum->setText(track.trackAlbumName);
|
||||
trackFingerprint = track.trackFingerprint;
|
||||
trackGenre = track.trackGenre;
|
||||
trackPath = track.trackPath;
|
||||
|
||||
//Set image to data from track obj.
|
||||
coverData = new Wt::WMemoryResource(track.coverMimeType);
|
||||
@@ -97,5 +98,6 @@ AudioTrack TrackDetails::extractTrackFromDetails()
|
||||
track.trackAlbumName = trackAlbum->text().toUTF8();
|
||||
track.trackGenre = trackGenre;
|
||||
track.trackFingerprint = trackFingerprint;
|
||||
track.trackPath = trackPath;
|
||||
return track;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
|
||||
std::string trackFingerprint;
|
||||
std::string trackGenre;
|
||||
std::string trackPath;
|
||||
|
||||
void updateWithTrackDetails(AudioTrack track);
|
||||
void changeBackgroundColor(Wt::WColor color);
|
||||
|
||||
Reference in New Issue
Block a user