- def addUserToRoomm(self, room, user):
- query = {"rid": room['_id'], "u._id": user['_id']}
- subscription = self.db.rocketchat_subscription.find_one(query)
- if subscription:
- roles = []
- if "roles" in subscription:
- if "owner" in subscription['roles']:
- raise ValueError("Already owner")
- roles = subscription['roles']
- roles.append("owner")
- self.db.rocketchat_subscription.update_one(query, {"$set": { "roles": roles }})
- else:
- subscription = {
- "open": True,
- "alert": True,
- "unread": 0,
- "userMentions": 0,
- "groupMentions": 0,
- "ts": room['ts'],
- "rid": room['_id'],
- "name": room['name'],
- "fname": room['fname'],
- "customFields": room['customFields'],
- "t": room['t'],
- "u": {
- "_id": user['_id'],
- "username": user['username'],
- "name": user['name'],
- },
- "roles": ["owner"]
- }
- self.db.rocketchat_subscription.insert_one(subscription)
- self.db.rocketchat_room.update({"_id": room['_id']}, {"$inc": {"usersCount": 1}})