Skip to content

Commit 0f06c9c

Browse files
committed
event/content: add SetThread method
1 parent cf80172 commit 0f06c9c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

event/relations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (rel *RelatesTo) SetReplace(mxid id.EventID) *RelatesTo {
101101
}
102102

103103
func (rel *RelatesTo) SetReplyTo(mxid id.EventID) *RelatesTo {
104+
if rel.Type != RelThread {
105+
rel.Type = ""
106+
rel.EventID = ""
107+
}
104108
rel.InReplyTo = &InReplyTo{EventID: mxid}
105109
rel.IsFallingBack = false
106110
return rel

event/reply.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,27 @@ func (content *MessageEventContent) GetReplyTo() id.EventID {
4747
}
4848

4949
func (content *MessageEventContent) SetReply(inReplyTo *Event) {
50-
content.RelatesTo = (&RelatesTo{}).SetReplyTo(inReplyTo.ID)
50+
if content.RelatesTo == nil {
51+
content.RelatesTo = &RelatesTo{}
52+
}
53+
content.RelatesTo.SetReplyTo(inReplyTo.ID)
54+
if content.Mentions == nil {
55+
content.Mentions = &Mentions{}
56+
}
57+
content.Mentions.Add(inReplyTo.Sender)
58+
}
59+
60+
func (content *MessageEventContent) SetThread(inReplyTo *Event) {
61+
root := inReplyTo.ID
62+
relatable, ok := inReplyTo.Content.Parsed.(Relatable)
63+
if ok {
64+
targetRoot := relatable.OptionalGetRelatesTo().GetThreadParent()
65+
if targetRoot != "" {
66+
root = targetRoot
67+
}
68+
}
69+
if content.RelatesTo == nil {
70+
content.RelatesTo = &RelatesTo{}
71+
}
72+
content.RelatesTo.SetThread(root, inReplyTo.ID)
5173
}

0 commit comments

Comments
 (0)