Progress.

This commit is contained in:
retoor 2025-01-27 00:56:06 +01:00
parent fb7cb35921
commit 36c69eb8bb
6 changed files with 32 additions and 8 deletions

View File

@ -23,7 +23,11 @@ class SocketService(BaseService):
print("BROADCAT!",message)
count = 0
for ws in self.subscriptions.get(channel_uid,[]):
await ws.send_json(message)
try:
await ws.send_json(message)
except Exception as ex:
print(ex)
continue
count += 1
return count
async def delete(self, ws):

View File

@ -212,7 +212,7 @@ class Socket extends EventHandler {
connectPromises = []
constructor() {
super()
this.url = window.location.hostname == 'localhost' ? 'ws://localhost/rpc.ws' : 'wss://' + window.location.hostname +'/rpc.ws'
this.url = window.location.hostname == 'localhost' ? 'ws://localhost:8081/rpc.ws' : 'wss://' + window.location.hostname +'/rpc.ws'
this.ensureConnection()
}
_camelToSnake(str) {

View File

@ -59,6 +59,10 @@ class BaseMapper:
model[key] = value
yield model
async def query(self, sql, *args):
for record in self.db.query(sql, *args):
yield dict(record)
async def delete(self, kwargs=None) -> int:
if not kwargs or not isinstance(kwargs, dict):
raise Exception("Can't execute delete with no filter.")

View File

@ -32,6 +32,10 @@ class BaseService:
async def new(self, **kwargs):
return await self.mapper.new()
async def query(self, sql, *args):
for record in self.app.db.query(sql, *args):
yield record
async def get(self, uid=None, **kwargs):
if uid:
if not kwargs:

View File

@ -8,6 +8,7 @@
<script src="/models.js"></script>
<script src="/message-list.js"></script>
<script src="/message-list-manager.js"></script>
<script src="/chat-window.js"></script>
<link rel="stylesheet" href="base.css">
</head>
<body>
@ -30,12 +31,10 @@
<li><a href="#">Random</a></li>
</ul>
</aside>
<section class="chat-area">
<div class="chat-header">
<h2>General</h2>
</div>
<message-list-manager class="message-list-manager"></message-list-manager>
<div class="chat-input">
<section>
<chat-window class="chat-area"></chat-window>
<div class="chat-input">
<textarea placeholder="Type a message..." rows="2"></textarea>
<button>Send</button>
</div>

View File

@ -15,6 +15,19 @@ class RPCView(BaseView):
self.ws = ws
async def get_messages(self, channel_uid,offset=0):
messages = []
async for message in self.services.channel_message.query("SELECT channel_uid, user_uid, message, created_at FROM channel_message WHERE channel_uid = :channel_uid ORDER BY created_at DESC LIMIT 30 OFFSET :offset",{"channel_uid":channel_uid,"offset":int(offset)}):
messages.append(dict(
uid=message["uid"],
user_uid=message["user_uid"],
channel_uid=message["channel_uid"],
user_nick=(await self.services.user.get(uid=message["user_uid"]))["nick"],
message=message["message"],
created_at=message["created_at"]
))
return messages
async def get_channels(self):
channels = []
async for subscription in self.services.channel_member.find(user_uid=self.user_uid,is_banned=False):