-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: firebase token and user status update. (#381)
* fix: message unread count remove when user not in group. Signed-off-by: Gordon <[email protected]> * fix: group member delete trigger and close ws conn when user logout. Signed-off-by: Gordon <[email protected]> * fix: group member delete trigger and close ws conn when user logout. Signed-off-by: Gordon <[email protected]> * fix: group member delete trigger and close ws conn when user logout. Signed-off-by: Gordon <[email protected]> * fix: group member delete trigger and close ws conn when user logout. Signed-off-by: Gordon <[email protected]> * fix: remove send time and void client messages sort incorrect. Signed-off-by: Gordon <[email protected]> * fix: add avatar and nickname when sessionType is notification. Signed-off-by: Gordon <[email protected]> * fix: add avatar and nickname when sessionType is notification. Signed-off-by: Gordon <[email protected]> * fix: add avatar and nickname when sessionType is notification. Signed-off-by: Gordon <[email protected]> * fix: add avatar and nickname when sessionType is notification. Signed-off-by: Gordon <[email protected]> * fix: some function remove not be used. Signed-off-by: Gordon <[email protected]> * fix: firebase token and user status update. Signed-off-by: Gordon <[email protected]> --------- Signed-off-by: Gordon <[email protected]>
- Loading branch information
1 parent
53aa556
commit 7332710
Showing
29 changed files
with
357 additions
and
514 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,72 @@ | ||
package cache | ||
|
||
import "sync" | ||
|
||
// Cache is a Generic sync.Map structure. | ||
type Cache[K comparable, V any] struct { | ||
m sync.Map | ||
} | ||
|
||
func NewCache[K comparable, V any]() *Cache[K, V] { | ||
return &Cache[K, V]{} | ||
} | ||
|
||
// Load returns the value stored in the map for a key, or nil if no value is present. | ||
func (c *Cache[K, V]) Load(key K) (value V, ok bool) { | ||
rawValue, ok := c.m.Load(key) | ||
if !ok { | ||
return | ||
} | ||
return rawValue.(V), ok | ||
} | ||
|
||
// Store sets the value for a key. | ||
func (c *Cache[K, V]) Store(key K, value V) { | ||
c.m.Store(key, value) | ||
} | ||
|
||
// StoreAll sets all value by f's key. | ||
func (c *Cache[K, V]) StoreAll(f func(value V) K, values []V) { | ||
for _, v := range values { | ||
c.m.Store(f(v), v) | ||
} | ||
} | ||
|
||
// LoadOrStore returns the existing value for the key if present. | ||
func (c *Cache[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) { | ||
rawValue, loaded := c.m.LoadOrStore(key, value) | ||
return rawValue.(V), loaded | ||
} | ||
|
||
// Delete deletes the value for a key. | ||
func (c *Cache[K, V]) Delete(key K) { | ||
c.m.Delete(key) | ||
} | ||
|
||
// DeleteAll deletes all values. | ||
func (c *Cache[K, V]) DeleteAll() { | ||
c.m.Range(func(key, value interface{}) bool { | ||
c.m.Delete(key) | ||
return true | ||
}) | ||
} | ||
|
||
// RangeAll returns all values in the map. | ||
func (c *Cache[K, V]) RangeAll() (values []V) { | ||
c.m.Range(func(rawKey, rawValue interface{}) bool { | ||
values = append(values, rawValue.(V)) | ||
return true | ||
}) | ||
return values | ||
} | ||
|
||
// RangeCon returns values in the map that satisfy condition f. | ||
func (c *Cache[K, V]) RangeCon(f func(key K, value V) bool) (values []V) { | ||
c.m.Range(func(rawKey, rawValue interface{}) bool { | ||
if f(rawKey.(K), rawValue.(V)) { | ||
values = append(values, rawValue.(V)) | ||
} | ||
return true | ||
}) | ||
return values | ||
} |
This file contains 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.