Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/evolution-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ func setupRouter(db *gorm.DB, authDB *sql.DB, sqliteDB *sql.DB, config *config.C
)
instanceService := instance_service.NewInstanceService(
instanceRepository,
killChannel,
clientPointer,
whatsmeowService,
config,
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func Load() *Config {

connectOnStartup := os.Getenv(config_env.CONNECT_ON_STARTUP)
if connectOnStartup == "" {
connectOnStartup = "false"
connectOnStartup = "true"
}

osName := os.Getenv(config_env.OS_NAME)
Expand Down
5 changes: 5 additions & 0 deletions pkg/instance/handler/instance_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package instance_handler

import (
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -282,6 +283,10 @@ func (i *instanceHandler) Qr(ctx *gin.Context) {

qrcode, err := i.instanceService.GetQr(instance)
if err != nil {
if errors.Is(err, instance_service.ErrSessionAlreadyLoggedIn) {
ctx.JSON(http.StatusConflict, gin.H{"error": err.Error(), "connected": true})
return
}
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/instance/repository/instance_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type InstanceRepository interface {
UpdateJid(userId string, jid string) error
GetAllConnectedInstances() ([]*instance_model.Instance, error)
GetAllConnectedInstancesByClientName(clientName string) ([]*instance_model.Instance, error)
GetAllPairedInstances() ([]*instance_model.Instance, error)
GetAllPairedInstancesByClientName(clientName string) ([]*instance_model.Instance, error)
GetAll(clientName string) ([]*instance_model.Instance, error)
Delete(instanceId string) error
GetAdvancedSettings(instanceId string) (*instance_model.AdvancedSettings, error)
Expand Down Expand Up @@ -136,6 +138,31 @@ func (i *instanceRepository) GetAllConnectedInstancesByClientName(clientName str
return instances, nil
}

// GetAllPairedInstances returns instances that have already completed pairing.
// The Connected column is intentionally not used here: it represents the live
// socket state and is expected to become false during a redeploy or process
// restart. Using it as the startup selector prevents valid persisted sessions
// from being restored after the application comes back up.
func (i *instanceRepository) GetAllPairedInstances() ([]*instance_model.Instance, error) {
var instances []*instance_model.Instance
err := i.db.Where("jid IS NOT NULL AND TRIM(jid) <> ''").Find(&instances).Error
if err != nil {
return nil, err
}

return instances, nil
}

func (i *instanceRepository) GetAllPairedInstancesByClientName(clientName string) ([]*instance_model.Instance, error) {
var instances []*instance_model.Instance
err := i.db.Where("jid IS NOT NULL AND TRIM(jid) <> '' AND client_name = ?", clientName).Find(&instances).Error
if err != nil {
return nil, err
}

return instances, nil
}

func (i *instanceRepository) GetAll(clientName string) ([]*instance_model.Instance, error) {
var instances []*instance_model.Instance
err := i.db.Where("client_name = ?", clientName).Find(&instances).Error
Expand Down
Loading