Better channel naming and renaming.

Still a few weird bugs, but it's better now
This commit is contained in:
emerson 2022-01-21 12:14:53 -05:00
parent ccfd571e13
commit 4b8ee81b23
4 changed files with 32 additions and 3 deletions

View file

@ -32,7 +32,8 @@ That said, it is usable for basic chatting.
| Channel topics | ✅ | ❌ ||
| Channel powers | ❌ | ❌ ||
| Encrypted rooms | ❌ | ❌ ||
| Message replies <small>(IRCv3)</small> | ❌ | ❌ ||
| Channel renaming <small>(IRCv3)</small> | 🟨 | ❌ | Only when the canonical alias changes |
| Message replies <small>(IRCv3)</small> | ✅ | ❌ ||
| Message reactions <small>(IRCv3)</small> | ❌ | ❌ ||
| Chat history <small>(IRCv3)</small> | ❌ | ❌ ||
| Multiline messages <small>(IRCv3)</small> | ❌ | ❌ ||

View file

@ -43,6 +43,25 @@ export class Channel {
return opStatus;
}
updateRoomName(newNameEvent: any) {
const newName: string = newNameEvent["content"]["alias"];
if (!newName || newName === this.name)
return;
const oldName = this.name;
this.name = newName;
this.ircUsers.forEach((user, username) => {
user.getClients().forEach(client => {
if (client.enabledCaps.has("draft/channel-rename")) {
client.sendMessage(this.server.name, "RENAME", [oldName, this.name, "New channel name set"], new Map());
}
else {
client.sendMessage(this.server.name, "PART", [oldName, "Renaming channel"], new Map());
this.joinNewIRCClient(client, new Map());
}
})
})
}
joinNewIRCClient(client: Client, passedTags: Map<string, string>) {
if (!client.user)
return;
@ -126,6 +145,9 @@ export class Channel {
return;
switch (event["type"]) {
case 'm.room.canonical_alias':
this.updateRoomName(event);
break;
case 'm.room.guest_access':
this.handleMatrixGuestAccess(event);
break;
@ -166,7 +188,6 @@ export class Channel {
case 'm.room.bot.options':
case 'm.room.pinned_events':
case 'm.room.tombstone':
case 'm.room.canonical_alias':
case 'm.room.server_acl':
case 'org.matrix.room.preview_urls':
break;

View file

@ -23,6 +23,7 @@ export class Client {
["account-tag", ""],
["batch", ""],
["draft/chathistory", ""],
["draft/channel-rename", ""],
["echo-message", ""],
["draft/event-playback", ""],
["extended-join", ""],
@ -190,11 +191,13 @@ export class Client {
if (this.user === null)
return;
if (rooms['join']) {
const joinedRooms: Set<Channel> = new Set();
for (const roomId of Object.keys(rooms.join)) {
const targetChannel = this.server.getOrCreateIRCChannel(roomId);
this.user.channels.add(targetChannel);
joinedRooms.add(targetChannel);
rooms.join[roomId].state.events.forEach((nextEvent: any) => targetChannel.routeMatrixEvent(nextEvent));
}
joinedRooms.forEach(c => {if (this.user !== null) this.user.channels.add(c)});
}
if (this.user === null)
return;

View file

@ -44,6 +44,10 @@ export class IRCUser {
return `${this.nick}!${this.ident}@${this.hostname}`;
}
getClients(): Set<Client> {
return this.clients;
}
addClient(client: Client, passedTags: Map<string, string>) {
this.clients.add(client);
if (this.nextBatch !== "") {