func GetSentOrganizations(coll string, email string) (string, []string) { session := db.Conn.Session.Copy() defer session.Close() orgs := []string{} userId := "" iter := db.Conn.GetCursor(session, coll, utils.M{"details.context.email": email}).Sort("-_id").Iter() var one struct { Details struct { Organization string `bson:"org"` User string `bson:"user"` } `bson:"details"` } for iter.Next(&one) { if userId == "" { userId = one.Details.User } if one.Details.User != userId { continue } if !db.InArray(one.Details.Organization, orgs) { orgs = append(orgs, one.Details.Organization) } } return userId, orgs }
func DisableUserChannel(orgs, topics []string, user, channelName string) { session := db.Conn.Session.Copy() defer session.Close() utils.RemoveDuplicates(&orgs) utils.RemoveDuplicates(&topics) db.Conn.Update( db.TopicCollection, utils.M{"user": user}, utils.M{"$addToSet": utils.M{"channels": channelName}}, ) disabled := []interface{}{} for _, org := range orgs { disabledTopics := []string{} db.Conn.GetCursor(session, db.TopicCollection, utils.M{"user": user, "org": org}).Distinct("ident", &disabledTopics) for _, name := range topics { if !db.InArray(name, disabledTopics) { topic := db.Topic{ User: user, Organization: org, Ident: name, Channels: []db.Channel{ db.Channel{Name: channelName, Enabled: false}, }, } topic.PrepareSave() disabled = append(disabled, topic) } } } if len(disabled) > 0 { db.Conn.InsertMulti(db.TopicCollection, disabled...) } }