Skip to content

Commit

Permalink
chat
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Mar 12, 2024
1 parent 8447369 commit 914a93e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion cmd/goatak_server/templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ <h5 class="modal-title" id="staticBackdropLabel">Chat messages</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Understood</button>-->
</div>
</div>
</div>
Expand Down
13 changes: 11 additions & 2 deletions cmd/webclient/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"runtime/pprof"
"time"

"github.com/aofei/air"
"github.com/google/uuid"
Expand Down Expand Up @@ -185,6 +186,7 @@ func addMessageHandler(app *App) air.Handler {
}

defer req.Body.Close()

if err := json.NewDecoder(req.Body).Decode(msg); err != nil {
return err
}
Expand All @@ -193,14 +195,21 @@ func addMessageHandler(app *App) air.Handler {
msg.ID = uuid.NewString()
}

if msg.Time.IsZero() {
msg.Time = time.Now()
}

if msg.Chatroom != msg.ToUID {
msg.Direct = true
}

app.SendMsg(model.MakeChatMessage(msg))
m := model.MakeChatMessage(msg)

app.logger.Debug(m.String())
app.SendMsg(m)
app.messages.Add(msg)

return res.WriteJSON(map[string]string{"ok": "ok"})
return res.WriteJSON(app.messages.Chats)
}
}

Expand Down
5 changes: 5 additions & 0 deletions staticfiles/static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,15 @@ let app = new Vue({
headers: {"Content-Type": "application/json"},
body: JSON.stringify(msg)
};
let vm = this;
fetch("/message", requestOptions)
.then(function (response) {
return response.json()
})
.then(function (data) {
vm.messages = data;
});

}
},
});
Expand Down

0 comments on commit 914a93e

Please sign in to comment.