Permalink
Browse files

[F] Add a flag to AddFileToMyList, so we can skip reading. Fix Updati…

…ng Watched states (probably)
  • Loading branch information...
da3dsoul committed Jul 19, 2018
1 parent ca96722 commit 691f6b5ecae875dd465134c09d55b8a092d997be
Showing with 34 additions and 26 deletions.
  1. +14 −15 Shoko.Server/AniDBHelper.cs
  2. +20 −11 Shoko.Server/Commands/AniDB/CommandRequest_AddFileToMyList.cs
@@ -543,20 +543,7 @@ public void UpdateMyListFileStatus(IHash hash, bool watched, DateTime? watchedDa
if (watched && watchedDate == null) watchedDate = DateTime.Now;

enHelperActivityType ev;
if (hash.MyListID == 0)
{
logger.Trace($"File has no MyListID, attempting to add: {hash.ED2KHash}");
// Run sychronously, but still do all of the stuff with watched state settings
CommandRequest_AddFileToMyList addcmd = new CommandRequest_AddFileToMyList(hash.ED2KHash);
// Initialize private parts
addcmd.LoadFromDBCommand(addcmd.ToDatabaseObject());
addcmd.ProcessCommand();

SVR_VideoLocal vid = RepoFactory.VideoLocal.GetByHash(hash.ED2KHash);
if (vid == null) return;
hash.MyListID = vid.MyListID;
}

// We have the ID, so update it
if (hash.MyListID > 0)
{
cmdUpdateFile.Init(hash, watched, watchedDate);
@@ -567,7 +554,19 @@ public void UpdateMyListFileStatus(IHash hash, bool watched, DateTime? watchedDa
}
else
{
logger.Trace($"File still has no MyListID: {hash.ED2KHash}");
logger.Trace($"File has no MyListID, attempting to add: {hash.ED2KHash}");
// We don't have the MyListID, so we'll act like it's not there, and AniDB will tell us
ev = enHelperActivityType.NoSuchMyListFile;
}

if (ev == enHelperActivityType.NoSuchMyListFile)
{
// Run synchronously, but still do all of the stuff with Trakt and whatnot
// We are skipping the watched state settings, as we are setting them here
CommandRequest_AddFileToMyList addcmd = new CommandRequest_AddFileToMyList(hash.ED2KHash, false);
// Initialize private parts
addcmd.LoadFromDBCommand(addcmd.ToDatabaseObject());
addcmd.ProcessCommand();
}
}
}
@@ -16,6 +16,8 @@ namespace Shoko.Server.Commands
public class CommandRequest_AddFileToMyList : CommandRequestImplementation
{
public string Hash { get; set; }
public bool ReadStates { get; set; } = true;


[NonSerialized]
private SVR_VideoLocal vid;
@@ -44,17 +46,18 @@ public CommandRequest_AddFileToMyList()
{
}

public CommandRequest_AddFileToMyList(string hash)
public CommandRequest_AddFileToMyList(string hash, bool readstate = true)
{
Hash = hash;
ReadStates = readstate;
Priority = (int) DefaultPriority;

GenerateCommandID();
}

public override void ProcessCommand()
{
logger.Info($"Processing CommandRequest_AddFileToMyList: {vid.FileName} - {vid.Hash}");
logger.Info($"Processing CommandRequest_AddFileToMyList: {vid?.FileName} - {Hash} - {ReadStates}");


try
@@ -105,16 +108,19 @@ public override void ProcessCommand()
bool watchedLocally = vid.GetUserRecord(juser.JMMUserID)?.WatchedDate != null;
bool watchedChanged = watched != watchedLocally;

// handle import watched settings. Don't update AniDB in either case, we'll do that with the storage state
if (ServerSettings.AniDB_MyList_ReadWatched && watched && !watchedLocally)
{
vid.ToggleWatchedStatus(true, false, watchedDate, false, juser.JMMUserID,
false, false);
}
else if (ServerSettings.AniDB_MyList_ReadUnwatched && !watched && watchedLocally)
if (ReadStates)
{
vid.ToggleWatchedStatus(false, false, watchedDate, false, juser.JMMUserID,
false, false);
// handle import watched settings. Don't update AniDB in either case, we'll do that with the storage state
if (ServerSettings.AniDB_MyList_ReadWatched && watched && !watchedLocally)
{
vid.ToggleWatchedStatus(true, false, watchedDate, false, juser.JMMUserID,
false, false);
}
else if (ServerSettings.AniDB_MyList_ReadUnwatched && !watched && watchedLocally)
{
vid.ToggleWatchedStatus(false, false, watchedDate, false, juser.JMMUserID,
false, false);
}
}

// We should have a MyListID at this point, so hopefully this will prevent looping
@@ -175,6 +181,9 @@ public override bool LoadFromDBCommand(CommandRequest cq)

// populate the fields
Hash = TryGetProperty(docCreator, "CommandRequest_AddFileToMyList", "Hash");
string read = TryGetProperty(docCreator, "CommandRequest_AddFileToMyList", "ReadStates");
if (!bool.TryParse(read, out bool read_states)) read_states = true;
ReadStates = read_states;
}

if (Hash.Trim().Length <= 0) return false;

0 comments on commit 691f6b5

Please sign in to comment.