| 178 | return []; | 178 | return []; |
| 179 | } | 179 | } |
| 180 | | 180 | |
| | 181 | async function validateGroup(group) { |
| | 182 | if (!group) return; |
| | 183 | |
| | 184 | // Validate that all members exist as characters |
| | 185 | let dirty = false; |
| | 186 | group.members = group.members.filter(member => { |
| | 187 | const character = characters.find(x => x.avatar === member || x.name === member); |
| | 188 | if (!character) { |
| | 189 | const msg = `Warning: Listed member ${member} does not exist as a character. It will be removed from the group.`; |
| | 190 | toastr.warning(msg, 'Group Validation'); |
| | 191 | console.warn(msg); |
| | 192 | dirty = true; |
| | 193 | } |
| | 194 | return character; |
| | 195 | }); |
| | 196 | |
| | 197 | if (dirty) { |
| | 198 | await editGroup(group.id, true, false); |
| | 199 | } |
| | 200 | } |
| | 201 | |
| 181 | export async function getGroupChat(groupId, reload = false) { | 202 | export async function getGroupChat(groupId, reload = false) { |
| 182 | const group = groups.find((x) => x.id === groupId); | 203 | const group = groups.find((x) => x.id === groupId); |
| | 204 | if (!group) { |
| | 205 | console.warn('Group not found', groupId); |
| | 206 | return; |
| | 207 | } |
| | 208 | |
| | 209 | // Run validation before any loading |
| | 210 | validateGroup(group); |
| | 211 | |
| 183 | const chat_id = group.chat_id; | 212 | const chat_id = group.chat_id; |
| 184 | const data = await loadGroupChat(chat_id); | 213 | const data = await loadGroupChat(chat_id); |
| 185 | let freshChat = false; | 214 | let freshChat = false; |