emoji signaling

This commit is contained in:
Aine
2023-10-19 10:31:14 +03:00
parent d3aaa5c060
commit f2e032e1e8
13 changed files with 170 additions and 42 deletions

View File

@@ -608,8 +608,8 @@ func (b *Bot) runSendCommand(ctx context.Context, cfg config.Room, tos []string,
}
}
b.mu.Lock(evt.RoomID.String())
defer b.mu.Unlock(evt.RoomID.String())
b.lock(evt.RoomID, evt.ID)
defer b.unlock(evt.RoomID, evt.ID)
domain := utils.SanitizeDomain(cfg.Domain())
from := cfg.Mailbox() + "@" + domain

View File

@@ -56,15 +56,19 @@ func (b *Bot) shouldQueue(msg string) bool {
// Sendmail tries to send email immediately, but if it gets 4xx error (greylisting),
// the email will be added to the queue and retried several times after that
func (b *Bot) Sendmail(eventID id.EventID, from, to, data string) (bool, error) {
log := b.log.With().Str("from", from).Str("to", to).Str("eventID", eventID.String()).Logger()
log.Info().Msg("attempting to deliver email")
err := b.sendmail(from, to, data)
if err != nil {
if b.shouldQueue(err.Error()) {
b.log.Info().Err(err).Str("id", eventID.String()).Str("from", from).Str("to", to).Msg("email has been added to the queue")
log.Info().Err(err).Msg("email has been added to the queue")
return true, b.q.Add(eventID.String(), from, to, data)
}
log.Warn().Err(err).Msg("email delivery failed")
return false, err
}
log.Warn().Err(err).Msg("email delivery succeeded")
return false, nil
}
@@ -286,8 +290,8 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
return
}
b.mu.Lock(evt.RoomID.String())
defer b.mu.Unlock(evt.RoomID.String())
b.lock(evt.RoomID, evt.ID)
defer b.unlock(evt.RoomID, evt.ID)
meta := b.getParentEmail(evt, mailbox)

29
bot/mutex.go Normal file
View File

@@ -0,0 +1,29 @@
package bot
import (
"maunium.net/go/mautrix/id"
)
func (b *Bot) lock(roomID id.RoomID, optionalEventID ...id.EventID) {
b.mu.Lock(roomID.String())
if len(optionalEventID) == 0 {
return
}
evtID := optionalEventID[0]
if _, err := b.lp.GetClient().SendReaction(roomID, evtID, "📨"); err != nil {
b.log.Error().Err(err).Str("roomID", roomID.String()).Str("eventID", evtID.String()).Msg("cannot send reaction on lock")
}
}
func (b *Bot) unlock(roomID id.RoomID, optionalEventID ...id.EventID) {
b.mu.Unlock(roomID.String())
if len(optionalEventID) == 0 {
return
}
evtID := optionalEventID[0]
if _, err := b.lp.GetClient().SendReaction(roomID, evtID, "✅"); err != nil {
b.log.Error().Err(err).Str("roomID", roomID.String()).Str("eventID", evtID.String()).Msg("cannot send reaction on unlock")
}
}