From 037e5aa21efef48103ca1fea379691a7a692208b Mon Sep 17 00:00:00 2001 From: Et0h Date: Sat, 23 Jan 2016 13:42:44 +0000 Subject: [PATCH] Refactor updateUndoPlaylistBuffer --- syncplay/client.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index d439b7b..391bb6d 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -531,11 +531,7 @@ class SyncplayClient(object): except: newIndex = 0 - if self._previousPlaylistRoom <> self.userlist.currentUser.room: - self._previousPlaylist = None - self._previousPlaylistRoom = self.userlist.currentUser.room - elif self._previousPlaylist <> self._playlist and self._playlist <> files: - self._previousPlaylist = self._playlist + self.updateUndoPlaylistBuffer(currentPlaylist=self._playlist, newPlaylist=files) self._playlist = files if username is None and self._protocol and self._protocol.logged: @@ -547,6 +543,22 @@ class SyncplayClient(object): self.changeToPlaylistIndex(newIndex, username) self.ui.showMessage(u"{} updated the playlist".format(username)) + def updateUndoPlaylistBuffer(self, currentPlaylist, newPlaylist): + if self.playlistBufferIsFromOldRoom(): + self.movePlaylistBufferToNewRoom() + elif self.playlistBufferNeedsUpdating(currentPlaylist, newPlaylist): + self._previousPlaylist = currentPlaylist + + def playlistBufferIsFromOldRoom(self): + return self._previousPlaylistRoom <> self.userlist.currentUser.room + + def movePlaylistBufferToNewRoom(self): + self._previousPlaylist = None + self._previousPlaylistRoom = self.userlist.currentUser.room + + def playlistBufferNeedsUpdating(self, currentPlaylist, newPlaylist): + return self._previousPlaylist <> currentPlaylist and currentPlaylist <> newPlaylist + @needsSharedPlaylistsEnabled def undoPlaylistChange(self): if self._previousPlaylist is not None and self._playlist <> self._previousPlaylist: