Skip to content

Instantly share code, notes, and snippets.

/diff

Created April 14, 2016 18:44
Show Gist options
  • Save anonymous/484c6c0ed3bdea96648469af15acd7a9 to your computer and use it in GitHub Desktop.
Save anonymous/484c6c0ed3bdea96648469af15acd7a9 to your computer and use it in GitHub Desktop.
add query value 'has_media' patch for Krile 3.0
diff --git a/StarryEyes/Filters/Expressions/Values/Statuses/Booleans.cs b/StarryEyes/Filters/Expressions/Values/Statuses/Booleans.cs
index 39b2227..cc166d6 100644
--- a/StarryEyes/Filters/Expressions/Values/Statuses/Booleans.cs
+++ b/StarryEyes/Filters/Expressions/Values/Statuses/Booleans.cs
@@ -1,4 +1,5 @@
<U+FEFF>using System;
+using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using StarryEyes.Anomaly.TwitterApi.DataModels;
@@ -51,4 +52,29 @@ namespace StarryEyes.Filters.Expressions.Values.Statuses
}
}
+ public sealed class StatusHasMedia : ValueBase^M
+ {^M
+ public override IEnumerable<FilterExpressionType> SupportedTypes^M
+ {^M
+ get^M
+ {^M
+ yield return FilterExpressionType.Boolean;^M
+ }^M
+ }^M
+^M
+ public override Func<TwitterStatus, bool> GetBooleanValueProvider()^M
+ {^M
+ return _ => _.Entities.Aggregate(false, (acc, e) => acc || e.EntityType == EntityType.Media);^M
+ }^M
+^M
+ public override string GetBooleanSqlQuery()^M
+ {^M
+ return "(SELECT COUNT(Id) FROM StatusEntity WHERE StatusEntity.ParentId = Status.Id) > 0";^M
+ }^M
+^M
+ public override string ToQuery()^M
+ {^M
+ return "has_media";^M
+ }^M
+ }
}
diff --git a/StarryEyes/Filters/Parsing/QueryCompiler.cs b/StarryEyes/Filters/Parsing/QueryCompiler.cs
index 92388db..a286ab2 100644
--- a/StarryEyes/Filters/Parsing/QueryCompiler.cs
+++ b/StarryEyes/Filters/Parsing/QueryCompiler.cs
@@ -678,6 +678,8 @@ namespace StarryEyes.Filters.Parsing
case "source":
case "client":
return new StatusSource();
+ case "has_media":
+ return new StatusHasMedia();
default:
throw CreateUnexpectedTokenError(value, value + " " + reader.RemainQuery);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment