feat(GODT-2800): User Event Service

This patch adds the User Event Service which is meant to replace the
current event polling flow.

Each user interested in receiving events should register a new
subscriber using the `Service.Subscribe` function and then react on
the incoming events.

The current patch does not hook this up Bridge user as there are no
existing consumers, but it does provide extensive testing for the
expected behavior.
This commit is contained in:
Leander Beernaert
2023-07-19 12:48:09 +02:00
parent 110286b81c
commit 82efa16d65
13 changed files with 2224 additions and 1 deletions

View File

@ -0,0 +1,40 @@
// Copyright (c) 2023 Proton AG
//
// This file is part of Proton Mail Bridge.
//
// Proton Mail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Proton Mail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
package userevents
import (
"context"
"github.com/ProtonMail/go-proton-api"
)
// EventSource represents a type which produces proton events.
type EventSource interface {
GetLatestEventID(ctx context.Context) (string, error)
GetEvent(ctx context.Context, id string) ([]proton.Event, bool, error)
}
type NullEventSource struct{}
func (n NullEventSource) GetLatestEventID(_ context.Context) (string, error) {
return "", nil
}
func (n NullEventSource) GetEvent(_ context.Context, _ string) ([]proton.Event, bool, error) {
return nil, false, nil
}