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
5 changes: 3 additions & 2 deletions cmd/evolution-go/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/evolution-foundation/evolution-go/pkg/safemap"
"context"
"database/sql"
"flag"
Expand Down Expand Up @@ -83,8 +84,8 @@ func init() {
}

func setupRouter(db *gorm.DB, authDB *sql.DB, sqliteDB *sql.DB, config *config.Config, conn *amqp.Connection, exPath string, runtimeCtx *core.RuntimeContext) *gin.Engine {
killChannel := make(map[string](chan bool))
clientPointer := make(map[string]*whatsmeow.Client)
killChannel := safemap.New[chan bool]()
clientPointer := safemap.New[*whatsmeow.Client]()

loggerWrapper := logger_wrapper.NewLoggerManager(config)

Expand Down
9 changes: 5 additions & 4 deletions pkg/call/service/call_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package call_service

import (
"github.com/evolution-foundation/evolution-go/pkg/safemap"
"context"
"errors"
"time"
Expand All @@ -18,7 +19,7 @@ type CallService interface {
}

type callService struct {
clientPointer map[string]*whatsmeow.Client
clientPointer *safemap.Map[*whatsmeow.Client]
whatsmeowService whatsmeow_service.WhatsmeowService
loggerWrapper *logger_wrapper.LoggerManager
}
Expand All @@ -29,7 +30,7 @@ type RejectCallStruct struct {
}

func (c *callService) ensureClientConnected(instanceId string) (*whatsmeow.Client, error) {
client := c.clientPointer[instanceId]
client := c.clientPointer.Get(instanceId)
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking client connection status - Client exists: %v", instanceId, client != nil)

if client == nil {
Expand All @@ -43,7 +44,7 @@ func (c *callService) ensureClientConnected(instanceId string) (*whatsmeow.Clien
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Instance started, waiting 2 seconds...", instanceId)
time.Sleep(2 * time.Second)

client = c.clientPointer[instanceId]
client = c.clientPointer.Get(instanceId)
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking new client - Exists: %v, Connected: %v",
instanceId,
client != nil,
Expand Down Expand Up @@ -83,7 +84,7 @@ func (c *callService) RejectCall(data *RejectCallStruct, instance *instance_mode
}

func NewCallService(
clientPointer map[string]*whatsmeow.Client,
clientPointer *safemap.Map[*whatsmeow.Client],
whatsmeowService whatsmeow_service.WhatsmeowService,
loggerWrapper *logger_wrapper.LoggerManager,
) CallService {
Expand Down
9 changes: 5 additions & 4 deletions pkg/chat/service/chat_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chat_service

import (
"github.com/evolution-foundation/evolution-go/pkg/safemap"
"context"
"errors"
"time"
Expand All @@ -25,7 +26,7 @@ type ChatService interface {
}

type chatService struct {
clientPointer map[string]*whatsmeow.Client
clientPointer *safemap.Map[*whatsmeow.Client]
whatsmeowService whatsmeow_service.WhatsmeowService
loggerWrapper *logger_wrapper.LoggerManager
}
Expand All @@ -40,7 +41,7 @@ type HistorySyncRequestStruct struct {
}

func (c *chatService) ensureClientConnected(instanceId string) (*whatsmeow.Client, error) {
client := c.clientPointer[instanceId]
client := c.clientPointer.Get(instanceId)
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking client connection status - Client exists: %v", instanceId, client != nil)

if client == nil {
Expand All @@ -54,7 +55,7 @@ func (c *chatService) ensureClientConnected(instanceId string) (*whatsmeow.Clien
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Instance started, waiting 2 seconds...", instanceId)
time.Sleep(2 * time.Second)

client = c.clientPointer[instanceId]
client = c.clientPointer.Get(instanceId)
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking new client - Exists: %v, Connected: %v",
instanceId,
client != nil,
Expand Down Expand Up @@ -244,7 +245,7 @@ func (c *chatService) HistorySyncRequest(data *HistorySyncRequestStruct, instanc
}

func NewChatService(
clientPointer map[string]*whatsmeow.Client,
clientPointer *safemap.Map[*whatsmeow.Client],
whatsmeowService whatsmeow_service.WhatsmeowService,
loggerWrapper *logger_wrapper.LoggerManager,
) ChatService {
Expand Down
9 changes: 5 additions & 4 deletions pkg/community/service/community_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package community_service

import (
"github.com/evolution-foundation/evolution-go/pkg/safemap"
"context"
"errors"
"time"
Expand All @@ -21,7 +22,7 @@ type CommunityService interface {
}

type communityService struct {
clientPointer map[string]*whatsmeow.Client
clientPointer *safemap.Map[*whatsmeow.Client]
whatsmeowService whatsmeow_service.WhatsmeowService
loggerWrapper *logger_wrapper.LoggerManager
}
Expand All @@ -36,7 +37,7 @@ type AddParticipantStruct struct {
}

func (c *communityService) ensureClientConnected(instanceId string) (*whatsmeow.Client, error) {
client := c.clientPointer[instanceId]
client := c.clientPointer.Get(instanceId)
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking client connection status - Client exists: %v", instanceId, client != nil)

if client == nil {
Expand All @@ -50,7 +51,7 @@ func (c *communityService) ensureClientConnected(instanceId string) (*whatsmeow.
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Instance started, waiting 2 seconds...", instanceId)
time.Sleep(2 * time.Second)

client = c.clientPointer[instanceId]
client = c.clientPointer.Get(instanceId)
c.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking new client - Exists: %v, Connected: %v",
instanceId,
client != nil,
Expand Down Expand Up @@ -157,7 +158,7 @@ func (c *communityService) CommunityRemove(data *AddParticipantStruct, instance
}

func NewCommunityService(
clientPointer map[string]*whatsmeow.Client,
clientPointer *safemap.Map[*whatsmeow.Client],
whatsmeowService whatsmeow_service.WhatsmeowService,
loggerWrapper *logger_wrapper.LoggerManager,
) CommunityService {
Expand Down
9 changes: 5 additions & 4 deletions pkg/group/service/group_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package group_service

import (
"github.com/evolution-foundation/evolution-go/pkg/safemap"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -37,7 +38,7 @@ type GroupService interface {
}

type groupService struct {
clientPointer map[string]*whatsmeow.Client
clientPointer *safemap.Map[*whatsmeow.Client]
whatsmeowService whatsmeow_service.WhatsmeowService
loggerWrapper *logger_wrapper.LoggerManager
}
Expand Down Expand Up @@ -117,7 +118,7 @@ type UpdateGroupRequestParticipantsStruct struct {
}

func (g *groupService) ensureClientConnected(instanceId string) (*whatsmeow.Client, error) {
client := g.clientPointer[instanceId]
client := g.clientPointer.Get(instanceId)
g.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking client connection status - Client exists: %v", instanceId, client != nil)

if client == nil {
Expand All @@ -131,7 +132,7 @@ func (g *groupService) ensureClientConnected(instanceId string) (*whatsmeow.Clie
g.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Instance started, waiting 2 seconds...", instanceId)
time.Sleep(2 * time.Second)

client = g.clientPointer[instanceId]
client = g.clientPointer.Get(instanceId)
g.loggerWrapper.GetLogger(instanceId).LogInfo("[%s] Checking new client - Exists: %v, Connected: %v",
instanceId,
client != nil,
Expand Down Expand Up @@ -641,7 +642,7 @@ func (g *groupService) UpdateGroupRequestParticipants(data *UpdateGroupRequestPa
}

func NewGroupService(
clientPointer map[string]*whatsmeow.Client,
clientPointer *safemap.Map[*whatsmeow.Client],
whatsmeowService whatsmeow_service.WhatsmeowService,
loggerWrapper *logger_wrapper.LoggerManager,
) GroupService {
Expand Down
Loading