-
Notifications
You must be signed in to change notification settings - Fork 231
metadata-2 #2273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
metadata-2 #2273
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "fmt" | ||
| "maps" | ||
| "net" | ||
| "slices" | ||
| "time" | ||
|
|
||
| "github.com/ergochat/ergo/irc/caps" | ||
|
|
@@ -797,10 +798,12 @@ func (channel *Channel) Settings() (result ChannelSettings) { | |
| } | ||
|
|
||
| func (channel *Channel) SetSettings(settings ChannelSettings) { | ||
| defer channel.MarkDirty(IncludeSettings) | ||
|
|
||
| channel.stateMutex.Lock() | ||
| defer channel.stateMutex.Unlock() | ||
|
|
||
| channel.settings = settings | ||
| channel.stateMutex.Unlock() | ||
| channel.MarkDirty(IncludeSettings) | ||
| } | ||
|
|
||
| func (channel *Channel) setForward(forward string) { | ||
|
|
@@ -827,3 +830,163 @@ func (channel *Channel) UUID() utils.UUID { | |
| defer channel.stateMutex.RUnlock() | ||
| return channel.uuid | ||
| } | ||
|
|
||
| func (session *Session) isSubscribedTo(key string) bool { | ||
| session.client.stateMutex.RLock() | ||
| defer session.client.stateMutex.RUnlock() | ||
|
|
||
| return session.metadataSubscriptions.Has(key) | ||
| } | ||
|
|
||
| func (session *Session) SubscribeTo(keys ...string) ([]string, error) { | ||
| session.client.stateMutex.Lock() | ||
| defer session.client.stateMutex.Unlock() | ||
|
|
||
| if session.metadataSubscriptions == nil { | ||
| session.metadataSubscriptions = make(utils.HashSet[string]) | ||
| } | ||
|
|
||
| var added []string | ||
|
|
||
| maxSubs := session.client.server.Config().Metadata.MaxSubs | ||
|
|
||
| for _, k := range keys { | ||
| if !session.metadataSubscriptions.Has(k) { | ||
| if len(session.metadataSubscriptions) > maxSubs { | ||
| return added, errMetadataTooManySubs | ||
| } | ||
| added = append(added, k) | ||
| session.metadataSubscriptions.Add(k) | ||
| } | ||
| } | ||
|
|
||
| return added, nil | ||
| } | ||
|
|
||
| func (session *Session) UnsubscribeFrom(keys ...string) []string { | ||
| session.client.stateMutex.Lock() | ||
| defer session.client.stateMutex.Unlock() | ||
|
|
||
| var removed []string | ||
|
|
||
| for k := range session.metadataSubscriptions { | ||
| if slices.Contains(keys, k) { | ||
| removed = append(removed, k) | ||
| session.metadataSubscriptions.Remove(k) | ||
| } | ||
| } | ||
|
|
||
| return removed | ||
| } | ||
|
|
||
| func (session *Session) MetadataSubscriptions() utils.HashSet[string] { | ||
| session.client.stateMutex.Lock() | ||
| defer session.client.stateMutex.Unlock() | ||
|
|
||
| return maps.Clone(session.metadataSubscriptions) | ||
| } | ||
|
|
||
| func (channel *Channel) GetMetadata(key string) (string, bool) { | ||
| channel.stateMutex.RLock() | ||
| defer channel.stateMutex.RUnlock() | ||
|
|
||
| val, ok := channel.metadata[key] | ||
| return val, ok | ||
| } | ||
|
|
||
| func (channel *Channel) SetMetadata(key string, value string) { | ||
| defer channel.MarkDirty(IncludeAllAttrs) | ||
|
|
||
| channel.stateMutex.Lock() | ||
| defer channel.stateMutex.Unlock() | ||
|
|
||
| if channel.metadata == nil { | ||
| channel.metadata = make(map[string]string) | ||
| } | ||
|
Comment on lines
+903
to
+905
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete as per above |
||
|
|
||
| channel.metadata[key] = value | ||
| } | ||
|
|
||
| func (channel *Channel) ListMetadata() map[string]string { | ||
| channel.stateMutex.RLock() | ||
| defer channel.stateMutex.RUnlock() | ||
|
|
||
| return maps.Clone(channel.metadata) | ||
| } | ||
|
|
||
| func (channel *Channel) DeleteMetadata(key string) { | ||
| defer channel.MarkDirty(IncludeAllAttrs) | ||
|
|
||
| channel.stateMutex.Lock() | ||
| defer channel.stateMutex.Unlock() | ||
|
|
||
| delete(channel.metadata, key) | ||
| } | ||
|
|
||
| func (channel *Channel) ClearMetadata() map[string]string { | ||
| defer channel.MarkDirty(IncludeAllAttrs) | ||
| channel.stateMutex.Lock() | ||
| defer channel.stateMutex.Unlock() | ||
|
|
||
| oldMap := channel.metadata | ||
| channel.metadata = nil | ||
|
|
||
| return oldMap | ||
| } | ||
|
|
||
| func (channel *Channel) CountMetadata() int { | ||
| channel.stateMutex.RLock() | ||
| defer channel.stateMutex.RUnlock() | ||
|
|
||
| return len(channel.metadata) | ||
| } | ||
|
|
||
| func (client *Client) GetMetadata(key string) (string, bool) { | ||
| client.stateMutex.RLock() | ||
| defer client.stateMutex.RUnlock() | ||
|
|
||
| val, ok := client.metadata[key] | ||
| return val, ok | ||
| } | ||
|
|
||
| func (client *Client) SetMetadata(key string, value string) { | ||
| client.stateMutex.Lock() | ||
| defer client.stateMutex.Unlock() | ||
|
|
||
| if client.metadata == nil { | ||
| client.metadata = make(map[string]string) | ||
| } | ||
|
|
||
| client.metadata[key] = value | ||
| } | ||
|
|
||
| func (client *Client) ListMetadata() map[string]string { | ||
| client.stateMutex.RLock() | ||
| defer client.stateMutex.RUnlock() | ||
|
|
||
| return maps.Clone(client.metadata) | ||
| } | ||
|
|
||
| func (client *Client) DeleteMetadata(key string) { | ||
| client.stateMutex.Lock() | ||
| defer client.stateMutex.Unlock() | ||
|
|
||
| delete(client.metadata, key) | ||
| } | ||
|
|
||
| func (client *Client) ClearMetadata() map[string]string { | ||
| client.stateMutex.Lock() | ||
| defer client.stateMutex.Unlock() | ||
|
|
||
| oldMap := client.metadata | ||
| client.metadata = nil | ||
|
|
||
| return oldMap | ||
| } | ||
|
|
||
| func (client *Client) CountMetadata() int { | ||
| client.stateMutex.RLock() | ||
| defer client.stateMutex.RUnlock() | ||
|
|
||
| return len(client.metadata) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.