message history for dm

This commit is contained in:
2026-04-11 22:49:05 +02:00
parent 62ff403d92
commit 4c87222b43
5 changed files with 42 additions and 9 deletions
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -317,7 +317,7 @@ func HttpHandleUserMessage(response http.ResponseWriter, request *http.Request)
response.WriteHeader(http.StatusAccepted) response.WriteHeader(http.StatusAccepted)
} }
func HttpHandleUserGetMessages(response http.ResponseWriter, request *http.Request) { func HttpHandleUserGetConnectionMessages(response http.ResponseWriter, request *http.Request) {
if !isMethodAllowed(&response, request) { if !isMethodAllowed(&response, request) {
return return
} }
+18 -6
View File
@@ -88,7 +88,7 @@ def cmd_history(args):
data["messages"] = args[1] data["messages"] = args[1]
if len(args) > 2: if len(args) > 2:
data["before"] = args[2] data["before"] = args[2]
r = requests.post(f"{BASE_URL}/messages", data=data) r = requests.post(f"{BASE_URL}/get/connection/messages", data=data)
if r.ok: if r.ok:
msgs = r.json() or [] msgs = r.json() or []
if not msgs: if not msgs:
@@ -102,18 +102,29 @@ def cmd_connections(args):
if not token: if not token:
print("not logged in") print("not logged in")
return return
r = post("/connections", token=token) r = post("/get/connections", token=token)
if r.ok: if r.ok:
for c in (r.json() or {}).values(): for c in (r.json() or {}).values():
print(f" {c['id']} requestor={c['requestorId']} recipient={c['recipientId']} state={c['state']}") print(f" {c['id']} requestor={c['requestorId']} recipient={c['recipientId']} state={c['state']}")
else: else:
print(f"error: {r.text}") print(f"error: {r.text}")
def cmd_delconnection(args):
if not token:
print("not logged in")
return
if not args:
print("usage: /delconnection <connectionid>")
return
r = post("/del/connection", token=token, connectionid=args[0])
print("deleted" if r.ok else f"error: {r.text}")
COMMANDS = { COMMANDS = {
"/login": cmd_login, "/login": cmd_login,
"/send": cmd_send, "/send": cmd_send,
"/history": cmd_history, "/history": cmd_history,
"/connections": cmd_connections, "/connections": cmd_connections,
"/delconnection": cmd_delconnection,
} }
HELP = """ HELP = """
@@ -121,6 +132,7 @@ HELP = """
/connections list your connections /connections list your connections
/send <connectionid> <message…> send a DM /send <connectionid> <message…> send a DM
/history <connectionid> [count] [before] fetch message history /history <connectionid> [count] [before] fetch message history
/delconnection <connectionid> delete a connection
""" """
# ── websocket ───────────────────────────────────────────────────────────────── # ── websocket ─────────────────────────────────────────────────────────────────
+20
View File
@@ -82,6 +82,8 @@
<button onclick="showForm('get-connections')">POST /get/connections</button> <button onclick="showForm('get-connections')">POST /get/connections</button>
<button onclick="showForm('get-members')">POST /get/group/members</button> <button onclick="showForm('get-members')">POST /get/group/members</button>
<button onclick="showForm('del-group')" class="warn">POST /del/group</button> <button onclick="showForm('del-group')" class="warn">POST /del/group</button>
<button onclick="showForm('del-connection')" class="warn">POST /del/connection</button>
<button onclick="showForm('get-connection-messages')">POST /get/connection/messages</button>
<button onclick="showForm('msg-user')">POST /msg/user</button> <button onclick="showForm('msg-user')">POST /msg/user</button>
<button onclick="showForm('msg-group')">POST /msg/group</button> <button onclick="showForm('msg-group')">POST /msg/group</button>
<button onclick="showForm('websocket')">WS /ws</button> <button onclick="showForm('websocket')">WS /ws</button>
@@ -236,6 +238,24 @@
], ],
submit: () => httpPost('/del/group', { token:'dg-token', groupid:'dg-groupid' }) submit: () => httpPost('/del/group', { token:'dg-token', groupid:'dg-groupid' })
}, },
'del-connection': {
title: 'POST /del/connection — delete a connection',
fields: [
{ id: 'dc-token', label: 'token', ph: '' },
{ id: 'dc-connectionid', label: 'connectionid', ph: 'UUID' },
],
submit: () => httpPost('/del/connection', { token:'dc-token', connectionid:'dc-connectionid' })
},
'get-connection-messages': {
title: 'POST /get/connection/messages — fetch message history',
fields: [
{ id: 'gcm-token', label: 'token', ph: '' },
{ id: 'gcm-connectionid', label: 'connectionid', ph: 'UUID' },
{ id: 'gcm-messages', label: 'messages', ph: 'count (optional)' },
{ id: 'gcm-before', label: 'before', ph: 'RFC3339 (optional)', hint: 'e.g. 2025-01-01T00:00:00Z' },
],
submit: () => httpPost('/get/connection/messages', { token:'gcm-token', connectionid:'gcm-connectionid', messages:'gcm-messages', before:'gcm-before' })
},
'msg-user': { 'msg-user': {
title: 'POST /msg/user — send direct message to user', title: 'POST /msg/user — send direct message to user',
fields: [ fields: [
+3 -2
View File
@@ -25,7 +25,6 @@ func main() {
http.HandleFunc("/mod/user/appearence", withCORS(HttpHandleUserModifyAppearance)) http.HandleFunc("/mod/user/appearence", withCORS(HttpHandleUserModifyAppearance))
http.HandleFunc("/mod/user/about", withCORS(HttpHandleUserModifyAbout)) http.HandleFunc("/mod/user/about", withCORS(HttpHandleUserModifyAbout))
http.HandleFunc("/mod/connection/accept", withCORS(HttpHandleUserElevateConnection)) http.HandleFunc("/mod/connection/accept", withCORS(HttpHandleUserElevateConnection))
http.HandleFunc("/mod/connection/delete", withCORS(HttpHandleUserDeleteConnection))
http.HandleFunc("/mod/group/addusers", withCORS(HttpHandleGroupAddUsers)) http.HandleFunc("/mod/group/addusers", withCORS(HttpHandleGroupAddUsers))
http.HandleFunc("/mod/group/removeusers", withCORS(HttpHandleGroupRemoveUser)) http.HandleFunc("/mod/group/removeusers", withCORS(HttpHandleGroupRemoveUser))
http.HandleFunc("/mod/group/color", withCORS(HttpHandleGroupChangeColor)) http.HandleFunc("/mod/group/color", withCORS(HttpHandleGroupChangeColor))
@@ -33,9 +32,11 @@ func main() {
http.HandleFunc("/get/groups", withCORS(HttpHandleGroupsGetWithoutMembers)) http.HandleFunc("/get/groups", withCORS(HttpHandleGroupsGetWithoutMembers))
http.HandleFunc("/get/connections", withCORS(HttpHandleUserGetConnections)) http.HandleFunc("/get/connections", withCORS(HttpHandleUserGetConnections))
http.HandleFunc("/get/connection/messages", withCORS(HttpHandleUserGetConnectionMessages))
http.HandleFunc("/get/group/members", withCORS(HttpHandleGroupMembersGet)) http.HandleFunc("/get/group/members", withCORS(HttpHandleGroupMembersGet))
http.HandleFunc("/del/group", withCORS(HttpHandleGroupDelete)) http.HandleFunc("/del/group", withCORS(HttpHandleGroupDelete))
http.HandleFunc("/del/connection", withCORS(HttpHandleUserDeleteConnection))
http.HandleFunc("/msg/user", withCORS(HttpHandleUserMessage)) http.HandleFunc("/msg/user", withCORS(HttpHandleUserMessage))
http.HandleFunc("/msg/group", withCORS(HttpHandleGroupMessage)) http.HandleFunc("/msg/group", withCORS(HttpHandleGroupMessage))