Browse code

[fix] info entries

Christian FraƟ authored on20/11/2021 16:34:37
Showing1 changed files
... ...
@@ -103,50 +103,71 @@ namespace ns_model
103 103
 				}
104 104
 				case "user_joined":
105 105
 				{
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
-					});
114
-					shall_update_users = true;
115
-					shall_update_entries = true;
106
+					if (model.channels.hasOwnProperty(event.data["channel"]))
107
+					{
108
+						model.channels[event.data["channel"]].users.push({"name": event.data["user_name"], "role": ""});
109
+						model.channels[event.data["channel"]].entries.push
110
+						({
111
+							"timestamp": event.timestamp,
112
+							"kind": enum_entrykind.info,
113
+							"sender": null,
114
+							"content": `${event.data["user_name"]} joined`,
115
+						});
116
+						shall_update_users = true;
117
+						shall_update_entries = true;
118
+					}
119
+					else
120
+					{
121
+						// do nothing
122
+					}
116 123
 					break;
117 124
 				}
118 125
 				case "user_parted":
119 126
 				{
120
-					model.channels[event.data["channel"]].users = model.channels[event.data["channel"]].users.filter
121
-					(
122
-						(user) => (user.name != event.data["user_name"])
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
-					});
131
-					shall_update_users = true;
132
-					shall_update_entries = true;
127
+					if (model.channels.hasOwnProperty(event.data["channel"]))
128
+					{
129
+						model.channels[event.data["channel"]].users = model.channels[event.data["channel"]].users.filter
130
+						(
131
+							(user) => (user.name != event.data["user_name"])
132
+						);
133
+						model.channels[event.data["channel"]].entries.push
134
+						({
135
+							"timestamp": event.timestamp,
136
+							"kind": enum_entrykind.info,
137
+							"sender": null,
138
+							"content": `${event.data["user_name"]} left`,
139
+						});
140
+						shall_update_users = true;
141
+						shall_update_entries = true;
142
+					}
143
+					else
144
+					{
145
+						// do nothing
146
+					}
133 147
 					break;
134 148
 				}
135 149
 				case "user_kicked":
136 150
 				{
137
-					model.channels[event.data["channel"]].users = model.channels[event.data["channel"]].users.filter
138
-					(
139
-						(user) => (user.name != event.data["user_name"])
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
-					});
148
-					shall_update_users = true;
149
-					shall_update_entries = true;
151
+					if (model.channels.hasOwnProperty(event.data["channel"]))
152
+					{
153
+						model.channels[event.data["channel"]].users = model.channels[event.data["channel"]].users.filter
154
+						(
155
+							(user) => (user.name != event.data["user_name"])
156
+						);
157
+						model.channels[event.data["channel"]].entries.push
158
+						({
159
+							"timestamp": event.timestamp,
160
+							"kind": enum_entrykind.info,
161
+							"sender": null,
162
+							"content": `${event.data["user_name"]} was kicked by ${event.data["op_name"]}: ${event.data["reason"]}`,
163
+						});
164
+						shall_update_users = true;
165
+						shall_update_entries = true;
166
+					}
167
+					else
168
+					{
169
+						// do nothing
170
+					}
150 171
 					break;
151 172
 				}
152 173
 				case "user_quit":
... ...
@@ -155,21 +176,21 @@ namespace ns_model
155 176
 					{
156 177
 						if (model.channels.hasOwnProperty(channel_name))
157 178
 						{
158
-							model.channels[channel_name].users = model.channels[event.data["channel"]].users.filter
179
+							model.channels[channel_name].users = model.channels[channel_name].users.filter
159 180
 							(
160 181
 								(user) => (user.name != event.data["user_name"])
161 182
 							);
183
+							model.channels[channel_name].entries.push
184
+							({
185
+								"timestamp": event.timestamp,
186
+								"kind": enum_entrykind.info,
187
+								"sender": null,
188
+								"content": `${event.data["user_name"]} quit`,
189
+							});
190
+							shall_update_entries = true;
191
+							shall_update_users = true;
162 192
 						}
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
-						});
170 193
 					}
171
-					shall_update_entries = true;
172
-					shall_update_users = true;
173 194
 					break;
174 195
 				}
175 196
 				case "message_channel":