Commit 0ec9f92d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Make 'clearchat' into a user message.

parent e393819e
......@@ -539,7 +539,7 @@ func gotAnswer(c *webClient, id string, sdp string) error {
}
err := down.pc.SetRemoteDescription(webrtc.SessionDescription{
Type: webrtc.SDPTypeAnswer,
SDP: sdp,
SDP: sdp,
})
if err != nil {
return err
......@@ -1235,7 +1235,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
switch m.Kind {
case "clearchat":
g.ClearChatHistory()
m := clientMessage{Type: "clearchat"}
m := clientMessage{
Type: "usermessage",
Kind: "clearchat",
Privileged: true,
}
clients := g.GetClients(nil)
for _, cc := range clients {
cc, ok := cc.(*webClient)
......
......@@ -1555,7 +1555,6 @@ function gotUserMessage(id, dest, username, time, privileged, kind, message) {
console.error(`Got unprivileged message of kind ${kind}`);
break;
case 'mute':
console.log(id, dest, username);
if(privileged) {
setLocalMute(true, true);
let by = username ? ' by ' + username : '';
......@@ -1564,6 +1563,12 @@ function gotUserMessage(id, dest, username, time, privileged, kind, message) {
console.error(`Got unprivileged message of kind ${kind}`);
}
break;
case 'clearchat':
if(privileged) {
clearChat();
} else {
console.error(`Got unprivileged message of kind ${kind}`);
}
default:
console.warn(`Got unknown user message ${kind}`);
break;
......@@ -2319,7 +2324,6 @@ async function serverConnect() {
serverConnection.onuser = gotUser;
serverConnection.onjoined = gotJoined;
serverConnection.onchat = addToChatbox;
serverConnection.onclearchat = clearChat;
serverConnection.onusermessage = gotUserMessage;
let url = `ws${location.protocol === 'https:' ? 's' : ''}://${location.host}/ws`;
......
......@@ -161,13 +161,6 @@ function ServerConnection() {
* @type {(this: ServerConnection, id: string, dest: string, username: string, time: number, privileged: boolean, kind: string, message: unknown) => void}
*/
this.onusermessage = null;
/**
* onclearchat is called whenever the server requests that the chat
* be cleared.
*
* @type{(this: ServerConnection) => void}
*/
this.onclearchat = null;
}
/**
......@@ -315,10 +308,6 @@ ServerConnection.prototype.connect = async function(url) {
m.privileged, m.kind, m.value,
);
break;
case 'clearchat':
if(sc.onclearchat)
sc.onclearchat.call(sc);
break;
case 'ping':
sc.send({
type: 'pong',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment