Browse code

[add] possibility to open queries

Christian Fraß authored on20/11/2021 15:20:07
Showing5 changed files
... ...
@@ -34,5 +34,4 @@ A simple IRC client, realized as web application
34 34
 - use websockets instead of polling
35 35
 - support commands (e.g. `/nick new_name`)
36 36
 - get correct user list (seems like it does not update when a user leaves the room)
37
-- add possibility to start query
38 37
 
... ...
@@ -93,6 +93,25 @@ namespace ns_control
93 93
 				}
94 94
 			);
95 95
 		}
96
+		// open query
97
+		{
98
+			document.querySelectorAll(".user").forEach
99
+			(
100
+				(dom_user) =>
101
+				{
102
+					register_listener
103
+					(
104
+						(dom_user as HTMLElement),
105
+						"click",
106
+						(e) =>
107
+						{
108
+							const user_name: string = JSON.parse(dom_user.getAttribute("rel"));
109
+							ns_model.open_query(model, user_name);
110
+						}
111
+					);
112
+				}
113
+			);
114
+		}
96 115
 	}
97 116
 	
98 117
 }
... ...
@@ -276,6 +276,27 @@ namespace ns_model
276 276
 	}
277 277
 	
278 278
 	
279
+	/**
280
+	 * adds a query to a user as spot
281
+	 */
282
+	export function open_query
283
+	(
284
+		model: type_model,
285
+		user_name: string
286
+	): void
287
+	{
288
+		if ((user_name !== model.nickname) && (! model.queries.hasOwnProperty(user_name)))
289
+		{
290
+			model.queries[user_name] = {"entries": []};
291
+			notify(model, "spots_changed");
292
+		}
293
+		else
294
+		{
295
+			// do nothing
296
+		}
297
+	}
298
+	
299
+	
279 300
 	/**
280 301
 	 * sets up the model
281 302
 	 */
... ...
@@ -112,6 +112,7 @@ namespace ns_view
112 112
 	 */
113 113
 	function update_users
114 114
 	(
115
+		conf: type_conf,
115 116
 		model: type_model
116 117
 	): void
117 118
 	{
... ...
@@ -165,8 +166,11 @@ namespace ns_view
165 166
 				dom_name.style.color = get_usercolor(user.name);
166 167
 				dom_user.appendChild(dom_name);
167 168
 			}
169
+			dom_user.setAttribute("rel", JSON.stringify(user.name));
168 170
 			dom_users.appendChild(dom_user);
169 171
 		}
172
+		// meeh…
173
+		ns_control.setup(conf, model);
170 174
 	}
171 175
 
172 176
 
... ...
@@ -198,7 +202,7 @@ namespace ns_view
198 202
 		ns_model.listen(model, "state_changed", () => {update_state(model);});
199 203
 		ns_model.listen(model, "spots_changed", () => {update_spots(conf, model);});
200 204
 		ns_model.listen(model, "entries_changed", () => {update_entries(model);});
201
-		ns_model.listen(model, "users_changed", () => {update_users(model);});
205
+		ns_model.listen(model, "users_changed", () => {update_users(conf, model);});
202 206
 		ns_model.listen(model, "message_sent", () => {clear_content();});
203 207
 	}
204 208
 	
... ...
@@ -90,6 +90,11 @@ label
90 90
 	&:after {content: "]";}
91 91
 }
92 92
 
93
+.user
94
+{
95
+	cursor: pointer;
96
+}
97
+
93 98
 .pane
94 99
 {
95 100
 	background-color: hsl(@hue, 0%, 12.5%);