about summary refs log tree commit diff
path: root/LibMatrix/Extensions/EnumerableExtensions.cs
blob: 7a810ac4140c2b1621595bcd866d3d89ed096582 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace LibMatrix.Extensions;

public static class EnumerableExtensions {
#if !DISABLE_LEGACY_EVENTS
    public static void MergeStateEventLists(this IList<LegacyMatrixEvent> oldState, IList<LegacyMatrixEvent> 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 IList<LegacyMatrixEventResponse> oldState, IList<LegacyMatrixEventResponse> 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);
        }
    }
#endif
}