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:
Kevin Whitaker
2017-02-19 22:21:05 -05:00
parent 5b89f375b2
commit fc98ec671a
7 changed files with 53 additions and 6 deletions

View File

@@ -150,7 +150,7 @@ std::list<AudioTrack> GroovePlayerMgr::getNextVoteBatch(Wt::Dbo::Session* sessio
if(requestQueue.size() > 0) if(requestQueue.size() > 0)
{ {
//There's a request. Pick one up front and put as third item. //There's a request. Pick one up front and put as third item.
AudioTrack selected = requestQueue.front(); AudioTrack selected = requestQueue.front().first;
getPictureFromTrack(&selected); getPictureFromTrack(&selected);
selectedTracks.push_back(selected); selectedTracks.push_back(selected);
} }
@@ -308,7 +308,7 @@ void GroovePlayerMgr::grooveEventLoop()
if(requestQueue.size() > 0) if(requestQueue.size() > 0)
{ {
//If winning track was a request, now you can remove it from request queue. //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(); requestQueue.pop_front();
} }
@@ -325,7 +325,7 @@ void GroovePlayerMgr::grooveEventLoop()
//Pick request song if there are any. //Pick request song if there are any.
if(requestQueue.size() > 0) if(requestQueue.size() > 0)
{ {
winner = requestQueue.front(); winner = requestQueue.front().first;
requestQueue.pop_front(); requestQueue.pop_front();
} }
else else

View File

@@ -65,7 +65,7 @@ public:
User userInvolved; User userInvolved;
std::list<AudioTrack> tracksInvolved; std::list<AudioTrack> tracksInvolved;
}; };
std::list<AudioTrack> requestQueue; std::list<std::pair<AudioTrack,User>> requestQueue;
std::list<PlayerEvent> lastInternalEvents; std::list<PlayerEvent> lastInternalEvents;
Wt::Dbo::backend::Sqlite3* sqliteConnection; Wt::Dbo::backend::Sqlite3* sqliteConnection;
Wt::Dbo::FixedSqlConnectionPool* connectionPool; Wt::Dbo::FixedSqlConnectionPool* connectionPool;

View File

@@ -23,6 +23,7 @@
#include <Wt/WText> #include <Wt/WText>
#include <Wt/WAnimation> #include <Wt/WAnimation>
#include <Wt/WBootstrapTheme> #include <Wt/WBootstrapTheme>
#include <regex>
struct WebInterface::internal struct WebInterface::internal
{ {
@@ -75,6 +76,7 @@ void WebInterface::playPauseActionFromServer(User userPausing, bool pause)
void WebInterface::songChangedFromServer(AudioTrack nextTrack) void WebInterface::songChangedFromServer(AudioTrack nextTrack)
{ {
priv_int->playerUI->updateDetailsFromServer(nextTrack); priv_int->playerUI->updateDetailsFromServer(nextTrack);
priv_int->playerUI->requestPane->updateRequestButtonState();
triggerUpdate(); triggerUpdate();
} }
@@ -114,5 +116,6 @@ void WebInterface::voteTracksUpdatedFromServer(std::list<AudioTrack> voteableTra
std::string WebInterface::getNotificationJs(std::string notificationText) 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;}");
} }

View File

@@ -54,7 +54,45 @@ RequestInterface::RequestInterface(WebInterface* app)
void RequestInterface::trackRequestClicked(AudioTrack track) 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() void RequestInterface::searchClicked()
@@ -101,6 +139,7 @@ void RequestInterface::searchClicked()
if(!left) rowCount += 1; if(!left) rowCount += 1;
left = !left; left = !left;
} }
updateRequestButtonState();
} }
else else
{ {

View File

@@ -77,6 +77,8 @@ public:
void trackRequestClicked(AudioTrack track); void trackRequestClicked(AudioTrack track);
void searchClicked(); void searchClicked();
int getRequestCountForUser(User user);
void updateRequestButtonState();
}; };
#endif // REQUESTINTERFACE_H #endif // REQUESTINTERFACE_H

View File

@@ -67,6 +67,7 @@ void TrackDetails::updateWithTrackDetails(AudioTrack track)
trackAlbum->setText(track.trackAlbumName); trackAlbum->setText(track.trackAlbumName);
trackFingerprint = track.trackFingerprint; trackFingerprint = track.trackFingerprint;
trackGenre = track.trackGenre; trackGenre = track.trackGenre;
trackPath = track.trackPath;
//Set image to data from track obj. //Set image to data from track obj.
coverData = new Wt::WMemoryResource(track.coverMimeType); coverData = new Wt::WMemoryResource(track.coverMimeType);
@@ -97,5 +98,6 @@ AudioTrack TrackDetails::extractTrackFromDetails()
track.trackAlbumName = trackAlbum->text().toUTF8(); track.trackAlbumName = trackAlbum->text().toUTF8();
track.trackGenre = trackGenre; track.trackGenre = trackGenre;
track.trackFingerprint = trackFingerprint; track.trackFingerprint = trackFingerprint;
track.trackPath = trackPath;
return track; return track;
} }

View File

@@ -44,6 +44,7 @@ public:
std::string trackFingerprint; std::string trackFingerprint;
std::string trackGenre; std::string trackGenre;
std::string trackPath;
void updateWithTrackDetails(AudioTrack track); void updateWithTrackDetails(AudioTrack track);
void changeBackgroundColor(Wt::WColor color); void changeBackgroundColor(Wt::WColor color);