feat: Added chat when MySQL is in use
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -157,6 +158,7 @@ func (a *App) GetOnlineOperators() ([]ChatPresence, error) {
|
||||
func (a *App) chatLoop() {
|
||||
defer func() { _ = recover() }()
|
||||
var lastID int64 = -1 // -1 = not yet baselined
|
||||
var lastDB *sql.DB // logbook the baseline belongs to
|
||||
lastPresence := time.Time{}
|
||||
lastPurge := time.Time{}
|
||||
t := time.NewTicker(chatPollInterval)
|
||||
@@ -164,8 +166,15 @@ func (a *App) chatLoop() {
|
||||
for range t.C {
|
||||
if !a.chatActive() {
|
||||
lastID = -1 // re-baseline if the backend changes
|
||||
lastDB = nil
|
||||
continue
|
||||
}
|
||||
// Profile switch swaps the logbook under us: re-baseline against the new
|
||||
// DB so we don't query it with the previous log's id cursor.
|
||||
if a.logDb != lastDB {
|
||||
lastID = -1
|
||||
lastDB = a.logDb
|
||||
}
|
||||
if err := a.ensureChatTables(); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user