|
|
|
@@ -10,6 +10,8 @@ import ( |
|
|
|
"github.com/elliotchance/orderedmap" |
|
|
|
) |
|
|
|
|
|
|
|
var opTypes = []int{1, 2, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 22, 23} |
|
|
|
|
|
|
|
type ClientsManager struct { |
|
|
|
Clients *orderedmap.OrderedMap |
|
|
|
Register chan *Client |
|
|
|
@@ -47,13 +49,15 @@ func (h *ClientsManager) Run() { |
|
|
|
close(client.Send) |
|
|
|
} |
|
|
|
case message := <-models.ActionChan: |
|
|
|
LastActionsQueue.Push(message) |
|
|
|
for _, client := range h.Clients.Keys() { |
|
|
|
select { |
|
|
|
case client.(*Client).Send <- message: |
|
|
|
default: |
|
|
|
close(client.(*Client).Send) |
|
|
|
h.Clients.Delete(client) |
|
|
|
if isInOpTypes(opTypes, message.OpType) { |
|
|
|
LastActionsQueue.Push(message) |
|
|
|
for _, client := range h.Clients.Keys() { |
|
|
|
select { |
|
|
|
case client.(*Client).Send <- message: |
|
|
|
default: |
|
|
|
close(client.(*Client).Send) |
|
|
|
h.Clients.Delete(client) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
case s := <-sig: |
|
|
|
@@ -71,8 +75,19 @@ func (h *ClientsManager) Run() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func isInOpTypes(types []int, opType models.ActionType) bool { |
|
|
|
isFound := false |
|
|
|
for _, value := range types { |
|
|
|
if value == int(opType) { |
|
|
|
isFound = true |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
return isFound |
|
|
|
} |
|
|
|
|
|
|
|
func initActionQueue() { |
|
|
|
actions, err := models.GetLast20PublicFeeds() |
|
|
|
actions, err := models.GetLast20PublicFeeds(opTypes) |
|
|
|
if err == nil { |
|
|
|
for i := len(actions) - 1; i >= 0; i-- { |
|
|
|
|
|
|
|
|