Browse code

[mod] added view for info entries

Christian FraƟ authored on20/11/2021 16:01:55
Showing4 changed files
... ...
@@ -104,7 +104,15 @@ namespace ns_model
104 104
 				case "user_joined":
105 105
 				{
106 106
 					model.channels[event.data["channel"]].users.push({"name": event.data["user_name"], "role": ""});
107
+					model.channels[event.data["channel"]].entries.push
108
+					({
109
+						"timestamp": event.timestamp,
110
+						"kind": enum_entrykind.info,
111
+						"sender": null,
112
+						"content": `${event.data["user_name"]} joined`,
113
+					});
107 114
 					shall_update_users = true;
115
+					shall_update_entries = true;
108 116
 					break;
109 117
 				}
110 118
 				case "user_parted":
... ...
@@ -113,7 +121,15 @@ namespace ns_model
113 121
 					(
114 122
 						(user) => (user.name != event.data["user_name"])
115 123
 					);
124
+					model.channels[event.data["channel"]].entries.push
125
+					({
126
+						"timestamp": event.timestamp,
127
+						"kind": enum_entrykind.info,
128
+						"sender": null,
129
+						"content": `${event.data["user_name"]} left`,
130
+					});
116 131
 					shall_update_users = true;
132
+					shall_update_entries = true;
117 133
 					break;
118 134
 				}
119 135
 				case "user_kicked":
... ...
@@ -122,7 +138,15 @@ namespace ns_model
122 138
 					(
123 139
 						(user) => (user.name != event.data["user_name"])
124 140
 					);
141
+					model.channels[event.data["channel"]].entries.push
142
+					({
143
+						"timestamp": event.timestamp,
144
+						"kind": enum_entrykind.info,
145
+						"sender": null,
146
+						"content": `${event.data["user_name"]} was kicked by ${event.data["op_name"]}: ${event.data["reason"]}`,
147
+					});
125 148
 					shall_update_users = true;
149
+					shall_update_entries = true;
126 150
 					break;
127 151
 				}
128 152
 				case "user_quit":
... ...
@@ -136,8 +160,15 @@ namespace ns_model
136 160
 								(user) => (user.name != event.data["user_name"])
137 161
 							);
138 162
 						}
163
+						model.channels[channel_name].entries.push
164
+						({
165
+							"timestamp": event.timestamp,
166
+							"kind": enum_entrykind.info,
167
+							"sender": null,
168
+							"content": `${event.data["user_name"]} quit`,
169
+						});
139 170
 					}
140
-					shall_update_spots = true;
171
+					shall_update_entries = true;
141 172
 					shall_update_users = true;
142 173
 					break;
143 174
 				}
... ...
@@ -146,6 +177,7 @@ namespace ns_model
146 177
 					model.channels[event.data["channel"]].entries.push
147 178
 					({
148 179
 						"timestamp": event.timestamp,
180
+						"kind": enum_entrykind.message,
149 181
 						"sender": event.data["sender"],
150 182
 						"content": event.data["content"],
151 183
 					});
... ...
@@ -166,6 +198,7 @@ namespace ns_model
166 198
 					model.queries[event.data["user_name"]].entries.push
167 199
 					({
168 200
 						"timestamp": event.timestamp,
201
+						"kind": enum_entrykind.message,
169 202
 						"sender": event.data["sender"],
170 203
 						"content": event.data["content"],
171 204
 					});
... ...
@@ -34,6 +34,13 @@ enum enum_state
34 34
 }
35 35
 
36 36
 
37
+enum enum_entrykind
38
+{
39
+	message = "message",
40
+	info = "info",
41
+}
42
+
43
+
37 44
 type type_event =
38 45
 {
39 46
 	timestamp: int;
... ...
@@ -52,7 +59,8 @@ type type_spot =
52 59
 type type_entry =
53 60
 {
54 61
 	timestamp: int;
55
-	sender: string;
62
+	kind: string;
63
+	sender: (null | string);
56 64
 	content: string;
57 65
 };
58 66
 
... ...
@@ -80,28 +80,61 @@ namespace ns_view
80 80
 		dom_entries.textContent = "";
81 81
 		for (const entry of entries)
82 82
 		{
83
-			let dom_entry: HTMLLIElement = document.createElement("li");
84
-			dom_entry.classList.add("entry");
83
+			switch (entry.kind)
85 84
 			{
86
-				let dom_time: HTMLSpanElement = document.createElement("span");
87
-				dom_time.classList.add("entry_time");
88
-				dom_time.textContent = (new Date(entry.timestamp*1000)).toISOString().slice(11, 19);
89
-				dom_entry.appendChild(dom_time);
85
+				default:
86
+				{
87
+					console.warn(`unhandled entry kind '${entry.kind}'`);
88
+					break;
89
+				}
90
+				case enum_entrykind.info:
91
+				{
92
+					let dom_entry: HTMLLIElement = document.createElement("li");
93
+					dom_entry.classList.add("entry");
94
+					dom_entry.classList.add("entry_info");
95
+					{
96
+						let dom_time: HTMLSpanElement = document.createElement("span");
97
+						dom_time.classList.add("entry_time");
98
+						dom_time.textContent = (new Date(entry.timestamp*1000)).toISOString().slice(11, 19);
99
+						dom_entry.appendChild(dom_time);
100
+					}
101
+					{
102
+						let dom_content: HTMLSpanElement = document.createElement("span");
103
+						dom_content.classList.add("entry_content");
104
+						dom_content.textContent = `-- ${entry.content}`;
105
+						dom_entry.appendChild(dom_content);
106
+					}
107
+					dom_entries.appendChild(dom_entry);
108
+					break;
109
+				}
110
+				case enum_entrykind.message:
111
+				{
112
+					let dom_entry: HTMLLIElement = document.createElement("li");
113
+					dom_entry.classList.add("entry");
114
+					dom_entry.classList.add("entry_message");
115
+					{
116
+						let dom_time: HTMLSpanElement = document.createElement("span");
117
+						dom_time.classList.add("entry_time");
118
+						dom_time.textContent = (new Date(entry.timestamp*1000)).toISOString().slice(11, 19);
119
+						dom_entry.appendChild(dom_time);
120
+					}
121
+					{
122
+						let dom_sender: HTMLSpanElement = document.createElement("span");
123
+						dom_sender.classList.add("entry_sender");
124
+						dom_sender.style.color = get_usercolor(entry.sender);
125
+						dom_sender.textContent = entry.sender;
126
+						dom_entry.appendChild(dom_sender);
127
+					}
128
+					{
129
+						let dom_content: HTMLSpanElement = document.createElement("span");
130
+						dom_content.classList.add("entry_content");
131
+						dom_content.textContent = entry.content;
132
+						dom_entry.appendChild(dom_content);
133
+					}
134
+					dom_entries.appendChild(dom_entry);
135
+					break;
136
+				}
90 137
 			}
91
-			{
92
-				let dom_sender: HTMLSpanElement = document.createElement("span");
93
-				dom_sender.classList.add("entry_sender");
94
-				dom_sender.style.color = get_usercolor(entry.sender);
95
-				dom_sender.textContent = entry.sender;
96
-				dom_entry.appendChild(dom_sender);
97
-			}
98
-			{
99
-				let dom_content: HTMLSpanElement = document.createElement("span");
100
-				dom_content.classList.add("entry_content");
101
-				dom_content.textContent = entry.content;
102
-				dom_entry.appendChild(dom_content);
103
-			}
104
-			dom_entries.appendChild(dom_entry);
105 138
 		}
106 139
 		dom_entries.scrollTo(0, dom_entries["scrollTopMax"]);
107 140
 	}
... ...
@@ -43,29 +43,42 @@ label
43 43
 	margin: 16px 0;
44 44
 }
45 45
 
46
-.entry > *
46
+.entry
47 47
 {
48
-	display: inline-block;
49
-}
50
-
51
-.entry_time
52
-{
53
-	margin: 0 4px;
48
+	& > *
49
+	{
50
+		display: inline-block;
51
+		margin: 0 4px;
52
+	}
54 53
 	
55
-	color: hsl(@hue, 0%, 75%);
54
+	& .entry_time
55
+	{
56
+		color: hsl(@hue, 0%, 75%);
57
+		
58
+		&:before {content: "<";}
59
+		&:after {content: ">";}
60
+	}
56 61
 	
57
-	&:before {content: "<";}
58
-	&:after {content: ">";}
59
-}
60
-
61
-.entry_sender
62
-{
63
-	margin: 0 4px;
62
+	& .entry_sender
63
+	{
64
+		&:before {content: "[";}
65
+		&:after {content: "]";}
66
+	}
64 67
 	
65
-	// font-weight: bold;
68
+	&.entry_message
69
+	{
70
+		& .entry_content
71
+		{
72
+		}
73
+	}
66 74
 	
67
-	&:before {content: "[";}
68
-	&:after {content: "]";}
75
+	&.entry_info
76
+	{
77
+		& .entry_content
78
+		{
79
+			color: hsl(@hue, 0%, 50%);
80
+		}
81
+	}
69 82
 }
70 83
 
71 84
 .spot
... ...
@@ -78,16 +91,16 @@ label
78 91
 	{
79 92
 		font-weight: bold;
80 93
 	}
81
-}
82
-
83
-.spot_kind
84
-{
85
-	display: none;
86
-	
87
-	padding: 4px;
88 94
 	
89
-	&:before {content: "[";}
90
-	&:after {content: "]";}
95
+	& .spot_kind
96
+	{
97
+		display: none;
98
+		
99
+		padding: 4px;
100
+		
101
+		&:before {content: "[";}
102
+		&:after {content: "]";}
103
+	}
91 104
 }
92 105
 
93 106
 .user