apply label

This commit is contained in:
Adam R Grey 2023-04-04 13:52:10 -04:00
parent 60eb4a61b9
commit f224aa8506

View File

@ -37,7 +37,7 @@ namespace ttrss_co_client.ttrss
if (loginResult.status == 0)
{
SessionId = loginResult.Content.session_id;
if(loginResult.Content.api_level == null)
if (loginResult.Content.api_level == null)
{
throw new NotImplementedException($"api doesn't report an api level - unsupported. api level 1 is version 1.5.8, so {BaseURI} might be extremely old. (or maybe this library is extremely old and ttrss changed again?)");
}
@ -45,7 +45,7 @@ namespace ttrss_co_client.ttrss
{
api_level = loginResult.Content.api_level.Value;
}
Console.WriteLine(SessionId);
}
else
@ -66,6 +66,7 @@ namespace ttrss_co_client.ttrss
//???? = 7
//???? = 8
//1.14 = 9
//1.15 = 10
assertInitialized();
return await getOneValue<int>("getApiLevel", "level");
}
@ -111,12 +112,12 @@ namespace ttrss_co_client.ttrss
///<param name="limit">0 for all</param>
///<param name="offset">skip this amount first</param>
///<param name="include_nested">idk, doesn't affect what the documentation says it should</param>
public async Task<IEnumerable<Feed>> GetFeeds(int cat_id = 0, bool unread_only=false, uint limit = 0, int offset = 0/*, bool include_nested*/)
public async Task<IEnumerable<Feed>> GetFeeds(int cat_id = 0, bool unread_only = false, uint limit = 0, int offset = 0/*, bool include_nested*/)
{
assertInitialized();
if(cat_id <-2)
if (cat_id < -2)
{
if(cat_id == -3 || cat_id == -4)
if (cat_id == -3 || cat_id == -4)
{
assertApiLevel(4);
}
@ -143,7 +144,7 @@ namespace ttrss_co_client.ttrss
public async Task<IEnumerable<Category>> GetCategories(bool unread_only = false, bool enable_nested = false, bool include_empty = false)
{
assertInitialized();
var json = JsonContent.Create(new
{
op = "getCategories",
@ -161,11 +162,11 @@ namespace ttrss_co_client.ttrss
public async Task<IEnumerable<Headline>> GetHeadlines(
int feed_id,
bool is_cat,
int limit=60,
int skip=0,
int limit = 60,
int skip = 0,
/*string filter,*/
bool show_excerpt = false,
bool show_content=false,
bool show_content = false,
VIEWMODE view_mode = VIEWMODE.All,
bool include_attachments = false,
int? since_id = null,
@ -175,16 +176,16 @@ namespace ttrss_co_client.ttrss
bool force_update = false,
bool has_sandbox = false)
{
if(limit>60)
if (limit > 60)
{
assertApiLevel(6);
}
if(limit > 200)
if (limit > 200)
{
throw new ArgumentOutOfRangeException("limit", limit, "capped at 200");
}
if(include_nested)
if (include_nested)
{
assertApiLevel(4);
}
@ -204,12 +205,12 @@ namespace ttrss_co_client.ttrss
}
}
if(sanitize == false)
if (sanitize == false)
{
//TODO: it's version 1.8.0, but no idea what version that is. I can narrow it down to 6, 7, or 8.
assertApiLevel(6);
}
if(force_update)
if (force_update)
{
assertApiLevel(9);
}
@ -237,11 +238,11 @@ namespace ttrss_co_client.ttrss
}
public async Task<IEnumerable<Headline>> GetHeadlinesTag(
string tag,
int limit=200,
int skip=0,
int limit = 200,
int skip = 0,
/*string filter,*/
bool show_excerpt = false,
bool show_content=false,
bool show_content = false,
VIEWMODE view_mode = VIEWMODE.All,
bool include_attachments = false,
int? since_id = null,
@ -254,13 +255,13 @@ namespace ttrss_co_client.ttrss
{
assertApiLevel(18);
if(limit > 200)
if (limit > 200)
{
throw new ArgumentOutOfRangeException("limit", limit, "capped at 200");
}
string sortOrderString;
switch(order_by)
switch (order_by)
{
case SORTORDER.OldestFirst:
sortOrderString = "date_reverse";
@ -429,11 +430,11 @@ namespace ttrss_co_client.ttrss
// }
#endregion
///<summary>to update note, see <see cref="UpdateArticleNote"/></summary>
public enum UPDATEFIELD { starred=0, published=1, unread=2 }
public enum UPDATEMODE { SetFalse=0, SetTrue=1, Toggle=2 }
public async Task<int> UpdateArticleField(UPDATEFIELD field, UPDATEMODE mode, params int[] ids)
public enum UPDATEFIELD { starred = 0, published = 1, unread = 2 }
public enum UPDATEMODE { SetFalse = 0, SetTrue = 1, Toggle = 2 }
public async Task<int> UpdateArticleField(UPDATEFIELD field, UPDATEMODE mode, params int[] ids)
{
if(ids == null || ids.Length == 0)
if (ids == null || ids.Length == 0)
{
throw new System.ArgumentNullException("ids", "need to specify at least one id");
}
@ -457,7 +458,7 @@ namespace ttrss_co_client.ttrss
///<summary>for fields other than note, we have a separate method UpdateArticleField</summary>
public async Task<int> UpdateArticleNote(string data, params int[] ids)
{
if(ids == null || ids.Length == 0)
if (ids == null || ids.Length == 0)
{
throw new System.ArgumentNullException("ids", "need to specify at least one id");
}
@ -516,7 +517,7 @@ namespace ttrss_co_client.ttrss
feed_id = feed_id
});
var apiResponse = await get<Dictionary<string, string>>(json);
return apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok";
}
public async Task<T> GetPref<T>(string pref)
@ -551,7 +552,7 @@ namespace ttrss_co_client.ttrss
assertInitialized();
var modestring = "all";
if(mode != CATCHUPMODE.All)
if (mode != CATCHUPMODE.All)
{
assertApiLevel(15);
switch (mode)
@ -577,10 +578,10 @@ namespace ttrss_co_client.ttrss
mode = modestring
});
var apiResponse = await get<Dictionary<string, string>>(json);
return apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok";
}
public async Task<IEnumerable<Label>> GetLabels(int? article_id)
public async Task<IEnumerable<Label>> GetLabels(int? article_id = null)
{
assertInitialized();
@ -591,20 +592,58 @@ namespace ttrss_co_client.ttrss
article_id = article_id
});
var labels = await get<IEnumerable<Label>>(json);
if(this.api_level < 5)
if (this.api_level < 5)
{
foreach(var l in labels)
foreach (var l in labels)
{
l.id = -11 - l.id;
}
}
return labels;
}
public async Task SetArticleLabel(int label_id, bool assign, params int[] article_ids)
public async Task<int> SetArticleLabel(int label_id, bool assign, params int[] article_ids)
{
//there's a label "cache", i guess?
if (article_ids == null || article_ids.Length == 0)
{
throw new System.ArgumentNullException("ids", "need to specify at least one id");
}
assertInitialized();
throw new NotImplementedException();
var json = JsonContent.Create(new
{
op = "setArticleLabel",
sid = this.SessionId,
article_ids = string.Join(',', article_ids),
label_id = label_id,
assign = assign
});
var apiResponse = await get<Dictionary<string, string>>(json);
if (!apiResponse.ContainsKey("status") && apiResponse["status"]?.ToLower() == "ok")
{
return 0;
}
if (this.api_level <= 10)
{
//update label cache
var tasks = new List<Task>();
foreach (var id in article_ids)
{
tasks.Add(GetLabels(id));
}
Task.WaitAll(tasks.ToArray());
}
int toReturn;
if (int.TryParse(apiResponse["updated"], out toReturn))
{
return toReturn;
}
else
{
throw new Exception("update ostensibly ok, but couldn't parse");
}
}
public async Task ShareToPublished(string title, Uri url, string content, bool sanitize = true)
{