try to find parent email by Message-Id and references
This commit is contained in:
38
bot/email.go
38
bot/email.go
@@ -92,8 +92,8 @@ func (b *Bot) IncomingEmail(ctx context.Context, email *utils.Email) error {
|
|||||||
defer b.unlock(roomID)
|
defer b.unlock(roomID)
|
||||||
|
|
||||||
var threadID id.EventID
|
var threadID id.EventID
|
||||||
if email.InReplyTo != "" && !cfg.NoThreads() {
|
if email.InReplyTo != "" || email.References != "" {
|
||||||
threadID = b.getThreadID(roomID, email.InReplyTo)
|
threadID = b.getThreadID(roomID, email.InReplyTo, email.References)
|
||||||
if threadID != "" {
|
if threadID != "" {
|
||||||
b.setThreadID(roomID, email.MessageID, threadID)
|
b.setThreadID(roomID, email.MessageID, threadID)
|
||||||
}
|
}
|
||||||
@@ -104,11 +104,9 @@ func (b *Bot) IncomingEmail(ctx context.Context, email *utils.Email) error {
|
|||||||
return utils.UnwrapError(serr)
|
return utils.UnwrapError(serr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if threadID == "" && !cfg.NoThreads() {
|
b.setThreadID(roomID, email.MessageID, eventID)
|
||||||
b.setThreadID(roomID, email.MessageID, eventID)
|
|
||||||
threadID = eventID
|
|
||||||
}
|
|
||||||
b.setLastEventID(roomID, threadID, eventID)
|
b.setLastEventID(roomID, threadID, eventID)
|
||||||
|
threadID = eventID
|
||||||
|
|
||||||
if !cfg.NoFiles() {
|
if !cfg.NoFiles() {
|
||||||
b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
|
b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
|
||||||
@@ -257,18 +255,28 @@ func (b *Bot) sendFiles(ctx context.Context, roomID id.RoomID, files []*utils.Fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) getThreadID(roomID id.RoomID, messageID string) id.EventID {
|
func (b *Bot) getThreadID(roomID id.RoomID, messageID string, references string) id.EventID {
|
||||||
key := acMessagePrefix + "." + messageID
|
refs := []string{messageID}
|
||||||
data := map[string]id.EventID{}
|
if references != "" {
|
||||||
err := b.lp.GetClient().GetRoomAccountData(roomID, key, &data)
|
refs = append(refs, strings.Split(references, " ")...)
|
||||||
if err != nil {
|
}
|
||||||
if !strings.Contains(err.Error(), "M_NOT_FOUND") {
|
|
||||||
b.log.Error("cannot retrieve account data %s: %v", key, err)
|
for _, refID := range refs {
|
||||||
return ""
|
key := acMessagePrefix + "." + refID
|
||||||
|
data := map[string]id.EventID{}
|
||||||
|
err := b.lp.GetClient().GetRoomAccountData(roomID, key, &data)
|
||||||
|
if err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "M_NOT_FOUND") {
|
||||||
|
b.log.Error("cannot retrieve account data %s: %v", key, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data["eventID"] != "" {
|
||||||
|
return data["eventID"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data["eventID"]
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) setThreadID(roomID id.RoomID, messageID string, eventID id.EventID) {
|
func (b *Bot) setThreadID(roomID id.RoomID, messageID string, eventID id.EventID) {
|
||||||
|
|||||||
Reference in New Issue
Block a user