diff --git a/app/queue.go b/app/queue.go index 09101f7c..141a1003 100644 --- a/app/queue.go +++ b/app/queue.go @@ -97,15 +97,16 @@ func (a *App) NotificationInterceptAttempt(domainId int64, queueId int, channel }) } -func (a *App) NotificationWaitingList(domainId int64, userIds []int64, list []*model.MemberWaiting) *model.AppError { - return a.MQ.SendNotification(domainId, &model.Notification{ +func (a *App) NotificationWaitingList(e *model.MemberWaitingByUsers) *model.AppError { + return a.MQ.SendNotification(e.DomainId, &model.Notification{ Id: 0, - DomainId: domainId, + DomainId: e.DomainId, Action: model.NotificationWaitingList, CreatedAt: model.GetMillis(), - ForUsers: userIds, + ForUsers: e.Users, Body: map[string]interface{}{ - "list": list, + "calls": e.Calls, + "chats": e.Chats, }, }) } diff --git a/model/manual_queue.go b/model/manual_queue.go index 9241a60b..d8b19280 100644 --- a/model/manual_queue.go +++ b/model/manual_queue.go @@ -3,7 +3,6 @@ package model import "encoding/json" type MemberWaiting struct { - Position int `json:"position" db:"position"` AttemptId int64 `json:"attempt_id" db:"attempt_id"` Wait int `json:"wait" db:"wait"` Communication json.RawMessage `json:"communication" db:"communication"` @@ -11,10 +10,12 @@ type MemberWaiting struct { Bucket *Lookup `json:"bucket,omitempty" db:"bucket"` Deadline int `json:"deadline" db:"deadline"` Channel string `json:"channel" db:"channel"` + SessionId string `json:"session_id,omitempty" db:"session_id,omitempty"` } type MemberWaitingByUsers struct { DomainId int64 `json:"-" db:"domain_id"` Users Int64Array `json:"-" db:"users"` - Members []*MemberWaiting `json:"-" db:"members"` + Calls []*MemberWaiting `json:"-" db:"calls"` + Chats []*MemberWaiting `json:"-" db:"chats"` } diff --git a/queue/app.go b/queue/app.go index 30946b6b..a787e993 100644 --- a/queue/app.go +++ b/queue/app.go @@ -19,5 +19,5 @@ type App interface { QueueSettings() model.QueueSettings NotificationHideMember(domainId int64, queueId int, memberId *int64, agentId int) *model.AppError NotificationInterceptAttempt(domainId int64, queueId int, channel string, attemptId int64, skipAgentId int32) *model.AppError - NotificationWaitingList(domainId int64, userIds []int64, list []*model.MemberWaiting) *model.AppError + NotificationWaitingList(e *model.MemberWaitingByUsers) *model.AppError } diff --git a/queue/queue_manual.go b/queue/queue_manual.go index 6b19a987..0d7c3b87 100644 --- a/queue/queue_manual.go +++ b/queue/queue_manual.go @@ -36,7 +36,7 @@ func (qm *QueueManager) listWaiting() { } for _, v := range list { - err = qm.app.NotificationWaitingList(v.DomainId, v.Users, v.Members) + err = qm.app.NotificationWaitingList(v) if err != nil { wlog.Error(err.Error()) } diff --git a/store/sqlstore/member_store.go b/store/sqlstore/member_store.go index a0b89d02..3cc28fd5 100644 --- a/store/sqlstore/member_store.go +++ b/store/sqlstore/member_store.go @@ -986,58 +986,8 @@ where id = :Id;`, map[string]interface{}{ func (s *SqlMemberStore) WaitingList() ([]*model.MemberWaitingByUsers, *model.AppError) { var list []*model.MemberWaitingByUsers - _, err := s.GetMaster().Select(&list, `with queues as materialized ( - SELECT q.domain_id, - q.name, - qs.queue_id, - q.priority, - coalesce((q.payload->'max_wait_time')::int, 0) as max_wait_time, - coalesce((q.payload->'sticky_agent_sec')::int, 0) as sticky_agent_sec, - q.sticky_agent, - b as bucket_id, - max(qs.lvl) lvl, - array_agg(distinct csia.agent_id) agents, - array_agg(distinct a.user_id) users - FROM call_center.cc_queue q - join call_center.cc_queue_skill qs on qs.queue_id = q.id - JOIN call_center.cc_skill_in_agent csia ON csia.skill_id = qs.skill_id - join call_center.cc_agent a on a.id = csia.agent_id and (q.team_id isnull or q.team_id = a.team_id) - left join lateral unnest(qs.bucket_ids) b on true - WHERE qs.enabled - AND csia.enabled - AND csia.capacity >= qs.min_capacity - AND csia.capacity <= qs.max_capacity - and q.domain_id = a.domain_id - and a.status = 'online' - and coalesce((q.payload->'manual_distribution')::bool, false) - group by 1, 2, 3, 4, 5, 6, 7, 8 -) -select list.domain_id, list.users::int8[] as users, jsonb_agg(row_to_json(list)::jsonb - 'domain_id' - 'users') as members -from ( - select row_number() - over (order by q.priority desc, (extract(epoch from now() - coalesce(a.transferred_at, a.joined_at)) + - a.weight) desc) position, - a.id attempt_id, - extract(epoch from now() - joined_at)::int as wait, - a.destination::jsonb as communication, - call_center.cc_get_lookup(q.queue_id, q.name) as queue, - call_center.cc_get_lookup(b.id::int8, b.name::text) as bucket, - ((extract(epoch from now() - joined_at)::numeric / q.max_wait_time::numeric) * 100)::int as deadline, --- q.agents, - q.users, - a.channel, - q.domain_id - from queues q - inner join call_center.cc_member_attempt a on q.queue_id = a.queue_id - left join call_center.cc_bucket b on b.id = a.bucket_id - where a.domain_id = q.domain_id - and a.agent_id isnull - and a.state = 'wait_agent' - and a.queue_id = q.queue_id - and coalesce(q.bucket_id, 0) = coalesce(a.bucket_id, 0) - order by q.lvl, q.priority desc, (extract(epoch from now() - a.joined_at) + a.weight) desc -) list -group by 1, 2`) + _, err := s.GetMaster().Select(&list, `select domain_id, users, chats, calls +from call_center.cc_manual_queue_list`) if err != nil { return nil, model.NewAppError("SqlMemberStore.WaitingList", "store.sql_member.waiting_list.app_error", nil, diff --git a/store/sqlstore/supplier.go b/store/sqlstore/supplier.go index 2a08fd3a..00f6bee5 100644 --- a/store/sqlstore/supplier.go +++ b/store/sqlstore/supplier.go @@ -249,7 +249,8 @@ func (me typeConverter) ToDb(val interface{}) (interface{}, error) { func (me typeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool) { switch target.(type) { - case *model.OutboundResourceParameters: + case *model.OutboundResourceParameters, + *[]*model.MemberWaiting: binder := func(holder, target interface{}) error { s, ok := holder.(*[]byte) if !ok { @@ -264,8 +265,7 @@ func (me typeConverter) FromDb(target interface{}) (gorp.CustomScanner, bool) { case *model.Lookup, *model.RingtoneFile, *model.AgentChannel, - *[]model.AgentChannel, - *[]*model.MemberWaiting: + *[]model.AgentChannel: binder := func(holder, target interface{}) error { s, ok := holder.(*string) if !ok {