Skip to content

Commit

Permalink
add EventReplaceID()
Browse files Browse the repository at this point in the history
  • Loading branch information
aine-etke committed Feb 18, 2025
1 parent d5e5115 commit 0e671f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ run:
issues-exit-code: 1
tests: true
build-tags: []
skip-dirs-use-default: true
skip-files: []
modules-download-mode: readonly

output:
Expand Down Expand Up @@ -118,6 +116,7 @@ linters:


issues:
exclude-dirs-use-default: true
exclude-dirs:
- mocks
exclude-rules:
Expand Down
16 changes: 16 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ func EventRelatesTo(evt *event.Event) *event.RelatesTo {
return RelatesTo(EventParent(evt.ID, relatable))
}

// EventReplaceID returns replace_id of a matrix event (if any)
// i.e. when the evt was replaced by another event, this returns the ID of the replacing event
func EventReplaceID(evt *event.Event) id.EventID {
ParseContent(evt, nil)
relatable, ok := evt.Content.Parsed.(event.Relatable)
if !ok {
return ""
}

relation := relatable.GetRelatesTo()
if relation == nil {
return ""
}
return relation.GetReplaceID()
}

// RelatesTo returns relation object of a matrix event (either threads with reply-to fallback or plain reply-to)
func RelatesTo(parentID id.EventID, noThreads ...bool) *event.RelatesTo {
if parentID == "" {
Expand Down

0 comments on commit 0e671f1

Please sign in to comment.