mirror of
https://github.com/tinode/chat.git
synced 2025-03-14 10:05:07 +00:00
more of interface{} -> any
This commit is contained in:
@ -35,7 +35,7 @@ type Adapter interface {
|
||||
// Version returns adapter version
|
||||
Version() int
|
||||
// DB connection stats object.
|
||||
Stats() interface{}
|
||||
Stats() any
|
||||
|
||||
// User management
|
||||
|
||||
@ -48,7 +48,7 @@ type Adapter interface {
|
||||
// UserDelete deletes user record
|
||||
UserDelete(uid t.Uid, hard bool) error
|
||||
// UserUpdate updates user record
|
||||
UserUpdate(uid t.Uid, update map[string]interface{}) error
|
||||
UserUpdate(uid t.Uid, update map[string]any) error
|
||||
// UserUpdateTags adds, removes, or resets user's tags
|
||||
UserUpdateTags(uid t.Uid, add, remove, reset []string) ([]string, error)
|
||||
// UserGetByCred returns user ID for the given validated credential.
|
||||
@ -122,7 +122,7 @@ type Adapter interface {
|
||||
// TopicUpdateOnMessage increments Topic's or User's SeqId value and updates TouchedAt timestamp.
|
||||
TopicUpdateOnMessage(topic string, msg *t.Message) error
|
||||
// TopicUpdate updates topic record.
|
||||
TopicUpdate(topic string, update map[string]interface{}) error
|
||||
TopicUpdate(topic string, update map[string]any) error
|
||||
// TopicOwnerChange updates topic's owner
|
||||
TopicOwnerChange(topic string, newOwner t.Uid) error
|
||||
// Topic subscriptions
|
||||
@ -135,7 +135,7 @@ type Adapter interface {
|
||||
// SubsForTopic gets a list of subscriptions to a given topic.. Does NOT load Public value.
|
||||
SubsForTopic(topic string, keepDeleted bool, opts *t.QueryOpt) ([]t.Subscription, error)
|
||||
// SubsUpdate updates pasrt of a subscription object. Pass nil for fields which don't need to be updated
|
||||
SubsUpdate(topic string, user t.Uid, update map[string]interface{}) error
|
||||
SubsUpdate(topic string, user t.Uid, update map[string]any) error
|
||||
// SubsDelete deletes a single subscription
|
||||
SubsDelete(topic string, user t.Uid) error
|
||||
|
||||
|
@ -56,7 +56,7 @@ const (
|
||||
type configType struct {
|
||||
// Connection string URI https://www.mongodb.com/docs/manual/reference/connection-string/
|
||||
Uri string `json:"uri,omitempty"`
|
||||
Addresses interface{} `json:"addresses,omitempty"`
|
||||
Addresses any `json:"addresses,omitempty"`
|
||||
ConnectTimeout int `json:"timeout,omitempty"`
|
||||
|
||||
// Options separately from ClientOptions (custom options):
|
||||
@ -99,7 +99,7 @@ func (a *adapter) Open(jsonconfig json.RawMessage) error {
|
||||
opts.SetHosts([]string{defaultHost})
|
||||
} else if host, ok := config.Addresses.(string); ok {
|
||||
opts.SetHosts([]string{host})
|
||||
} else if ihosts, ok := config.Addresses.([]interface{}); ok && len(ihosts) > 0 {
|
||||
} else if ihosts, ok := config.Addresses.([]any); ok && len(ihosts) > 0 {
|
||||
hosts := make([]string, len(ihosts))
|
||||
for i, ih := range ihosts {
|
||||
h, ok := ih.(string)
|
||||
@ -256,7 +256,7 @@ func (a *adapter) Version() int {
|
||||
}
|
||||
|
||||
// DB connection stats object.
|
||||
func (a *adapter) Stats() interface{} {
|
||||
func (a *adapter) Stats() any {
|
||||
if a.db == nil {
|
||||
return nil
|
||||
}
|
||||
@ -420,7 +420,7 @@ func (a *adapter) CreateDb(reset bool) error {
|
||||
// Collection "kvmeta" with metadata key-value pairs.
|
||||
// Key in "_id" field.
|
||||
// Record current DB version.
|
||||
if _, err := a.db.Collection("kvmeta").InsertOne(a.ctx, map[string]interface{}{"_id": "version", "value": adpVersion}); err != nil {
|
||||
if _, err := a.db.Collection("kvmeta").InsertOne(a.ctx, map[string]any{"_id": "version", "value": adpVersion}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -557,7 +557,7 @@ func createSystemTopic(a *adapter) error {
|
||||
UpdatedAt: now},
|
||||
TouchedAt: now,
|
||||
Access: t.DefaultAccess{Auth: t.ModeNone, Anon: t.ModeNone},
|
||||
Public: map[string]interface{}{"fn": "System"},
|
||||
Public: map[string]any{"fn": "System"},
|
||||
})
|
||||
return err
|
||||
}
|
||||
@ -592,7 +592,7 @@ func (a *adapter) UserGet(id t.Uid) (*t.User, error) {
|
||||
|
||||
// UserGetAll returns user records for a given list of user IDs
|
||||
func (a *adapter) UserGetAll(ids ...t.Uid) ([]t.User, error) {
|
||||
uids := make([]interface{}, len(ids))
|
||||
uids := make([]any, len(ids))
|
||||
for i, id := range ids {
|
||||
uids[i] = id.String()
|
||||
}
|
||||
@ -787,7 +787,7 @@ func (a *adapter) UserDelete(uid t.Uid, hard bool) error {
|
||||
}
|
||||
|
||||
// topicStateForUser is called by UserUpdate when the update contains state change
|
||||
func (a *adapter) topicStateForUser(uid t.Uid, now time.Time, update interface{}) error {
|
||||
func (a *adapter) topicStateForUser(uid t.Uid, now time.Time, update any) error {
|
||||
state, ok := update.(t.ObjState)
|
||||
if !ok {
|
||||
return t.ErrMalformed
|
||||
@ -821,7 +821,7 @@ func (a *adapter) topicStateForUser(uid t.Uid, now time.Time, update interface{}
|
||||
}
|
||||
|
||||
// UserUpdate updates user record
|
||||
func (a *adapter) UserUpdate(uid t.Uid, update map[string]interface{}) error {
|
||||
func (a *adapter) UserUpdate(uid t.Uid, update map[string]any) error {
|
||||
// to get round the hardcoded "UpdatedAt" key in store.Users.Update()
|
||||
update = normalizeUpdateMap(update)
|
||||
|
||||
@ -842,7 +842,7 @@ func (a *adapter) UserUpdateTags(uid t.Uid, add, remove, reset []string) ([]stri
|
||||
// Compare to nil vs checking for zero length: zero length reset is valid.
|
||||
if reset != nil {
|
||||
// Replace Tags with the new value
|
||||
return reset, a.UserUpdate(uid, map[string]interface{}{"tags": reset})
|
||||
return reset, a.UserUpdate(uid, map[string]any{"tags": reset})
|
||||
}
|
||||
|
||||
var user t.User
|
||||
@ -860,7 +860,7 @@ func (a *adapter) UserUpdateTags(uid t.Uid, add, remove, reset []string) ([]stri
|
||||
newTags = diff(newTags, remove)
|
||||
}
|
||||
|
||||
update := map[string]interface{}{"tags": newTags}
|
||||
update := map[string]any{"tags": newTags}
|
||||
if err := a.UserUpdate(uid, update); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -1678,7 +1678,7 @@ func (a *adapter) UsersForTopic(topic string, keepDeleted bool, opts *t.QueryOpt
|
||||
// Fetch subscriptions
|
||||
var subs []t.Subscription
|
||||
join := make(map[string]t.Subscription)
|
||||
usrq := make([]interface{}, 0, 16)
|
||||
usrq := make([]any, 0, 16)
|
||||
for cur.Next(a.ctx) {
|
||||
var sub t.Subscription
|
||||
if err = cur.Decode(&sub); err != nil {
|
||||
@ -1875,11 +1875,11 @@ func (a *adapter) TopicDelete(topic string, isChan, hard bool) error {
|
||||
|
||||
// TopicUpdateOnMessage increments Topic's or User's SeqId value and updates TouchedAt timestamp.
|
||||
func (a *adapter) TopicUpdateOnMessage(topic string, msg *t.Message) error {
|
||||
return a.topicUpdate(topic, map[string]interface{}{"seqid": msg.SeqId, "touchedat": msg.CreatedAt})
|
||||
return a.topicUpdate(topic, map[string]any{"seqid": msg.SeqId, "touchedat": msg.CreatedAt})
|
||||
}
|
||||
|
||||
// TopicUpdate updates topic record.
|
||||
func (a *adapter) TopicUpdate(topic string, update map[string]interface{}) error {
|
||||
func (a *adapter) TopicUpdate(topic string, update map[string]any) error {
|
||||
if t, u := update["TouchedAt"], update["UpdatedAt"]; t == nil && u != nil {
|
||||
update["TouchedAt"] = u
|
||||
}
|
||||
@ -1888,10 +1888,10 @@ func (a *adapter) TopicUpdate(topic string, update map[string]interface{}) error
|
||||
|
||||
// TopicOwnerChange updates topic's owner
|
||||
func (a *adapter) TopicOwnerChange(topic string, newOwner t.Uid) error {
|
||||
return a.topicUpdate(topic, map[string]interface{}{"owner": newOwner.String()})
|
||||
return a.topicUpdate(topic, map[string]any{"owner": newOwner.String()})
|
||||
}
|
||||
|
||||
func (a *adapter) topicUpdate(topic string, update map[string]interface{}) error {
|
||||
func (a *adapter) topicUpdate(topic string, update map[string]any) error {
|
||||
_, err := a.db.Collection("topics").UpdateOne(a.ctx,
|
||||
b.M{"_id": topic},
|
||||
b.M{"$set": update})
|
||||
@ -1984,7 +1984,7 @@ func (a *adapter) SubsForTopic(topic string, keepDeleted bool, opts *t.QueryOpt)
|
||||
}
|
||||
|
||||
// SubsUpdate updates part of a subscription object. Pass nil for fields which don't need to be updated
|
||||
func (a *adapter) SubsUpdate(topic string, user t.Uid, update map[string]interface{}) error {
|
||||
func (a *adapter) SubsUpdate(topic string, user t.Uid, update map[string]any) error {
|
||||
// to get round the hardcoded pass of "Private" key
|
||||
update = normalizeUpdateMap(update)
|
||||
|
||||
@ -2057,7 +2057,7 @@ func (a *adapter) subsDelete(ctx context.Context, filter b.M, hard bool) error {
|
||||
func (a *adapter) getFindPipeline(req [][]string, opt []string, activeOnly bool) (map[string]struct{}, b.A) {
|
||||
allReq := t.FlattenDoubleSlice(req)
|
||||
index := make(map[string]struct{})
|
||||
var allTags []interface{}
|
||||
var allTags []any
|
||||
for _, tag := range append(allReq, opt...) {
|
||||
allTags = append(allTags, tag)
|
||||
index[tag] = struct{}{}
|
||||
@ -2091,7 +2091,7 @@ func (a *adapter) getFindPipeline(req [][]string, opt []string, activeOnly bool)
|
||||
}
|
||||
|
||||
for _, l := range req {
|
||||
var reqTags []interface{}
|
||||
var reqTags []any
|
||||
for _, tag := range l {
|
||||
reqTags = append(reqTags, tag)
|
||||
}
|
||||
@ -2387,7 +2387,7 @@ func (a *adapter) DeviceUpsert(uid t.Uid, dev *t.DeviceDef) error {
|
||||
if err == nil && user.Id != "" { // current user owns this device
|
||||
// ArrayFilter used to avoid adding another (duplicate) device object. Update that device data
|
||||
updOpts := mdbopts.Update().SetArrayFilters(mdbopts.ArrayFilters{
|
||||
Filters: []interface{}{b.M{"dev.deviceid": dev.DeviceId}}})
|
||||
Filters: []any{b.M{"dev.deviceid": dev.DeviceId}}})
|
||||
_, err = a.db.Collection("users").UpdateOne(a.ctx,
|
||||
b.M{"_id": userId},
|
||||
b.M{"$set": b.M{
|
||||
@ -2428,7 +2428,7 @@ func (a *adapter) deviceInsert(userId string, dev *t.DeviceDef) error {
|
||||
if err != nil && strings.Contains(err.Error(), "must be an array") {
|
||||
// field 'devices' is not array. Make it array with 'dev' as its first element
|
||||
_, err = a.db.Collection("users").UpdateOne(a.ctx, filter,
|
||||
b.M{"$set": b.M{"devices": []interface{}{dev}}})
|
||||
b.M{"$set": b.M{"devices": []any{dev}}})
|
||||
}
|
||||
|
||||
return err
|
||||
@ -2436,7 +2436,7 @@ func (a *adapter) deviceInsert(userId string, dev *t.DeviceDef) error {
|
||||
|
||||
// DeviceGetAll returns all devices for a given set of users
|
||||
func (a *adapter) DeviceGetAll(uids ...t.Uid) (map[t.Uid][]t.DeviceDef, int, error) {
|
||||
ids := make([]interface{}, len(uids))
|
||||
ids := make([]any, len(uids))
|
||||
for i, id := range uids {
|
||||
ids[i] = id.String()
|
||||
}
|
||||
@ -2478,7 +2478,7 @@ func (a *adapter) DeviceDelete(uid t.Uid, deviceID string) error {
|
||||
filter := b.M{"_id": uid.String()}
|
||||
update := b.M{}
|
||||
if deviceID == "" {
|
||||
update["$set"] = b.M{"devices": []interface{}{}}
|
||||
update["$set"] = b.M{"devices": []any{}}
|
||||
} else {
|
||||
update["$pull"] = b.M{"devices": b.M{"deviceid": deviceID}}
|
||||
}
|
||||
@ -2656,7 +2656,7 @@ func (a *adapter) FileLinkAttachments(topic string, userId, msgId t.Uid, fids []
|
||||
}
|
||||
}
|
||||
|
||||
ids := make([]interface{}, len(fids))
|
||||
ids := make([]any, len(fids))
|
||||
for i, id := range fids {
|
||||
ids[i] = id
|
||||
}
|
||||
@ -2776,8 +2776,8 @@ func diff(userTags, removeTags []string) []string {
|
||||
}
|
||||
|
||||
// normalizeUpdateMap turns keys that hardcoded as CamelCase into lowercase (MongoDB uses lowercase by default)
|
||||
func normalizeUpdateMap(update map[string]interface{}) map[string]interface{} {
|
||||
result := make(map[string]interface{}, len(update))
|
||||
func normalizeUpdateMap(update map[string]any) map[string]any {
|
||||
result := make(map[string]any, len(update))
|
||||
for key, value := range update {
|
||||
result[strings.ToLower(key)] = value
|
||||
}
|
||||
@ -2786,11 +2786,11 @@ func normalizeUpdateMap(update map[string]interface{}) map[string]interface{} {
|
||||
}
|
||||
|
||||
// Recursive unmarshalling of bson.D type.
|
||||
// Mongo drivers unmarshalling into interface{} creates bson.D object for maps and bson.A object for slices.
|
||||
// We need manually unmarshal them into correct types: map[string]interface{} and []interface{] respectively.
|
||||
func unmarshalBsonD(bsonObj interface{}) interface{} {
|
||||
// Mongo drivers unmarshalling into any creates bson.D object for maps and bson.A object for slices.
|
||||
// We need manually unmarshal them into correct types: map[string]any and []interface{] respectively.
|
||||
func unmarshalBsonD(bsonObj any) any {
|
||||
if obj, ok := bsonObj.(b.D); ok && len(obj) != 0 {
|
||||
result := make(map[string]interface{})
|
||||
result := make(map[string]any)
|
||||
for key, val := range obj.Map() {
|
||||
result[key] = unmarshalBsonD(val)
|
||||
}
|
||||
@ -2800,7 +2800,7 @@ func unmarshalBsonD(bsonObj interface{}) interface{} {
|
||||
return obj.Data
|
||||
} else if obj, ok := bsonObj.(b.A); ok {
|
||||
// in case of array of bson.D objects
|
||||
var result []interface{}
|
||||
var result []any
|
||||
for _, elem := range obj {
|
||||
result = append(result, unmarshalBsonD(elem))
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ func TestFileGet(t *testing.T) {
|
||||
|
||||
// ================== Update tests ================================
|
||||
func TestUserUpdate(t *testing.T) {
|
||||
update := map[string]interface{}{
|
||||
update := map[string]any{
|
||||
"UserAgent": "Test Agent v0.11",
|
||||
"UpdatedAt": now.Add(30 * time.Minute),
|
||||
}
|
||||
@ -745,7 +745,7 @@ func TestTopicUpdateOnMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTopicUpdate(t *testing.T) {
|
||||
update := map[string]interface{}{
|
||||
update := map[string]any{
|
||||
"UpdatedAt": now.Add(55 * time.Minute),
|
||||
}
|
||||
err := adp.TopicUpdate(topics[0].Id, update)
|
||||
@ -772,7 +772,7 @@ func TestTopicOwnerChange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubsUpdate(t *testing.T) {
|
||||
update := map[string]interface{}{
|
||||
update := map[string]any{
|
||||
"UpdatedAt": now.Add(22 * time.Minute),
|
||||
}
|
||||
err := adp.SubsUpdate(topics[0].Id, types.ParseUserId("usr"+users[0].Id), update)
|
||||
@ -944,7 +944,7 @@ func TestCredDel(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got []map[string]interface{}
|
||||
var got []map[string]any
|
||||
cur, err := db.Collection("credentials").Find(ctx, b.M{"method": "email", "value": "alice@test.example.com"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -1164,14 +1164,14 @@ func TestMessageGetDeleted(t *testing.T) {
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
func mismatchErrorString(key string, got, want interface{}) string {
|
||||
func mismatchErrorString(key string, got, want any) string {
|
||||
return fmt.Sprintf("%v mismatch:\nGot = %v\nWant = %v", key, got, want)
|
||||
}
|
||||
|
||||
func initConnectionToDb() {
|
||||
var adpConfig struct {
|
||||
Addresses interface{} `json:"addresses,omitempty"`
|
||||
Database string `json:"database,omitempty"`
|
||||
Addresses any `json:"addresses,omitempty"`
|
||||
Database string `json:"database,omitempty"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(config.Adapters[adp.GetName()], &adpConfig); err != nil {
|
||||
|
@ -254,7 +254,7 @@ func (adapter) Version() int {
|
||||
}
|
||||
|
||||
// DB connection stats object.
|
||||
func (a *adapter) Stats() interface{} {
|
||||
func (a *adapter) Stats() any {
|
||||
if a.db == nil {
|
||||
return nil
|
||||
}
|
||||
@ -791,7 +791,7 @@ func createSystemTopic(tx *sql.Tx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func addTags(tx *sqlx.Tx, table, keyName string, keyVal interface{}, tags []string, ignoreDups bool) error {
|
||||
func addTags(tx *sqlx.Tx, table, keyName string, keyVal any, tags []string, ignoreDups bool) error {
|
||||
|
||||
if len(tags) == 0 {
|
||||
return nil
|
||||
@ -821,12 +821,12 @@ func addTags(tx *sqlx.Tx, table, keyName string, keyVal interface{}, tags []stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeTags(tx *sqlx.Tx, table, keyName string, keyVal interface{}, tags []string) error {
|
||||
func removeTags(tx *sqlx.Tx, table, keyName string, keyVal any, tags []string) error {
|
||||
if len(tags) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
var args []any
|
||||
for _, tag := range tags {
|
||||
args = append(args, tag)
|
||||
}
|
||||
@ -926,7 +926,7 @@ func (a *adapter) AuthUpdRecord(uid t.Uid, scheme, unique string, authLvl auth.L
|
||||
secret []byte, expires time.Time) error {
|
||||
|
||||
params := []string{"authLvl=?"}
|
||||
args := []interface{}{authLvl}
|
||||
args := []any{authLvl}
|
||||
|
||||
if unique != "" {
|
||||
params = append(params, "uname=?")
|
||||
@ -1044,7 +1044,7 @@ func (a *adapter) UserGet(uid t.Uid) (*t.User, error) {
|
||||
}
|
||||
|
||||
func (a *adapter) UserGetAll(ids ...t.Uid) ([]t.User, error) {
|
||||
uids := make([]interface{}, len(ids))
|
||||
uids := make([]any, len(ids))
|
||||
for i, id := range ids {
|
||||
uids[i] = store.DecodeUid(id)
|
||||
}
|
||||
@ -1218,7 +1218,7 @@ func (a *adapter) UserDelete(uid t.Uid, hard bool) error {
|
||||
}
|
||||
|
||||
// topicStateForUser is called by UserUpdate when the update contains state change.
|
||||
func (a *adapter) topicStateForUser(tx *sqlx.Tx, decoded_uid int64, now time.Time, update interface{}) error {
|
||||
func (a *adapter) topicStateForUser(tx *sqlx.Tx, decoded_uid int64, now time.Time, update any) error {
|
||||
var err error
|
||||
|
||||
state, ok := update.(t.ObjState)
|
||||
@ -1250,7 +1250,7 @@ func (a *adapter) topicStateForUser(tx *sqlx.Tx, decoded_uid int64, now time.Tim
|
||||
}
|
||||
|
||||
// UserUpdate updates user object.
|
||||
func (a *adapter) UserUpdate(uid t.Uid, update map[string]interface{}) error {
|
||||
func (a *adapter) UserUpdate(uid t.Uid, update map[string]any) error {
|
||||
ctx, cancel := a.getContextForTx()
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
@ -1377,7 +1377,7 @@ func (a *adapter) UserGetByCred(method, value string) (t.Uid, error) {
|
||||
// the R permission. If read fails, the counts are still returned with the original
|
||||
// user IDs but with the unread count undefined and non-nil error.
|
||||
func (a *adapter) UserUnreadCount(ids ...t.Uid) (map[t.Uid]int, error) {
|
||||
uids := make([]interface{}, len(ids))
|
||||
uids := make([]any, len(ids))
|
||||
counts := make(map[t.Uid]int, len(ids))
|
||||
for i, id := range ids {
|
||||
uids[i] = store.DecodeUid(id)
|
||||
@ -1590,7 +1590,7 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) (
|
||||
// We are going to use these subscriptions to fetch topics and users which may have been modified recently.
|
||||
q := `SELECT createdat,updatedat,deletedat,topic,delid,recvseqid,
|
||||
readseqid,modewant,modegiven,private FROM subscriptions WHERE userid=?`
|
||||
args := []interface{}{store.DecodeUid(uid)}
|
||||
args := []any{store.DecodeUid(uid)}
|
||||
if !keepDeleted {
|
||||
// Filter out deleted rows.
|
||||
q += " AND deletedat IS NULL"
|
||||
@ -1636,8 +1636,8 @@ func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) (
|
||||
// Fetch subscriptions. Two queries are needed: users table (p2p) and topics table (grp).
|
||||
// Prepare a list of separate subscriptions to users vs topics
|
||||
join := make(map[string]t.Subscription) // Keeping these to make a join with table for .private and .access
|
||||
topq := make([]interface{}, 0, 16)
|
||||
usrq := make([]interface{}, 0, 16)
|
||||
topq := make([]any, 0, 16)
|
||||
usrq := make([]any, 0, 16)
|
||||
for rows.Next() {
|
||||
var sub t.Subscription
|
||||
if err = rows.StructScan(&sub); err != nil {
|
||||
@ -1820,7 +1820,7 @@ func (a *adapter) UsersForTopic(topic string, keepDeleted bool, opts *t.QueryOpt
|
||||
s.readseqid,s.modewant,s.modegiven,u.public,u.trusted,u.lastseen,u.useragent,s.private
|
||||
FROM subscriptions AS s JOIN users AS u ON s.userid=u.id
|
||||
WHERE s.topic=?`
|
||||
args := []interface{}{topic}
|
||||
args := []any{topic}
|
||||
if !keepDeleted {
|
||||
// Filter out rows with users deleted
|
||||
q += " AND u.state!=?"
|
||||
@ -1869,7 +1869,7 @@ func (a *adapter) UsersForTopic(topic string, keepDeleted bool, opts *t.QueryOpt
|
||||
var subs []t.Subscription
|
||||
var lastSeen sql.NullTime
|
||||
var userAgent string
|
||||
var public, trusted interface{}
|
||||
var public, trusted any
|
||||
for rows.Next() {
|
||||
if err = rows.Scan(
|
||||
&sub.CreatedAt, &sub.UpdatedAt, &sub.DeletedAt,
|
||||
@ -2011,7 +2011,7 @@ func (a *adapter) TopicDelete(topic string, isChan, hard bool) error {
|
||||
}()
|
||||
|
||||
// If the topic is a channel, must try to delete subscriptions under both grpXXX and chnXXX names.
|
||||
args := []interface{}{topic}
|
||||
args := []any{topic}
|
||||
if isChan {
|
||||
args = append(args, t.GrpToChn(topic))
|
||||
}
|
||||
@ -2062,7 +2062,7 @@ func (a *adapter) TopicUpdateOnMessage(topic string, msg *t.Message) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *adapter) TopicUpdate(topic string, update map[string]interface{}) error {
|
||||
func (a *adapter) TopicUpdate(topic string, update map[string]any) error {
|
||||
ctx, cancel := a.getContextForTx()
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
@ -2147,7 +2147,7 @@ func (a *adapter) SubscriptionGet(topic string, user t.Uid, keepDeleted bool) (*
|
||||
func (a *adapter) SubsForUser(forUser t.Uid) ([]t.Subscription, error) {
|
||||
q := `SELECT createdat,updatedat,deletedat,userid AS user,topic,delid,recvseqid,
|
||||
readseqid,modewant,modegiven FROM subscriptions WHERE userid=? AND deletedat IS NULL`
|
||||
args := []interface{}{store.DecodeUid(forUser)}
|
||||
args := []any{store.DecodeUid(forUser)}
|
||||
|
||||
ctx, cancel := a.getContext()
|
||||
if cancel != nil {
|
||||
@ -2182,7 +2182,7 @@ func (a *adapter) SubsForTopic(topic string, keepDeleted bool, opts *t.QueryOpt)
|
||||
q := `SELECT createdat,updatedat,deletedat,userid AS user,topic,delid,recvseqid,
|
||||
readseqid,modewant,modegiven,private FROM subscriptions WHERE topic=?`
|
||||
|
||||
args := []interface{}{topic}
|
||||
args := []any{topic}
|
||||
if !keepDeleted {
|
||||
// Filter out deleted rows.
|
||||
q += " AND deletedat IS NULL"
|
||||
@ -2233,7 +2233,7 @@ func (a *adapter) SubsForTopic(topic string, keepDeleted bool, opts *t.QueryOpt)
|
||||
}
|
||||
|
||||
// SubsUpdate updates one or multiple subscriptions to a topic.
|
||||
func (a *adapter) SubsUpdate(topic string, user t.Uid, update map[string]interface{}) error {
|
||||
func (a *adapter) SubsUpdate(topic string, user t.Uid, update map[string]any) error {
|
||||
ctx, cancel := a.getContextForTx()
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
@ -2351,7 +2351,7 @@ func (a *adapter) SubsDelForUser(user t.Uid, hard bool) error {
|
||||
// Searching the 'users.Tags' for the given tags using respective index.
|
||||
func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string, activeOnly bool) ([]t.Subscription, error) {
|
||||
index := make(map[string]struct{})
|
||||
var args []interface{}
|
||||
var args []any
|
||||
stateConstraint := ""
|
||||
if activeOnly {
|
||||
args = append(args, t.StateOK)
|
||||
@ -2399,7 +2399,7 @@ func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string, activeOnly
|
||||
}
|
||||
|
||||
var userId int64
|
||||
var public, trusted interface{}
|
||||
var public, trusted any
|
||||
var access t.DefaultAccess
|
||||
var userTags t.StringSlice
|
||||
var ignored int
|
||||
@ -2443,7 +2443,7 @@ func (a *adapter) FindUsers(uid t.Uid, req [][]string, opt []string, activeOnly
|
||||
// Searching the 'topics.Tags' for the given tags using respective index.
|
||||
func (a *adapter) FindTopics(req [][]string, opt []string, activeOnly bool) ([]t.Subscription, error) {
|
||||
index := make(map[string]struct{})
|
||||
var args []interface{}
|
||||
var args []any
|
||||
stateConstraint := ""
|
||||
if activeOnly {
|
||||
args = append(args, t.StateOK)
|
||||
@ -2492,7 +2492,7 @@ func (a *adapter) FindTopics(req [][]string, opt []string, activeOnly bool) ([]t
|
||||
}
|
||||
|
||||
var access t.DefaultAccess
|
||||
var public, trusted interface{}
|
||||
var public, trusted any
|
||||
var topicTags t.StringSlice
|
||||
var ignored int
|
||||
var isChan int
|
||||
@ -2722,7 +2722,7 @@ func messageDeleteList(tx *sqlx.Tx, topic string, toDel *t.DelMessage) error {
|
||||
if err == nil && toDel.DeletedFor == "" {
|
||||
// Hard-deleting messages requires updates to the messages table
|
||||
where := "m.topic=? AND "
|
||||
args := []interface{}{topic}
|
||||
args := []any{topic}
|
||||
if len(toDel.SeqIdRanges) > 1 || toDel.SeqIdRanges[0].Hi == 0 {
|
||||
for _, r := range toDel.SeqIdRanges {
|
||||
if r.Hi == 0 {
|
||||
@ -2751,7 +2751,7 @@ func messageDeleteList(tx *sqlx.Tx, topic string, toDel *t.DelMessage) error {
|
||||
|
||||
_, err = tx.Exec("UPDATE messages AS m SET m.deletedAt=?,m.delId=?,m.head=NULL,m.content=NULL WHERE "+
|
||||
where,
|
||||
append([]interface{}{t.TimeNow(), toDel.DelId}, args...)...)
|
||||
append([]any{t.TimeNow(), toDel.DelId}, args...)...)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2825,7 +2825,7 @@ func (a *adapter) DeviceUpsert(uid t.Uid, def *t.DeviceDef) error {
|
||||
}
|
||||
|
||||
func (a *adapter) DeviceGetAll(uids ...t.Uid) (map[t.Uid][]t.DeviceDef, int, error) {
|
||||
var unums []interface{}
|
||||
var unums []any
|
||||
for _, uid := range uids {
|
||||
unums = append(unums, store.DecodeUid(uid))
|
||||
}
|
||||
@ -3008,7 +3008,7 @@ func (a *adapter) CredUpsert(cred *t.Credential) (bool, error) {
|
||||
// 2.2 In that case mark it as soft-deleted.
|
||||
func credDel(tx *sqlx.Tx, uid t.Uid, method, value string) error {
|
||||
constraints := " WHERE userid=?"
|
||||
args := []interface{}{store.DecodeUid(uid)}
|
||||
args := []any{store.DecodeUid(uid)}
|
||||
|
||||
if method != "" {
|
||||
constraints += " AND method=?"
|
||||
@ -3043,7 +3043,7 @@ func credDel(tx *sqlx.Tx, uid t.Uid, method, value string) error {
|
||||
}
|
||||
|
||||
// Case 2.2
|
||||
args = append([]interface{}{t.TimeNow()}, args...)
|
||||
args = append([]any{t.TimeNow()}, args...)
|
||||
res, err = tx.Exec("UPDATE credentials SET deletedat=?"+constraints, args...)
|
||||
if err == nil {
|
||||
if count, _ := res.RowsAffected(); count >= 0 {
|
||||
@ -3138,7 +3138,7 @@ func (a *adapter) CredGetActive(uid t.Uid, method string) (*t.Credential, error)
|
||||
// CredGetAll returns credential records for the given user and method, all or validated only.
|
||||
func (a *adapter) CredGetAll(uid t.Uid, method string, validatedOnly bool) ([]t.Credential, error) {
|
||||
query := "SELECT createdat,updatedat,method,value,resp,done,retries FROM credentials WHERE userid=? AND deletedat IS NULL"
|
||||
args := []interface{}{store.DecodeUid(uid)}
|
||||
args := []any{store.DecodeUid(uid)}
|
||||
if method != "" {
|
||||
query += " AND method=?"
|
||||
args = append(args, method)
|
||||
@ -3173,7 +3173,7 @@ func (a *adapter) FileStartUpload(fd *t.FileDef) error {
|
||||
if cancel != nil {
|
||||
defer cancel()
|
||||
}
|
||||
var user interface{}
|
||||
var user any
|
||||
if fd.User != "" {
|
||||
user = store.DecodeUid(t.ParseUid(fd.User))
|
||||
} else {
|
||||
@ -3275,7 +3275,7 @@ func (a *adapter) FileDeleteUnused(olderThan time.Time, limit int) ([]string, er
|
||||
// Garbage collecting entries which as either marked as deleted, or lack message references, or have no user assigned.
|
||||
query := "SELECT fu.id,fu.location FROM fileuploads AS fu LEFT JOIN filemsglinks AS fml ON fml.fileid=fu.id " +
|
||||
"WHERE fml.id IS NULL"
|
||||
var args []interface{}
|
||||
var args []any
|
||||
if !olderThan.IsZero() {
|
||||
query += " AND fu.updatedat<?"
|
||||
args = append(args, olderThan)
|
||||
@ -3291,7 +3291,7 @@ func (a *adapter) FileDeleteUnused(olderThan time.Time, limit int) ([]string, er
|
||||
}
|
||||
|
||||
var locations []string
|
||||
var ids []interface{}
|
||||
var ids []any
|
||||
for rows.Next() {
|
||||
var id int
|
||||
var loc string
|
||||
@ -3330,8 +3330,8 @@ func (a *adapter) FileLinkAttachments(topic string, userId, msgId t.Uid, fids []
|
||||
}
|
||||
now := t.TimeNow()
|
||||
|
||||
var args []interface{}
|
||||
var linkId interface{}
|
||||
var args []any
|
||||
var linkId any
|
||||
var linkBy string
|
||||
if !msgId.IsZero() {
|
||||
linkBy = "msgid"
|
||||
@ -3349,7 +3349,7 @@ func (a *adapter) FileLinkAttachments(topic string, userId, msgId t.Uid, fids []
|
||||
}
|
||||
|
||||
// Decoded ids
|
||||
var dids []interface{}
|
||||
var dids []any
|
||||
for _, fid := range fids {
|
||||
id := t.ParseUid(fid)
|
||||
if id.IsZero() {
|
||||
@ -3495,7 +3495,7 @@ func isMissingDb(err error) bool {
|
||||
}
|
||||
|
||||
// Convert to JSON before storing to JSON field.
|
||||
func toJSON(src interface{}) []byte {
|
||||
func toJSON(src any) []byte {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
@ -3505,12 +3505,12 @@ func toJSON(src interface{}) []byte {
|
||||
}
|
||||
|
||||
// Deserialize JSON data from DB.
|
||||
func fromJSON(src interface{}) interface{} {
|
||||
func fromJSON(src any) any {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
if bb, ok := src.([]byte); ok {
|
||||
var out interface{}
|
||||
var out any
|
||||
json.Unmarshal(bb, &out)
|
||||
return out
|
||||
}
|
||||
@ -3529,7 +3529,7 @@ func decodeUidString(str string) int64 {
|
||||
}
|
||||
|
||||
// Convert update to a list of columns and arguments.
|
||||
func updateByMap(update map[string]interface{}) (cols []string, args []interface{}) {
|
||||
func updateByMap(update map[string]any) (cols []string, args []any) {
|
||||
for col, arg := range update {
|
||||
col = strings.ToLower(col)
|
||||
if col == "public" || col == "trusted" || col == "private" {
|
||||
@ -3542,7 +3542,7 @@ func updateByMap(update map[string]interface{}) (cols []string, args []interface
|
||||
}
|
||||
|
||||
// If Tags field is updated, get the tags so tags table cab be updated too.
|
||||
func extractTags(update map[string]interface{}) []string {
|
||||
func extractTags(update map[string]any) []string {
|
||||
var tags []string
|
||||
|
||||
if val := update["Tags"]; val != nil {
|
||||
|
Reference in New Issue
Block a user