resolveConflicts resolves a list of conflicted state entries. It takes two lists. The first is a list of all state entries that are not conflicted. The second is a list of all state entries that are conflicted A state entry is conflicted when there is more than one numeric event ID for the same stat
( ctx context.Context, notConflicted, conflicted []types.StateEntry, )
| 789 | // The returned list is sorted by state key tuple. |
| 790 | // Returns an error if there was a problem talking to the database. |
| 791 | func (v *StateResolution) resolveConflictsV1( |
| 792 | ctx context.Context, |
| 793 | notConflicted, conflicted []types.StateEntry, |
| 794 | ) ([]types.StateEntry, error) { |
| 795 | span, ctx := opentracing.StartSpanFromContext(ctx, "StateResolution.resolveConflictsV1") |
| 796 | defer span.Finish() |
| 797 | |
| 798 | // Load the conflicted events |
| 799 | conflictedEvents, eventIDMap, err := v.loadStateEvents(ctx, conflicted) |
| 800 | if err != nil { |
| 801 | return nil, err |
| 802 | } |
| 803 | |
| 804 | // Work out which auth events we need to load. |
| 805 | needed := gomatrixserverlib.StateNeededForAuth(conflictedEvents) |
| 806 | |
| 807 | // Find the numeric IDs for the necessary state keys. |
| 808 | var neededStateKeys []string |
| 809 | neededStateKeys = append(neededStateKeys, needed.Member...) |
| 810 | neededStateKeys = append(neededStateKeys, needed.ThirdPartyInvite...) |
| 811 | stateKeyNIDMap, err := v.db.EventStateKeyNIDs(ctx, neededStateKeys) |
| 812 | if err != nil { |
| 813 | return nil, err |
| 814 | } |
| 815 | |
| 816 | // Load the necessary auth events. |
| 817 | tuplesNeeded := v.stateKeyTuplesNeeded(stateKeyNIDMap, needed) |
| 818 | var authEntries []types.StateEntry |
| 819 | for _, tuple := range tuplesNeeded { |
| 820 | if eventNID, ok := stateEntryMap(notConflicted).lookup(tuple); ok { |
| 821 | authEntries = append(authEntries, types.StateEntry{ |
| 822 | StateKeyTuple: tuple, |
| 823 | EventNID: eventNID, |
| 824 | }) |
| 825 | } |
| 826 | } |
| 827 | authEvents, _, err := v.loadStateEvents(ctx, authEntries) |
| 828 | if err != nil { |
| 829 | return nil, err |
| 830 | } |
| 831 | |
| 832 | // Resolve the conflicts. |
| 833 | resolvedEvents := gomatrixserverlib.ResolveStateConflicts(conflictedEvents, authEvents) |
| 834 | |
| 835 | // Map from the full events back to numeric state entries. |
| 836 | for _, resolvedEvent := range resolvedEvents { |
| 837 | entry, ok := eventIDMap[resolvedEvent.EventID()] |
| 838 | if !ok { |
| 839 | panic(fmt.Errorf("missing state entry for event ID %q", resolvedEvent.EventID())) |
| 840 | } |
| 841 | notConflicted = append(notConflicted, entry) |
| 842 | } |
| 843 | |
| 844 | // Sort the result so it can be searched. |
| 845 | sort.Sort(stateEntrySorter(notConflicted)) |
| 846 | return notConflicted, nil |
| 847 | } |
| 848 |
no test coverage detected