diff options
Diffstat (limited to 'LibMatrix/Extensions/EnumerableExtensions.cs')
-rw-r--r-- | LibMatrix/Extensions/EnumerableExtensions.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/LibMatrix/Extensions/EnumerableExtensions.cs b/LibMatrix/Extensions/EnumerableExtensions.cs new file mode 100644 index 0000000..d9619b7 --- /dev/null +++ b/LibMatrix/Extensions/EnumerableExtensions.cs @@ -0,0 +1,28 @@ +namespace LibMatrix.Extensions; + +public static class EnumerableExtensions { + public static void MergeStateEventLists(this List<StateEvent> oldState, List<StateEvent> newState) { + foreach (var stateEvent in newState) { + var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey); + if (old is null) { + oldState.Add(stateEvent); + continue; + } + oldState.Remove(old); + oldState.Add(stateEvent); + } + } + + public static void MergeStateEventLists(this List<StateEventResponse> oldState, List<StateEventResponse> newState) { + foreach (var stateEvent in newState) { + var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey); + if (old is null) { + oldState.Add(stateEvent); + continue; + } + oldState.Remove(old); + oldState.Add(stateEvent); + } + } + +} |