1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Make 'clearchat' into a user message.

This commit is contained in:
Juliusz Chroboczek 2021-01-03 17:47:56 +01:00
parent e393819eda
commit 0ec9f92dad
3 changed files with 12 additions and 15 deletions

View file

@ -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)

View file

@ -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`;

View file

@ -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',