Browse code

[mod] support user join/part/kick/quit events

Christian FraƟ authored on20/11/2021 15:44:18
Showing2 changed files
... ...
@@ -33,5 +33,4 @@ A simple IRC client, realized as web application
33 33
 
34 34
 - use websockets instead of polling
35 35
 - support commands (e.g. `/nick new_name`)
36
-- get correct user list (seems like it does not update when a user leaves the room)
37 36
 
... ...
@@ -95,12 +95,52 @@ namespace ns_model
95 95
 					console.warn("unhandled event kind: " + event.kind);
96 96
 					break;
97 97
 				}
98
-				case "userlist":
98
+				case "user_list":
99 99
 				{
100 100
 					model.channels[event.data["channel"]].users = event.data["users"];
101 101
 					shall_update_users = true;
102 102
 					break;
103 103
 				}
104
+				case "user_joined":
105
+				{
106
+					model.channels[event.data["channel"]].users.push({"name": event.data["user_name"], "role": ""});
107
+					shall_update_users = true;
108
+					break;
109
+				}
110
+				case "user_parted":
111
+				{
112
+					model.channels[event.data["channel"]].users = model.channels[event.data["channel"]].users.filter
113
+					(
114
+						(user) => (user.name != event.data["user_name"])
115
+					);
116
+					shall_update_users = true;
117
+					break;
118
+				}
119
+				case "user_kicked":
120
+				{
121
+					model.channels[event.data["channel"]].users = model.channels[event.data["channel"]].users.filter
122
+					(
123
+						(user) => (user.name != event.data["user_name"])
124
+					);
125
+					shall_update_users = true;
126
+					break;
127
+				}
128
+				case "user_quit":
129
+				{
130
+					for (let channel_name of event.data["channels"])
131
+					{
132
+						if (model.channels.hasOwnProperty(channel_name))
133
+						{
134
+							model.channels[channel_name].users = model.channels[event.data["channel"]].users.filter
135
+							(
136
+								(user) => (user.name != event.data["user_name"])
137
+							);
138
+						}
139
+					}
140
+					shall_update_spots = true;
141
+					shall_update_users = true;
142
+					break;
143
+				}
104 144
 				case "message_channel":
105 145
 				{
106 146
 					model.channels[event.data["channel"]].entries.push