a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at dev 229 lines 5.2 kB view raw
1using System.Diagnostics.CodeAnalysis; 2 3namespace Iceshrimp.Parsing; 4 5public interface ISearchQueryFilter; 6 7public record WordFilter(bool Negated, string Value) : ISearchQueryFilter; 8 9public record CwFilter(bool Negated, string Value) : ISearchQueryFilter; 10 11public record MultiWordFilter(bool Negated, string[] Values) : ISearchQueryFilter; 12 13public record FromFilter(bool Negated, string Value) : ISearchQueryFilter; 14 15public record MentionFilter(bool Negated, string Value) : ISearchQueryFilter; 16 17public record ReplyFilter(bool Negated, string Value) : ISearchQueryFilter; 18 19public record InstanceFilter(bool Negated, string Value) : ISearchQueryFilter; 20 21public enum MiscFilterType 22{ 23 Followers, 24 Following, 25 Replies, 26 Renotes 27} 28 29public record MiscFilter(bool Negated, MiscFilterType Value) : ISearchQueryFilter 30{ 31 public static bool TryParse(bool negated, ReadOnlySpan<char> value, [NotNullWhen(true)] out MiscFilter? result) 32 { 33 MiscFilterType? type = value switch 34 { 35 "followers" => MiscFilterType.Followers, 36 "following" => MiscFilterType.Following, 37 "replies" => MiscFilterType.Replies, 38 "reply" => MiscFilterType.Replies, 39 "renote" => MiscFilterType.Renotes, 40 "renotes" => MiscFilterType.Renotes, 41 "boosts" => MiscFilterType.Renotes, 42 "boost" => MiscFilterType.Renotes, 43 _ => null 44 }; 45 46 if (!type.HasValue) 47 { 48 result = null; 49 return false; 50 } 51 52 result = new MiscFilter(negated, type.Value); 53 return true; 54 } 55} 56 57public enum InFilterType 58{ 59 Bookmarks, 60 Likes, 61 Reactions, 62 Interactions 63} 64 65public record InFilter(bool Negated, InFilterType Value) : ISearchQueryFilter 66{ 67 public static bool TryParse(bool negated, ReadOnlySpan<char> value, [NotNullWhen(true)] out InFilter? result) 68 { 69 InFilterType? type = value switch 70 { 71 "bookmarks" => InFilterType.Bookmarks, 72 "likes" => InFilterType.Likes, 73 "favorites" => InFilterType.Likes, 74 "favourites" => InFilterType.Likes, 75 "reactions" => InFilterType.Reactions, 76 "interactions" => InFilterType.Interactions, 77 _ => null 78 }; 79 80 if (!type.HasValue) 81 { 82 result = null; 83 return false; 84 } 85 86 result = new InFilter(negated, type.Value); 87 return true; 88 } 89} 90 91public enum AttachmentFilterType 92{ 93 Media, 94 Image, 95 Video, 96 Audio, 97 File, 98 Poll 99} 100 101public record AttachmentFilter(bool Negated, AttachmentFilterType Value) : ISearchQueryFilter 102{ 103 public static bool TryParse( 104 bool negated, ReadOnlySpan<char> value, [NotNullWhen(true)] out AttachmentFilter? result 105 ) 106 { 107 AttachmentFilterType? type = value switch 108 { 109 "any" => AttachmentFilterType.Media, 110 "media" => AttachmentFilterType.Media, 111 "image" => AttachmentFilterType.Image, 112 "video" => AttachmentFilterType.Video, 113 "audio" => AttachmentFilterType.Audio, 114 "file" => AttachmentFilterType.File, 115 "poll" => AttachmentFilterType.Poll, 116 _ => null 117 }; 118 119 if (!type.HasValue) 120 { 121 result = null; 122 return false; 123 } 124 125 result = new AttachmentFilter(negated, type.Value); 126 return true; 127 } 128} 129 130public record AfterFilter(DateOnly Value) : ISearchQueryFilter; 131 132public record BeforeFilter(DateOnly Value) : ISearchQueryFilter; 133 134public enum VisibilityFilterType 135{ 136 Public, 137 Home, 138 Followers, 139 Specified, 140 Local 141} 142 143public record VisibilityFilter(bool Negated, VisibilityFilterType Value) : ISearchQueryFilter 144{ 145 public static bool TryParse( 146 bool negated, ReadOnlySpan<char> value, [NotNullWhen(true)] out VisibilityFilter? result 147 ) 148 { 149 VisibilityFilterType? type = value switch 150 { 151 "public" => VisibilityFilterType.Public, 152 "home" => VisibilityFilterType.Home, 153 "unlisted" => VisibilityFilterType.Home, 154 "followers" => VisibilityFilterType.Followers, 155 "specified" => VisibilityFilterType.Specified, 156 "direct" => VisibilityFilterType.Specified, 157 "private" => VisibilityFilterType.Specified, 158 "local" => VisibilityFilterType.Local, 159 _ => null 160 }; 161 162 if (!type.HasValue) 163 { 164 result = null; 165 return false; 166 } 167 168 result = new VisibilityFilter(negated, type.Value); 169 return true; 170 } 171} 172 173public enum CaseFilterType 174{ 175 Sensitive, 176 Insensitive 177} 178 179public record CaseFilter(CaseFilterType Value) : ISearchQueryFilter 180{ 181 public static bool TryParse(ReadOnlySpan<char> value, [NotNullWhen(true)] out CaseFilter? result) 182 { 183 CaseFilterType? type = value switch 184 { 185 "sensitive" => CaseFilterType.Sensitive, 186 "insensitive" => CaseFilterType.Insensitive, 187 _ => null 188 }; 189 190 if (!type.HasValue) 191 { 192 result = null; 193 return false; 194 } 195 196 result = new CaseFilter(type.Value); 197 return true; 198 } 199} 200 201public enum MatchFilterType 202{ 203 Words, 204 Substring 205} 206 207public record MatchFilter(MatchFilterType Value) : ISearchQueryFilter 208{ 209 public static bool TryParse(ReadOnlySpan<char> value, [NotNullWhen(true)] out MatchFilter? result) 210 { 211 MatchFilterType? type = value switch 212 { 213 "words" => MatchFilterType.Words, 214 "word" => MatchFilterType.Words, 215 "substring" => MatchFilterType.Substring, 216 "substr" => MatchFilterType.Substring, 217 _ => null 218 }; 219 220 if (!type.HasValue) 221 { 222 result = null; 223 return false; 224 } 225 226 result = new MatchFilter(type.Value); 227 return true; 228 } 229}