Problem: no events is sent when a channel is created

Solution: fix bug when checking if channel was created
This commit is contained in:
Peter Stuifzand 2022-04-16 23:55:10 +02:00
parent 6bf8417451
commit 13484d1834
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -186,7 +186,7 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
for {
varMicrosub.Add("ChannelsCreate.RandStringBytes", 1)
channel.UID = util.RandStringBytes(24)
result, err := b.database.Exec(`insert into "channels" ("uid", "name", "created_at") values($1, $2, DEFAULT)`, channel.UID, channel.Name)
result, err := b.database.Exec(`insert into "channels" ("uid", "name", "created_at") values ($1, $2, DEFAULT)`, channel.UID, channel.Name)
if err != nil {
log.Println("channels insert", err)
if !shouldRetryWithNewUID(err, try) {
@ -195,7 +195,7 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
try++
continue
}
if n, err := result.RowsAffected(); err != nil {
if n, err := result.RowsAffected(); err == nil {
if n > 0 {
b.broker.Notifier <- sse.Message{Event: "new channel", Object: channelMessage{1, channel}}
}