ca6061ae349e3f60ceff37f040d1c9b7025e1583
Christian Fraß [ini]

Christian Fraß authored 2 years ago

1) type int = number;
2) type float = number;
3) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

4) 
Christian Fraß [ini]

Christian Fraß authored 2 years ago

5) var _conf: any = null;
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

6) 
Christian Fraß [ini]

Christian Fraß authored 2 years ago

7) 
8) function get_timestamp(): int
9) {
10) 	return Math.floor(Date.now()/1000);
11) }
12) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

13) 
Christian Fraß [ini]

Christian Fraß authored 2 years ago

14) function hash_string_to_unit(x: string): float
15) {
16) 	return (x.split("").reduce((x, y) => ((x + y.charCodeAt(0)) % 32), 0) / 32);
17) }
18) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

19) 
Christian Fraß [ini]

Christian Fraß authored 2 years ago

20) function get_usercolor(name: string): string
21) {
22) 	const hue: float = hash_string_to_unit(name);
23) 	return `hsl(${(hue*360).toFixed(2)},50%,75%)`;
24) }
25) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

26) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

27) async function backend_call(connection_id: (null | string), action: string, data: any): Promise<any>
Christian Fraß [ini]

Christian Fraß authored 2 years ago

28) {
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

29) 	const response = await fetch
30) 	(
Christian Fraß [mod] minor adjustments

Christian Fraß authored 2 years ago

31) 		`${_conf["backend"]["scheme"]}://${_conf["backend"]["host"]}:${_conf["backend"]["port"].toFixed(0)}/${_conf["backend"]["path"]}`,
Christian Fraß [ini]

Christian Fraß authored 2 years ago

32) 		{
33) 			"method": "POST",
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

34) 			"body": JSON.stringify({"id": connection_id, "action": action, "data": data}),
Christian Fraß [ini]

Christian Fraß authored 2 years ago

35) 		}
36) 	);
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

37) 	if (response.ok)
38) 	{
Christian Fraß [ini]

Christian Fraß authored 2 years ago

39) 		return response.json();
40) 	}
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

41) 	else
42) 	{
Christian Fraß [ini]

Christian Fraß authored 2 years ago

43) 		console.error(response.text());
44) 		return Promise.reject<any>(new Error("backend call failed"));
45) 	}
46) }
47) 
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

48) enum enum_state
49) {
50) 	offline = "offline",
51) 	connecting = "connecting",
52) 	online = "online",
53) }
54) 
55) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

56) type type_event =
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

57) {
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

58) 	timestamp: int;
59) 	kind: string;
60) 	data: any;
61) };
62) 
63) 
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

64) type type_spot =
65) {
66) 	kind: string;
67) 	name: string;
68) };
69) 
70) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

71) type type_entry =
72) {
73) 	timestamp: int;
74) 	sender: string;
75) 	content: string;
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

76) };
77) 
78) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

79) type type_user =
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

80) {
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

81) 	name: string;
82) 	role: string;
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

83) };
84) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

85) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

86) type type_channel =
Christian Fraß [ini]

Christian Fraß authored 2 years ago

87) {
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

88) 	users: Array<type_user>;
89) 	entries: Array<type_entry>;
90) };
91) 
92) 
93) type type_query =
94) {
95) 	entries: Array<type_entry>;
96) };
97) 
98) 
99) type type_model =
100) {
101) 	state: enum_state;
102) 	connection_id: (null | string);
103) 	nickname: (null | string);
104) 	channels: Record<string, type_channel>;
105) 	queries: Record<string, type_query>;
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

106) 	active: (null | type_spot);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

107) };
108) 
109) 
110) 
111) function model_set_state(model: type_model, state: enum_state): void
112) {
113) 	model.state = state;
114) 	view_update_state(model);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

115) }
116) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

117) 
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

118) function model_set_active(model: type_model, spot: type_spot): void
Christian Fraß [ini]

Christian Fraß authored 2 years ago

119) {
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

120) 	model.active = spot;
121) 	view_update_spots(model);
122) 	view_update_entries(model);
123) 	view_update_users(model);
124) }
125) 
126) 
127) function model_process_events(model: type_model, events: Array<type_event>): void
128) {
129) 	let shall_update_spots: boolean = false;
130) 	let shall_update_entries: boolean = false;
131) 	let shall_update_users: boolean = false;
132) 	for (const event of events)
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

133) 	{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

134) 		switch (event.kind)
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

135) 		{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

136) 			default:
Christian Fraß [mod] style

Christian Fraß authored 2 years ago

137) 			{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

138) 				console.warn("unhandled event kind: " + event.kind);
139) 				break;
Christian Fraß [mod] style

Christian Fraß authored 2 years ago

140) 			}
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

141) 			case "userlist":
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

142) 			{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

143) 				model.channels[event.data["channel"]].users = event.data["users"];
144) 				shall_update_users = true;
145) 				break;
146) 			}
147) 			case "message_channel":
148) 			{
149) 				model.channels[event.data["channel"]].entries.push
150) 				({
151) 					"timestamp": event.timestamp,
152) 					"sender": event.data["sender"],
153) 					"content": event.data["content"],
154) 				});
155) 				shall_update_entries = true;
156) 				break;
157) 			}
158) 			case "message_query":
159) 			{
160) 				if (! model.queries.hasOwnProperty(event.data["user_name"]))
161) 				{
162) 					model.queries[event.data["user_name"]] = {"entries": []};
163) 					shall_update_spots = true;
164) 				}
165) 				else
166) 				{
167) 					// do nothing
168) 				}
169) 				model.queries[event.data["user_name"]].entries.push
170) 				({
171) 					"timestamp": event.timestamp,
172) 					"sender": event.data["sender"],
173) 					"content": event.data["content"],
174) 				});
175) 				shall_update_entries = true;
176) 				break;
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

177) 			}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

178) 		}
179) 	}
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

180) 	
181) 	// update view
182) 	{
183) 		if (shall_update_spots) view_update_spots(model);
184) 		if (shall_update_entries) view_update_entries(model);
185) 		if (shall_update_users) view_update_users(model);
186) 	}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

187) }
188) 
189) 
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

190) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

191) function view_update_state(model: type_model): void
192) {
193) 	document.querySelector("body").setAttribute("class", model.state);
194) }
195) 
196) 
197) function view_update_spots(model: type_model): void
198) {
199) 	let dom_spots: HTMLUListElement = document.querySelector("#spots");
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

200) 	const spots: Array<type_spot> = (
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

201) 		[]
202) 		.concat(Object.keys(model.channels).map((name) => ({"kind": "channel", "name": name})))
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

203) 		.concat(Object.keys(model.queries).map((name) => ({"kind": "query", "name": name})))
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

204) 	);
205) 	dom_spots.textContent = "";
206) 	for (const spot of spots)
207) 	{
208) 		let dom_spot: HTMLLIElement = document.createElement("li");
209) 		dom_spot.classList.add("spot");
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

210) 		{
211) 			let dom_kind: HTMLSpanElement = document.createElement("span");
212) 			dom_kind.classList.add("spot_kind");
213) 			dom_kind.textContent = spot.kind;
214) 			dom_spot.appendChild(dom_kind);
215) 		}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

216) 		{
217) 			let dom_name: HTMLSpanElement = document.createElement("span");
218) 			dom_name.classList.add("spot_sender");
219) 			dom_name.textContent = spot.name;
220) 			dom_spot.appendChild(dom_name);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

221) 		}
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

222) 		dom_spot.classList.toggle("spot_active", ((spot.kind === model.active.kind) && (spot.name === model.active.name)));
223) 		dom_spot.addEventListener
224) 		(
225) 			"click",
226) 			(e) =>
227) 			{
228) 				model_set_active(model, spot);
229) 			}
230) 		);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

231) 		dom_spots.appendChild(dom_spot);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

232) 	}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

233) }
234) 
235) 
236) function view_update_entries(model: type_model): void
237) {
238) 	let dom_entries: HTMLUListElement = document.querySelector("#entries");
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

239) 	let entries: Array<type_entry>;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

240) 	switch (model.active.kind)
Christian Fraß [mod] style

Christian Fraß authored 2 years ago

241) 	{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

242) 		case "channel":
243) 		{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

244) 			entries = model.channels[model.active.name].entries;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

245) 			break;
246) 		}
247) 		case "query":
248) 		{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

249) 			entries = model.queries[model.active.name].entries;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

250) 			break;
251) 		}
Christian Fraß [mod] style

Christian Fraß authored 2 years ago

252) 	}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

253) 	dom_entries.textContent = "";
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

254) 	for (const entry of entries)
Christian Fraß [mod] style

Christian Fraß authored 2 years ago

255) 	{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

256) 		let dom_entry: HTMLLIElement = document.createElement("li");
257) 		dom_entry.classList.add("entry");
258) 		{
259) 			let dom_time: HTMLSpanElement = document.createElement("span");
260) 			dom_time.classList.add("entry_time");
261) 			dom_time.textContent = (new Date(entry.timestamp*1000)).toISOString().slice(11, 19);
262) 			dom_entry.appendChild(dom_time);
263) 		}
264) 		{
265) 			let dom_sender: HTMLSpanElement = document.createElement("span");
266) 			dom_sender.classList.add("entry_sender");
267) 			dom_sender.style.color = get_usercolor(entry.sender);
268) 			dom_sender.textContent = entry.sender;
269) 			dom_entry.appendChild(dom_sender);
270) 		}
271) 		{
272) 			let dom_content: HTMLSpanElement = document.createElement("span");
273) 			dom_content.classList.add("entry_content");
274) 			dom_content.textContent = entry.content;
275) 			dom_entry.appendChild(dom_content);
276) 		}
277) 		dom_entries.appendChild(dom_entry);
Christian Fraß [mod] style

Christian Fraß authored 2 years ago

278) 	}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

279) 	dom_entries.scrollTo(0, dom_entries["scrollTopMax"]);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

280) }
281) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

282) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

283) function view_update_users(model: type_model): void
Christian Fraß [ini]

Christian Fraß authored 2 years ago

284) {
285) 	let dom_users: HTMLUListElement = document.querySelector("#users");
286) 	dom_users.textContent = "";
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

287) 	let users: Array<type_user>;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

288) 	switch (model.active.kind)
289) 	{
290) 		default:
291) 		{
292) 			console.warn("unhandled kind: " + model.active.kind);
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

293) 			users = [];
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

294) 			break;
295) 		}
296) 		case "channel":
297) 		{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

298) 			users = model.channels[model.active.name].users;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

299) 			break;
300) 		}
301) 		case "query":
302) 		{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

303) 			users = [{"name": model.nickname, "role": ""}, {"name": model.active.name, "role": ""}];
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

304) 			break;
305) 		}
306) 	}
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

307) 	const users_sorted: Array<type_user> = users.sort
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

308) 	(
309) 		(x, y) =>
310) 		(
Christian Fraß [ini]

Christian Fraß authored 2 years ago

311) 			(x.role >= y.role)
312) 			? -1
313) 			: (
314) 				(x.role === y.role)
315) 				? ((x.name < y.name) ? -1 : +1)
316) 				: +1
317) 			)
318) 		)
319) 	);
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

320) 	for (const user of users_sorted)
321) 	{
Christian Fraß [ini]

Christian Fraß authored 2 years ago

322) 		let dom_user: HTMLLIElement = document.createElement("li");
323) 		dom_user.classList.add("user");
324) 		{
325) 			let dom_role: HTMLSpanElement = document.createElement("span");
326) 			dom_role.textContent = user.role;
327) 			dom_user.appendChild(dom_role);
328) 		}
329) 		{
330) 			let dom_name: HTMLSpanElement = document.createElement("span");
331) 			dom_name.textContent = user.name;
332) 			dom_name.style.color = get_usercolor(user.name);
333) 			dom_user.appendChild(dom_name);
334) 		}
335) 		dom_users.appendChild(dom_user);
336) 	}
337) }
338) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

339) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

340) function view_setup(model: type_model): void
Christian Fraß [ini]

Christian Fraß authored 2 years ago

341) {
342) 	document.querySelector<HTMLInputElement>("#channel").value = _conf["irc"]["predefined_channel"];
343) 	document.querySelector<HTMLInputElement>("#nickname").value = (_conf["irc"]["predefined_nickname_prefix"] + (Math.random()*100).toFixed(0));
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

344) 	setInterval
345) 	(
346) 		async () =>
347) 		{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

348) 			switch (model.state)
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

349) 			{
350) 				default:
351) 				{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

352) 					throw (new Error("invalid state: " + model.state));
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

353) 					break;
354) 				}
355) 				case enum_state.offline:
356) 				{
Christian Fraß [ini]

Christian Fraß authored 2 years ago

357) 					// do nothing
358) 					break;
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

359) 				}
360) 				case enum_state.connecting:
361) 				{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

362) 					const ready: boolean = await backend_call(model.connection_id, "check", null);
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

363) 					if (ready)
364) 					{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

365) 						model_set_state(model, enum_state.online);
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

366) 					}
367) 					else
368) 					{
369) 						// do nothing
Christian Fraß [ini]

Christian Fraß authored 2 years ago

370) 					}
371) 					break;
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

372) 				}
373) 				case enum_state.online:
374) 				{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

375) 					const events: Array<type_event> = await backend_call(model.connection_id, "fetch", null);
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

376) 					model_process_events(model, events);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

377) 					break;
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

378) 				}
Christian Fraß [ini]

Christian Fraß authored 2 years ago

379) 			}
380) 		},
381) 		_conf["settings"]["poll_interval_in_milliseconds"]
382) 	);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

383) 	model_set_state(model, enum_state.offline);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

384) }
385) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

386) 
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

387) function control_setup(model: type_model): void
Christian Fraß [ini]

Christian Fraß authored 2 years ago

388) {
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

389) 	document.querySelector("#connect > form").addEventListener
390) 	(
Christian Fraß [ini]

Christian Fraß authored 2 years ago

391) 		"submit",
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

392) 		async (event) =>
393) 		{
Christian Fraß [mod] minor adjustments

Christian Fraß authored 2 years ago

394) 			event.preventDefault();
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

395) 			
396) 			model_set_state(model, enum_state.connecting);
397) 			
Christian Fraß [ini]

Christian Fraß authored 2 years ago

398) 			let dom_nickname: HTMLInputElement = document.querySelector<HTMLInputElement>("#nickname");
399) 			let dom_channel: HTMLInputElement = document.querySelector<HTMLInputElement>("#channel");
400) 			const nickname: string = dom_nickname.value;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

401) 			const channel_names: Array<string> = dom_channel.value.split(",");
402) 			
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

403) 			const connection_id: string = await backend_call
404) 			(
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

405) 				model.connection_id,
Christian Fraß [ini]

Christian Fraß authored 2 years ago

406) 				"connect",
407) 				{
408) 					"server": _conf["irc"]["server"],
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

409) 					"channels": channel_names,
Christian Fraß [ini]

Christian Fraß authored 2 years ago

410) 					"nickname": nickname,
411) 				}
412) 			);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

413) 			model.connection_id = connection_id;
414) 			model.nickname = nickname;
415) 			for (const channel_name of channel_names)
416) 			{
417) 				model.channels[channel_name] =
418) 				{
419) 					"users": [],
420) 					"entries": [],
421) 				};
422) 			}
423) 			// TODO: can crash
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

424) 			model_set_active(model, {"kind": "channel", "name": channel_names[0]});
Christian Fraß [ini]

Christian Fraß authored 2 years ago

425) 		}
426) 	);
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

427) 	document.querySelector("#disconnect").addEventListener
428) 	(
Christian Fraß [ini]

Christian Fraß authored 2 years ago

429) 		"click",
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

430) 		async (event) =>
431) 		{
432) 			await backend_call
433) 			(
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

434) 				model.connection_id,
Christian Fraß [ini]

Christian Fraß authored 2 years ago

435) 				"disconnect",
436) 				null
437) 			);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

438) 			model_set_state(model, enum_state.offline);
439) 			model.connection_id = null;
Christian Fraß [ini]

Christian Fraß authored 2 years ago

440) 		}
441) 	);
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

442) 	document.querySelector("#main > form").addEventListener
443) 	(
Christian Fraß [ini]

Christian Fraß authored 2 years ago

444) 		"submit",
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

445) 		async (e) =>
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

446) 		{
Christian Fraß [ini]

Christian Fraß authored 2 years ago

447) 			event.preventDefault();
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

448) 			
449) 			let dom_content: HTMLInputElement = document.querySelector<HTMLInputElement>("#content");
450) 			const content: string = dom_content.value;
451) 			dom_content.value = "";
452) 			dom_content.focus();
453) 			switch (model.active.kind)
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

454) 			{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

455) 				case "channel":
456) 				{
457) 					const event: type_event =
458) 					{
459) 						"timestamp": get_timestamp(),
460) 						"kind": "message_channel",
461) 						"data":
462) 						{
463) 							"channel": model.active.name,
464) 							"sender": model.nickname,
465) 							"content": content,
466) 						}
467) 					};
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

468) 					model_process_events(model, [event]);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

469) 					view_update_entries(model);
470) 					backend_call
471) 					(
472) 						model.connection_id,
473) 						"send_channel",
474) 						{
475) 							"channel": model.active.name,
476) 							"content": content,
477) 						}
478) 					);
479) 					break;
Christian Fraß [ini]

Christian Fraß authored 2 years ago

480) 				}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

481) 				case "query":
Christian Fraß [ini]

Christian Fraß authored 2 years ago

482) 				{
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

483) 					const event: type_event =
484) 					{
485) 						"timestamp": get_timestamp(),
486) 						"kind": "message_query",
487) 						"data":
488) 						{
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

489) 							"user_name": model.active.name,
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

490) 							"sender": model.nickname,
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

491) 							"content": content,
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

492) 						}
493) 					};
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

494) 					model_process_events(model, [event]);
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

495) 					backend_call
496) 					(
497) 						model.connection_id,
498) 						"send_query",
499) 						{
500) 							"receiver": model.active.name,
501) 							"content": content,
502) 						}
503) 					);
504) 					break;
Christian Fraß [ini]

Christian Fraß authored 2 years ago

505) 				}
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

506) 			}
Christian Fraß [ini]

Christian Fraß authored 2 years ago

507) 		}
508) 	);
509) }
510) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

511) 
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

512) var _model;
Christian Fraß [ini]

Christian Fraß authored 2 years ago

513) async function main(): Promise<void>
514) {
515) 	_conf = await fetch("conf.json").then(x => x.json());
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

516) 	const model: type_model =
517) 	{
518) 		"state": enum_state.offline,
519) 		"connection_id": null,
520) 		"nickname": null,
521) 		"channels": {},
522) 		"queries": {},
523) 		"active": null,
524) 	};
Christian Fraß [mod] selektives view-update

Christian Fraß authored 2 years ago

525) _model = model;
Christian Fraß [mod] start support for mul...

Christian Fraß authored 2 years ago

526) 	view_setup(model);
527) 	control_setup(model);
Christian Fraß [ini]

Christian Fraß authored 2 years ago

528) }
529) 
Christian Fraß [mod] adjustment for connec...

Christian Fraß authored 2 years ago

530) 
Christian Fraß [ini]

Christian Fraß authored 2 years ago

531) function init(): void
532) {
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

533) 	document.addEventListener
534) 	(
Christian Fraß [ini]

Christian Fraß authored 2 years ago

535) 		"DOMContentLoaded",
Christian Fraß [mod] pack model stuff into...

Christian Fraß authored 2 years ago

536) 		(event) => {main();}