Re: Displaying chat by punished users only to themselves (db fiddle attached)

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Displaying chat by punished users only to themselves (db fiddle attached)
Date: 2022-05-04 14:40:34
Message-ID: CAADeyWgt2Ch3iZFmRrwvZFmwubAwO-8ZD-Di5utEQW4XOqWUUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you for replying, David!

The "social dynamic" is needed, because I cannot pass real user id (via
HTTP) to SQL queries.

Instead I pass social network type "social" (like 100 is facebook, 200 is
twitter) and the social network id "sid" returned by that network. This way
noone can read chats by other users, by just replacing the numeric "uid"...

So I try your suggestion with:

https://dbfiddle.uk/?rdbms=postgres_14&fiddle=48d4bef569d966021e94c72f86d9fce5

CREATE OR REPLACE FUNCTION words_get_chat(
in_gid integer,
in_social integer,
in_sid text
) RETURNS TABLE (
out_mine integer,
out_msg text
) AS
$func$
SELECT
CASE WHEN c.uid = s.uid THEN 1 ELSE 0 END,
c.msg
FROM words_chat c
JOIN words_games g USING (gid)
JOIN words_users u1 ON (u1.uid = g.player1)
JOIN words_users u2 ON (u2.uid = g.player2)
JOIN words_social s ON (s.uid IN (u1.uid, u2.uid))
WHERE c.gid = in_gid
AND s.social = in_social
AND s.sid = in_sid
ORDER BY c.CREATED ASC;

$func$ LANGUAGE sql;

...but how to bring the u1.muted or u2.muted there?

Best regards
Alex

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2022-05-04 14:56:30 Re: Displaying chat by punished users only to themselves (db fiddle attached)
Previous Message David G. Johnston 2022-05-04 14:26:59 Re: Displaying chat by punished users only to themselves (db fiddle attached)