diff --git a/docker-run.sh b/docker-run.sh
new file mode 100755
index 0000000..2381669
--- /dev/null
+++ b/docker-run.sh
@@ -0,0 +1,2 @@
+docker-compose -f docker/minIO/docker-compose.yml up -d
+docker-compose -f docker/postgres/docker-compose.yml up -d
diff --git a/go-socket b/go-socket
index 072fef0..84467a3 100755
Binary files a/go-socket and b/go-socket differ
diff --git a/machine-client/index.html b/machine-client/index.html
index 89d7320..35558ae 100644
--- a/machine-client/index.html
+++ b/machine-client/index.html
@@ -76,6 +76,7 @@
+
@@ -168,6 +169,13 @@
@@ -255,6 +263,7 @@
'mod-connection-deelevate':{ method:'POST', path:'/connection/deelevate', title:'POST /connection/deelevate — de-elevate', fields:[{id:'mcde-token',dest:'header',name:'token'},{id:'mcde-connectionid',dest:'body',name:'connectionid'}] },
'get-user': { method:'GET', path:'/user', title:'GET /user — get user info', fields:[{id:'gu-token',dest:'header',name:'token'},{id:'gu-targetid',dest:'query',name:'targetid'}] },
'get-connections': { method:'GET', path:'/connections', title:'GET /connections — get connections', fields:[{id:'gconn-token',dest:'header',name:'token'}] },
+ 'get-connections-unread': { method:'GET', path:'/connections/unreadmessages', title:'GET /connections/unreadmessages — unread counts for given connections (returns []uint32 in same order)', fields:[{id:'gcur-token',dest:'header',name:'token'},{id:'gcur-connections',dest:'query',name:'connections'}] },
'get-connection-messages': { method:'GET', path:'/connection/messages', title:'GET /connection/messages — message history', fields:[{id:'gcm-token',dest:'header',name:'token'},{id:'gcm-connectionid',dest:'query',name:'connectionid'},{id:'gcm-messages',dest:'query',name:'messages'},{id:'gcm-before',dest:'query',name:'before'}] },
'del-user': { method:'DELETE', path:'/user', title:'DELETE /user — delete own account', fields:[{id:'du-token',dest:'header',name:'token'}] },
'del-connection': { method:'DELETE', path:'/connection', title:'DELETE /connection — delete a connection', fields:[{id:'dc-token',dest:'header',name:'token'},{id:'dc-connectionid',dest:'query',name:'connectionid'}] },
diff --git a/main.go b/main.go
index 65b75de..b8eefc7 100644
--- a/main.go
+++ b/main.go
@@ -54,7 +54,7 @@ func main() {
http.HandleFunc("GET /file", withCORS(httpRequest.HandleAttachmentFileDownload))
http.HandleFunc("POST /message", withCORS(httpRequest.HandleDm))
- http.HandleFunc("/ws", wsServer.ServeWsConnection)
+ http.HandleFunc("GET /ws", wsServer.ServeWsConnection)
log.Println("beep boop; server server started")
log.Fatal(http.ListenAndServe(":8080", nil))
diff --git a/packages/convertions/convertions.go b/packages/convertions/convertions.go
index 6869a91..9311159 100644
--- a/packages/convertions/convertions.go
+++ b/packages/convertions/convertions.go
@@ -45,14 +45,14 @@ func StringToUuid(str string) (uuid.UUID, error) {
return uuid.Parse(str)
}
-func StringToUuidSlice(uuidStr string) (*[]uuid.UUID, error) {
+func StringToUuidSlice(uuidStr string) ([]uuid.UUID, error) {
if uuidStr == "" {
return nil, errors.New("empty string")
}
parts := strings.Split(uuidStr, ",")
- slice := make([]uuid.UUID, len(parts))
+ slice := make([]uuid.UUID, 0, len(parts))
for _, part := range parts {
id, err := StringToUuid(part)
@@ -62,7 +62,7 @@ func StringToUuidSlice(uuidStr string) (*[]uuid.UUID, error) {
slice = append(slice, id)
}
- return &slice, nil
+ return slice, nil
}
func StringToTimestamp(str string) (time.Time, error) {
diff --git a/packages/httpRequest/connectionsAndDms.go b/packages/httpRequest/connectionsAndDms.go
index 69a1127..fb89119 100644
--- a/packages/httpRequest/connectionsAndDms.go
+++ b/packages/httpRequest/connectionsAndDms.go
@@ -74,13 +74,13 @@ func HandleDm(response http.ResponseWriter, request *http.Request) {
Receiver: conn.Id,
}
- if user.WsConn != nil {
+ if target.WsConn != nil {
wsServer.WsSendMessageCloseIfTimeout(target, types.WsEventMessage{
Type: WsEventType.DirectMessage,
Event: message,
})
} else {
- cache.IncrementConnectionsUnreadMessages(user.Id, conn.Id)
+ cache.IncrementConnectionsUnreadMessages(target.Id, conn.Id)
}
err = postgresql.ConnectionMessageSave(ctx, message)
@@ -109,10 +109,9 @@ func HandleUserGetConnectionsUnreadMessages(response http.ResponseWriter, reques
http.Error(response, "invalid uuid format", http.StatusBadRequest)
return
}
+ result := make([]uint32, 0, len(connectionIds))
- result := make([]uint32, len(*connectionIds))
-
- for _, connId := range *connectionIds {
+ for _, connId := range connectionIds {
_, ok := cache.GetConnection(user, connId)
if !ok {
http.Error(response, "no such connection: "+connId.String(), http.StatusUnauthorized)
@@ -120,7 +119,7 @@ func HandleUserGetConnectionsUnreadMessages(response http.ResponseWriter, reques
}
}
- for _, connId := range *connectionIds {
+ for _, connId := range connectionIds {
count, _ := cache.GetConnectionsUnreadMessages(user.Id, connId)
cache.DeallocateConnectionsUnreadMessages(user.Id, connId)
result = append(result, count)
diff --git a/todo.txt b/todo.txt
index 63fe116..96b0991 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,4 +1,4 @@
-when user not ws connected collect count of unread messages for each conn
+when user not ws connected collect count of unread messages for each conn (add db table in future)
add hubs