mirror of
https://github.com/status-im/status-console-client.git
synced 2025-02-25 17:15:14 +00:00
It allows not to block producer when there are not consumers. And it allows to have more then one consumer in different parts of the application.
34 lines
706 B
Go
34 lines
706 B
Go
package client
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/event"
|
|
"github.com/status-im/status-console-client/protocol/v1"
|
|
)
|
|
|
|
type DatabaseWithEvents struct {
|
|
Database
|
|
feed *event.Feed
|
|
}
|
|
|
|
func NewDatabaseWithEvents(db Database, feed *event.Feed) DatabaseWithEvents {
|
|
return DatabaseWithEvents{Database: db, feed: feed}
|
|
}
|
|
|
|
func (db DatabaseWithEvents) SaveMessages(c Contact, msgs []*protocol.Message) (int64, error) {
|
|
rowid, err := db.Database.SaveMessages(c, msgs)
|
|
if err != nil {
|
|
return rowid, err
|
|
}
|
|
for _, m := range msgs {
|
|
ev := messageEvent{
|
|
baseEvent: baseEvent{
|
|
Contact: c,
|
|
Type: EventTypeMessage,
|
|
},
|
|
Message: m,
|
|
}
|
|
db.feed.Send(Event{ev})
|
|
}
|
|
return rowid, err
|
|
}
|