Enable sending DM messages
This commit is contained in:
parent
3ba8e3ef70
commit
e1bc6bba98
@ -1,6 +1,8 @@
|
|||||||
package webserver
|
package webserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -34,10 +36,24 @@ func (app *Application) Messages(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||||
|
room_id := scraper.DMChatRoomID(parts[0])
|
||||||
|
if len(parts) == 2 && parts[1] == "send" {
|
||||||
|
body, err := io.ReadAll(r.Body)
|
||||||
|
panic_if(err)
|
||||||
|
var message_data struct {
|
||||||
|
Text string `json:"text"`
|
||||||
|
}
|
||||||
|
panic_if(json.Unmarshal(body, &message_data))
|
||||||
|
trove := scraper.SendDMMessage(room_id, message_data.Text, 0)
|
||||||
|
app.Profile.SaveDMTrove(trove, false)
|
||||||
|
go app.Profile.SaveDMTrove(trove, true)
|
||||||
|
}
|
||||||
|
|
||||||
chat_view := app.Profile.GetChatRoomsPreview(app.ActiveUser.ID)
|
chat_view := app.Profile.GetChatRoomsPreview(app.ActiveUser.ID)
|
||||||
if strings.Trim(r.URL.Path, "/") != "" {
|
if strings.Trim(r.URL.Path, "/") != "" {
|
||||||
chat_view.ActiveRoomID = scraper.DMChatRoomID(strings.Trim(r.URL.Path, "/"))
|
chat_view.ActiveRoomID = room_id
|
||||||
chat_contents := app.Profile.GetChatRoomContents(chat_view.ActiveRoomID)
|
chat_contents := app.Profile.GetChatRoomContents(room_id)
|
||||||
chat_view.MergeWith(chat_contents.DMTrove)
|
chat_view.MergeWith(chat_contents.DMTrove)
|
||||||
chat_view.MessageIDs = chat_contents.MessageIDs
|
chat_view.MessageIDs = chat_contents.MessageIDs
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,6 @@ input[type="submit"] {
|
|||||||
background-color: var(--color-twitter-blue-light);
|
background-color: var(--color-twitter-blue-light);
|
||||||
width: 10em;
|
width: 10em;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
margin-top: 1em;
|
|
||||||
border-radius: 1em;
|
border-radius: 1em;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@ -684,9 +683,14 @@ ul.space-participants-list li {
|
|||||||
flex-basis: 0;
|
flex-basis: 0;
|
||||||
flex-grow: 7;
|
flex-grow: 7;
|
||||||
border-left: 1px solid var(--color-outline-gray);
|
border-left: 1px solid var(--color-outline-gray);
|
||||||
overflow-y: scroll;
|
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.chats-container #chat-view .chat-messages {
|
||||||
|
flex-grow: 1;
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
.chats-container #chat-view .our-message {
|
.chats-container #chat-view .our-message {
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
@ -763,5 +767,24 @@ ul.space-participants-list li {
|
|||||||
}
|
}
|
||||||
.dm-message-content-container .replying-to-label img.svg-icon {
|
.dm-message-content-container .replying-to-label img.svg-icon {
|
||||||
width: 1em;
|
width: 1em;
|
||||||
|
}
|
||||||
|
.dm-composer-container {
|
||||||
|
padding-top: 0.5em;
|
||||||
|
border-top: 1px solid var(--color-outline-gray);
|
||||||
|
/* position: absolute;
|
||||||
|
bottom: 1em;
|
||||||
|
right: 0.5em;
|
||||||
|
left: 0.5em;*/
|
||||||
|
}
|
||||||
|
.dm-composer-container form {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
span.composer {
|
||||||
|
flex-grow: 1;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
padding: 1px 6px;
|
||||||
|
max-height: 10em;
|
||||||
|
overflow-y: auto; /* scrollbar only if needed */
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<link rel='shortcut icon' href='/static/img/favicon.ico' type='image/x-icon'>
|
<link rel='shortcut icon' href='/static/img/favicon.ico' type='image/x-icon'>
|
||||||
<link rel='stylesheet' href='/static/vendor/fonts.css'>
|
<link rel='stylesheet' href='/static/vendor/fonts.css'>
|
||||||
<script src="/static/vendor/htmx.min.js" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script>
|
<script src="/static/vendor/htmx.min.js" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script>
|
||||||
|
<script src="/static/vendor/htmx-extension-json-enc.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="top-bar">
|
<div class="top-bar">
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{{define "chat-view"}}
|
{{define "chat-view"}}
|
||||||
<div id="chat-view">
|
<div id="chat-view">
|
||||||
|
<div class="chat-messages">
|
||||||
{{range .MessageIDs}}
|
{{range .MessageIDs}}
|
||||||
{{$message := (index $.DMTrove.Messages .)}}
|
{{$message := (index $.DMTrove.Messages .)}}
|
||||||
{{$user := (user $message.SenderID)}}
|
{{$user := (user $message.SenderID)}}
|
||||||
@ -53,4 +54,32 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
{{if $.ActiveRoomID}}
|
||||||
|
<div class="dm-composer-container">
|
||||||
|
<form hx-post="/messages/{{$.ActiveRoomID}}/send" hx-target="body" hx-ext="json-enc">
|
||||||
|
<span
|
||||||
|
class="composer"
|
||||||
|
role="textbox"
|
||||||
|
contenteditable
|
||||||
|
oninput="var text = this.innerText; document.querySelector('#real-input').value = text"
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
<input id="real-input" type="hidden" name="text" value="" />
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
// Make pasting text work for HTML as well as plain text
|
||||||
|
var editor = document.querySelector("span.composer");
|
||||||
|
editor.addEventListener("paste", function(e) {
|
||||||
|
// cancel paste
|
||||||
|
e.preventDefault();
|
||||||
|
// get text representation of clipboard
|
||||||
|
var text = (e.originalEvent || e).clipboardData.getData('text/plain');
|
||||||
|
// insert text manually
|
||||||
|
document.execCommand("insertHTML", false, text);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -484,7 +484,7 @@ func (api *API) SendDMMessage(room_id DMChatRoomID, text string, in_reply_to_id
|
|||||||
`","text":"` + text + `",` +
|
`","text":"` + text + `",` +
|
||||||
replying_to_text + `"cards_platform":"Web-12","include_cards":1,"include_quote_count":true,"dm_users":false}`
|
replying_to_text + `"cards_platform":"Web-12","include_cards":1,"include_quote_count":true,"dm_users":false}`
|
||||||
|
|
||||||
var result APIDMResponse
|
var result APIInbox
|
||||||
err = api.do_http_POST(url.String(), post_data, &result)
|
err = api.do_http_POST(url.String(), post_data, &result)
|
||||||
return result.UserEvents, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user