This repository was archived by the owner on Oct 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 235
Impl read state #1521
Open
jsoncitron
wants to merge
92
commits into
aiko-chan-ai:main
Choose a base branch
from
jsoncitron:read-state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Impl read state #1521
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
cacc107
Create ReadState.js
jsoncitron 4caccc3
Update ReadState.js
jsoncitron 668ae8a
Create ReadStateManager.js
jsoncitron ef6799c
Add read state type
jsoncitron 5816efe
Super props bc 403
jsoncitron a0e9203
Read state manager on client
jsoncitron b18178e
Update ReadState.js
jsoncitron 78bd160
Create GUILD_FEATURE_ACK.js
jsoncitron b37282e
Create USER_NON_CHANNEL_ACK.js
jsoncitron 8939710
Create MESSAGE_ACK.js
jsoncitron 1d4bac4
Update index.js
jsoncitron 995275f
Update index.js
jsoncitron 8928ee7
Create CHANNEL_PINS_ACK.js
jsoncitron d0bbba1
Update CHANNEL_PINS_ACK.js
jsoncitron 1bdd26b
Update MESSAGE_ACK.js
jsoncitron 5a50c42
Update Options.js
jsoncitron a91c26d
Update Constants.js
jsoncitron 67bf85a
Update USER_NON_CHANNEL_ACK.js
jsoncitron 702af2e
Update ReadStateManager.js
jsoncitron 207235a
Update READY.js
jsoncitron 98a8647
Update ReadStateManager.js
jsoncitron 01dc43b
Update ReadStateManager.js
jsoncitron 055bce9
Update Message.js
jsoncitron 4707d24
Update ReadStateManager.js
jsoncitron 1a80393
Update ReadState.js
jsoncitron e0397aa
Update ReadState.js
jsoncitron 80afecf
Inc mention counter
jsoncitron 04f93db
Update Guild.js
jsoncitron 77e9299
Update CHANNEL_PINS_ACK.js
jsoncitron 1d23fb1
Update CHANNEL_PINS_ACK.js
jsoncitron 07d76a0
Update GUILD_FEATURE_ACK.js
jsoncitron d1bcede
Update MESSAGE_ACK.js
jsoncitron d7aefa6
Update USER_NON_CHANNEL_ACK.js
jsoncitron a2eb23c
Update READY.js
jsoncitron 847153e
Update GuildSettingManager.js
jsoncitron 57f3162
Update Guild.js
jsoncitron ddb98fa
Update Client.js
jsoncitron 742d2cf
Update MessageCreate.js
jsoncitron 9eb58fd
Update READY.js
jsoncitron e56c1ad
Update USER_GUILD_SETTINGS_UPDATE.js
jsoncitron 3454465
Update Constants.js
jsoncitron 9b35aa6
build 375018
jsoncitron a60634e
Update ReadStateManager.js
jsoncitron 6271223
Update ReadState.js
jsoncitron f9cf065
Update ReadStateManager.js
jsoncitron 6b82ac5
Update ReadState.js
jsoncitron 745b2c6
Update TextBasedChannel.js
jsoncitron dc25b6f
Update ClientUser.js
jsoncitron 4b9153a
Update Guild.js
jsoncitron c1d8c6f
Update ClientUser.js
jsoncitron d6918d8
Update Guild.js
jsoncitron 5c80c00
Update Constants.js
jsoncitron 76b330f
Update ReadState.js
jsoncitron ec1eaf6
Create ReadStateFlags.js
jsoncitron 4dbce7d
Update ReadState.js
jsoncitron a2d258b
Update ReadStateManager.js
jsoncitron c4476d0
Update ReadStateManager.js
jsoncitron 76549a1
Update GuildSettingManager.js
jsoncitron 15c56a3
Update GuildSettingManager.js
jsoncitron 9b9a239
Update Client.js
jsoncitron 0ef2515
Update ReadStateManager.js
jsoncitron b51b899
fix crash manager
jsoncitron b459d2f
Update ReadState.js
jsoncitron b17f0f1
Update ReadStateManager.js
jsoncitron 9836abd
Update MESSAGE_ACK.js
jsoncitron 42d26e7
Update GUILD_FEATURE_ACK.js
jsoncitron 9d4ad05
Update CHANNEL_PINS_ACK.js
jsoncitron cd48792
Update MessageCreate.js
jsoncitron d8b0275
Update MESSAGE_ACK.js
jsoncitron 77bc436
Update GUILD_FEATURE_ACK.js
jsoncitron 94135c6
Update CHANNEL_PINS_ACK.js
jsoncitron 7abdde0
Update MessageCreate.js
jsoncitron 5348f21
Update USER_NON_CHANNEL_ACK.js
jsoncitron 26f04c5
Update enums.d.ts
jsoncitron 9d303e1
Update enums.d.ts
jsoncitron c2b138d
Update index.d.ts
jsoncitron 3443255
Update index.d.ts
jsoncitron 3e3f9cb
Client Build number
jsoncitron 290f363
Update rawDataTypes.d.ts
jsoncitron 215ce31
Merge branch 'main' into read-state
jsoncitron c7248a6
377993
jsoncitron 7a81785
380213
jsoncitron 812cc6b
Update Options.js
jsoncitron f0c024e
Update MessageCreate.js
jsoncitron b6ce2e3
Update Constants.js
jsoncitron f52f6f4
Update Options.js
jsoncitron d02d7fc
Update Options.js
jsoncitron 18b3280
Update Constants.js
jsoncitron 113ed08
Update APIRequest.js
jsoncitron 6709453
Update Constants.js
jsoncitron 81a7e3e
Update ReadStateManager.js
jsoncitron fde39a0
Update ReadState.js
jsoncitron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| 'use strict'; | ||
|
|
||
| const { Collection } = require('@discordjs/collection'); | ||
| const { Events } = require('../../../util/Constants'); | ||
| const ReadState = require('../../../structures/ReadState'); | ||
|
|
||
| module.exports = (client, { d: data }) => { | ||
| let readStates = client.readStates.cache.get('CHANNEL'); | ||
|
|
||
| let before = null, after = null; | ||
| if (readStates) { | ||
| after = readStates.get(data.channel_id) ?? null; | ||
| if (after) { | ||
| before = after._copy(); | ||
| after.lastAckedId = data.channel_id; | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.channel_id, | ||
| last_acked_id: null, | ||
| last_pin_timestamp: data.timestamp, | ||
| badge_count: 0, | ||
| read_state_type: 0, | ||
| }); | ||
| readStates.set(after.id, after); | ||
| } | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.channel_id, | ||
| last_acked_id: null, | ||
| last_pin_timestamp: data.timestamp, | ||
| badge_count: 0, | ||
| read_state_type: 0, | ||
| }); | ||
|
|
||
| readStates = new Collection(); | ||
| readStates.set(after.id, after); | ||
| client.readStates.cache.set('CHANNEL', readStates); | ||
| } | ||
|
|
||
| /** | ||
| * Emitted when pins were acked in a channel. | ||
| * @event Client#channelPinsAck | ||
| * @param {?ReadState} before Old read state | ||
| * @param {ReadState} after New read state | ||
| */ | ||
| client.emit(Events.CHANNEL_PINS_ACK, before, after); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| 'use strict'; | ||
|
|
||
| const { Collection } = require('@discordjs/collection'); | ||
| const { Events, ReadStateTypes } = require('../../../util/Constants'); | ||
| const ReadState = require('../../../structures/ReadState'); | ||
|
|
||
| module.exports = (client, { d: data }) => { | ||
| const readStateType = ReadStateTypes[data.ack_type]; | ||
| if (readStateType !== 0 && !readStateType) return; | ||
|
|
||
| let readStates = client.readStates.cache.get(readStateType); | ||
|
|
||
| let before = null, after = null; | ||
| if (readStates) { | ||
| after = readStates.get(data.resource_id) ?? null; | ||
| if (after) { | ||
| before = after._copy(); | ||
| after.lastAckedId = data.entity_id; | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.resource_id, | ||
| last_acked_id: data.entity_id, | ||
| badge_count: 0, | ||
| read_state_type: data.ack_type, | ||
| }); | ||
| readStates.set(after.id, after); | ||
| } | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.resource_id, | ||
| last_acked_id: data.entity_id, | ||
| badge_count: 0, | ||
| read_state_type: data.ack_type, | ||
| }); | ||
|
|
||
| readStates = new Collection(); | ||
| readStates.set(after.id, after); | ||
| client.readStates.set(readStateType, readStates); | ||
| } | ||
|
|
||
| /** | ||
| * Emitted when a guild feature is acked. | ||
| * @event Client#guildFeatureAck | ||
| * @param {?ReadState} before Old read state | ||
| * @param {ReadState} after New read state | ||
| */ | ||
| client.emit(Events.GUILD_FEATURE_ACK, before, after); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 'use strict'; | ||
|
|
||
| const { Collection } = require('@discordjs/collection'); | ||
| const { Events } = require('../../../util/Constants'); | ||
| const ReadState = require('../../../structures/ReadState'); | ||
|
|
||
| module.exports = (client, { d: data }) => { | ||
| let readStates = client.readStates.cache.get('CHANNEL'); | ||
|
|
||
| const lastViewed = data.last_viewed === 0 || data.last_viewed ? data.last_viewed : undefined; | ||
|
|
||
| let before = null, after = null; | ||
| if (readStates) { | ||
| after = readStates.get(data.channel_id) ?? null; | ||
| if (after) { | ||
| before = after._copy(); | ||
| after.lastAckedId = data.channel_id; | ||
| if (lastViewed !== undefined) after.lastViewed = lastViewed; | ||
| if (data.mention_count !== undefined) after.mentionCount = data.mentionCount; | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.channel_id, | ||
| last_acked_id: data.message_id, | ||
| mention_count: data.mention_count, | ||
| last_viewed: lastViewed, | ||
| read_state_type: 0, | ||
| }); | ||
| readStates.set(after.id, after); | ||
| } | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.channel_id, | ||
| last_acked_id: data.message_id, | ||
| mention_count: data.mention_count, | ||
| last_viewed: lastViewed, | ||
| read_state_type: 0, | ||
| }); | ||
|
|
||
| readStates = new Collection(); | ||
| readStates.set(after.id, after); | ||
| client.readStates.cache.set('CHANNEL', readStates); | ||
| } | ||
|
|
||
| /** | ||
| * Emitted when a message is acked. | ||
| * @event Client#messageAck | ||
| * @param {?ReadState} before Old read state | ||
| * @param {ReadState} after New read state | ||
| */ | ||
| client.emit(Events.MESSAGE_ACK, before, after); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 22 additions & 2 deletions
24
src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,26 @@ | ||
| 'use strict'; | ||
|
|
||
| const { Events } = require('../../../util/Constants'); | ||
|
|
||
| module.exports = (client, { d: data }) => { | ||
| const guild = client.guilds.cache.get(data.guild_id); | ||
| if (guild) guild?.settings._patch(data); | ||
| if (data.guild_id === null) { | ||
| const before = client.guildSettings._copy(); | ||
| client.guildSettings._patch(data); | ||
|
|
||
| /** | ||
| * Emitted when guild settings are updated. | ||
| * @event Client#guildSettingsUpdate | ||
| * @param {GuildSettingManager} before The guild setting | ||
| * @param {GuildSettingManager} after The guild setting | ||
| */ | ||
| client.emit(Events.USER_GUILD_SETTINGS_UPDATE, before, client.guildSettings); | ||
| } else { | ||
| let guild = client.guilds.cache.get(data.guild_id); | ||
| if (!guild) return; | ||
|
|
||
| const before = client.guildSettings._copy(); | ||
| guild.settings._patch(data); | ||
|
|
||
| client.emit(Events.USER_GUILD_SETTINGS_UPDATE, before, guild.settings); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| 'use strict'; | ||
|
|
||
| const { Collection } = require('@discordjs/collection'); | ||
| const { Events, ReadStateTypes } = require('../../../util/Constants'); | ||
| const ReadState = require('../../../structures/ReadState'); | ||
|
|
||
| module.exports = (client, { d: data }) => { | ||
| const readStateType = ReadStateTypes[data.ack_type]; | ||
| if (readStateType !== 0 && !readStateType) return; | ||
|
|
||
| let readStates = client.readStates.cache.get(readStateType); | ||
|
|
||
| let before = null, after = null; | ||
| if (readStates) { | ||
| after = readStates.get(data.resource_id) ?? null; | ||
| if (after) { | ||
| before = after._copy(); | ||
| after.lastAckedId = data.entity_id; | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.resource_id, | ||
| last_acked_id: data.entity_id, | ||
| badge_count: 0, | ||
| read_state_type: data.ack_type, | ||
| }); | ||
| readStates.set(after.id, after); | ||
| } | ||
| } else { | ||
| after = new ReadState(client, { | ||
| id: data.resource_id, | ||
| last_acked_id: data.entity_id, | ||
| badge_count: 0, | ||
| read_state_type: data.ack_type, | ||
| }); | ||
|
|
||
| readStates = new Collection(); | ||
| readStates.set(after.id, after); | ||
| client.readStates.cache.set(readStateType, readStates); | ||
| } | ||
|
|
||
| /** | ||
| * Emitted when a user feature is acked. | ||
| * @event Client#userFeatureAck | ||
| * @param {?ReadState} before Old read state | ||
| * @param {ReadState} after New read state | ||
| */ | ||
| client.emit(Events.USER_FEATURE_ACK, before, after); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use GuildSettingManager (intended for Guild) with Client?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/dolfies/discord.py-self/blob/0890463f4339f53ee279bb5f0c4af72f8a718979/discord/message.py#L2338-L2352
state.client.notification_settings is GuildSettings with null guild id