Commit 8cd19a27 authored by Mehdi Sabwat's avatar Mehdi Sabwat Committed by Mehdi Sabwat
Browse files

Media: add isUnseen accessor

It will return true if the playCount was set to 0, and if lastPosition
is negative which means the media was never played or that it ended
(in that case, the playCount won't be equal to 0)

Ref. #388
parent fe128035
Pipeline #157017 failed with stages
in 16 seconds
......@@ -224,6 +224,7 @@ public:
* This method will not bump the media in the history
*/
virtual bool setPlayCount( uint32_t playCount ) = 0;
virtual bool isUnseen() const = 0;
virtual time_t lastPlayedDate() const = 0;
virtual ShowEpisodePtr showEpisode() const = 0;
virtual const std::vector<FilePtr>& files() const = 0;
......
......@@ -308,6 +308,12 @@ uint32_t Media::playCount() const
return m_playCount;
}
bool Media::isUnseen() const
{
if ((m_playCount == 0) && (m_lastPosition < 0))
return true;
return false;
}
Media::PositionTypes Media::computePositionType( float position ) const
{
......
......@@ -187,6 +187,7 @@ class Media : public IMedia,
virtual bool removeLabel( LabelPtr label ) override;
virtual Query<ILabel> labels() const override;
virtual uint32_t playCount() const override;
virtual bool isUnseen() const override;
virtual ProgressResult setLastPosition( float lastPosition ) override;
virtual ProgressResult setLastTime( int64_t lastTime ) override;
virtual bool setPlayCount( uint32_t playCount ) override;
......
......@@ -51,6 +51,7 @@ static void Create( Tests* T )
ASSERT_NE( 0u, m->insertionDate() );
ASSERT_TRUE( m->isDiscoveredMedia() );
ASSERT_TRUE( m->isPresent() );
ASSERT_TRUE( m->isUnseen() );
auto files = m->files();
ASSERT_EQ( 1u, files.size() );
......@@ -126,6 +127,7 @@ static void SetProgress( Tests* T )
ASSERT_EQ( expectedPosition, m1->lastPosition() );
ASSERT_EQ( m1->duration() / 2, m1->lastTime() );
ASSERT_EQ( 0u, m1->playCount() );
ASSERT_FALSE( m1->isUnseen() );
/* Then update to a progress to 3%. This should reset it to -1 */
......@@ -138,6 +140,7 @@ static void SetProgress( Tests* T )
ASSERT_EQ( -1, m1->lastTime() );
ASSERT_EQ( -1.f, m1->lastPosition() );
ASSERT_EQ( 0u, m1->playCount() );
ASSERT_TRUE( m1->isUnseen() );
/* Then again at 4% and ensure the progress is still -1 */
res = m1->setLastPosition( 0.04 );
......@@ -147,6 +150,7 @@ static void SetProgress( Tests* T )
m1 = T->ml->media( m1->id() );
ASSERT_EQ( -1, m1->lastTime() );
ASSERT_EQ( -1.f, m1->lastPosition() );
ASSERT_TRUE( m1->isUnseen() );
/*
* Now set a progress of 99% and check the playcount was bumped, and
......@@ -161,7 +165,8 @@ static void SetProgress( Tests* T )
ASSERT_EQ( -1, m1->lastTime() );
ASSERT_EQ( -1.f, m1->lastPosition() );
ASSERT_EQ( 1u, m1->playCount() );
ASSERT_FALSE( m1->isUnseen() );
/* Now do the same with a longer media to ensure the "margin" are updated */
expectedPosition = 0.5f;
res = m2->setLastPosition( expectedPosition );
......@@ -173,6 +178,7 @@ static void SetProgress( Tests* T )
ASSERT_EQ( expectedPosition, m2->lastPosition() );
ASSERT_EQ( m2->duration() / 2, m2->lastTime() );
ASSERT_EQ( 0u, m2->playCount() );
ASSERT_FALSE( m2->isUnseen() );
/* This media should only ignore the first & last percent */
res = m2->setLastPosition( 0.009f );
......@@ -184,6 +190,7 @@ static void SetProgress( Tests* T )
ASSERT_EQ( -1.f, m2->lastPosition() );
ASSERT_EQ( -1, m2->lastTime() );
ASSERT_EQ( 0u, m2->playCount() );
ASSERT_TRUE( m2->isUnseen() );
/* So check 0.01 is not ignored */
expectedPosition = 0.01f;
......@@ -199,6 +206,7 @@ static void SetProgress( Tests* T )
ASSERT_TRUE( m2->lastTime() >= 180000 - 1 &&
m2->lastTime() <= 180000 );
ASSERT_EQ( 0u, m2->playCount() );
ASSERT_FALSE( m2->isUnseen() );
/*
* And finally check that 0.98 is just a regular progress and not the end of
......@@ -216,6 +224,7 @@ static void SetProgress( Tests* T )
ASSERT_TRUE( m2->lastTime() >= 17640000 - 1 &&
m2->lastTime() <= 17640000 );
ASSERT_EQ( 0u, m2->playCount() );
ASSERT_FALSE( m2->isUnseen() );
}
static void SetLastPositionNoDuration( Tests* T )
......@@ -518,6 +527,7 @@ static void RemoveFromHistory( Tests* T )
ASSERT_EQ( 1u, history.size() );
ASSERT_EQ( m->id(), history[0]->id() );
ASSERT_EQ( 1u, m->playCount() );
ASSERT_FALSE( m->isUnseen() );
m->removeFromHistory();
......@@ -531,6 +541,7 @@ static void RemoveFromHistory( Tests* T )
ASSERT_EQ( 0u, m->playCount() );
ASSERT_EQ( -1.f, m->lastPosition() );
ASSERT_EQ( -1, m->lastTime() );
ASSERT_TRUE( m->isUnseen() );
}
static void SetReleaseDate( Tests* T )
......@@ -1142,12 +1153,14 @@ static void SetPlayCount( Tests* T )
{
auto m = T->ml->addMedia( "media.avi", IMedia::Type::Video );
ASSERT_EQ( 0u, m->playCount() );
ASSERT_TRUE( m->isUnseen() );
auto res = m->setPlayCount( 123 );
ASSERT_TRUE( res );
ASSERT_EQ( 123u, m->playCount() );
m = T->ml->media( m->id() );
ASSERT_EQ( 123u, m->playCount() );
ASSERT_FALSE( m->isUnseen() );
}
static void CheckDbModel( Tests* T )
......@@ -1294,6 +1307,7 @@ static void FetchInProgress( Tests* T )
ASSERT_EQ( -1.f, m1->lastPosition() );
ASSERT_EQ( -1, m1->lastTime() );
ASSERT_EQ( 1u, m1->playCount() );
ASSERT_FALSE( m1->isUnseen() );
}
static void ConvertToExternal( Tests* T )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment