Skip to content

Commit

Permalink
Merge pull request #1310 from mykie88/get_rooms
Browse files Browse the repository at this point in the history
Added back deleted changes to get rooms function
  • Loading branch information
zxenonx authored Nov 9, 2021
2 parents 2fc0bf5 + 2a01af2 commit 73323ec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
43 changes: 31 additions & 12 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,38 @@ class object referrencing DataStorage
return helper


def get_rooms(user_id: str, org_id: str):
"""get rooms for a particular user
def get_user_rooms(user_id: str, org_id: str):
"""
A utility function that retrieves all the rooms linked to a user from the dm_rooms collection
Args:
user_id: user's unique identifier
org_id: organization's unique identifier
Returns:
return: returns list of rooms if Available else returns empty list if false
collection: dm_rooms
user_id (str): a unique identifier used as a query param to filter the collection
org_id (str): uniquely identifies the organisation the user belongs too in the collection
Returns:
A List of dicts containing the information of each room associated with the particular user.
example:
[{'_id': '616c0adb240d4baaf0fefd68',
'bookmark': [],
'closed': False,
'created_at': '2021-10-17T11:36:59.385987Z',
'org_id': '61695d8bb233d46cc8a9af48',
'pinned': [],
'private': True,
'room_name': 'any name',
'room_user_ids': ['616a8fe2f99355096b2de6a4', '61696f4f09dcfac4133ddaa3'],
'starred': []
}]
Raises:
None: no error handling, function returns an empty list if invalid params are parsed
"""
response = get_org(org_id).read_query(
"dm_rooms",
query={"room_user_ids": user_id},
options={"sort": {"created_at": -1}},
org = get_org(org_id) # initializes the DataStorage class with a unique organization identifier
query = {"room_user_ids": user_id} # matches the room_user_ids field in the room document
options = {"sort": {"created_at": -1}} # query modifier, sorts from the most recent

user_rooms = org.read_query(
"dm_rooms", query=query, options=options
)

if user_rooms and "status_code" not in user_rooms:
Expand Down Expand Up @@ -318,7 +337,7 @@ def sidebar_emitter(org_id:str, member_id:str, group_room_name:str = None) -> di
"""
rooms = []
starred_rooms = []
user_rooms = get_rooms(user_id=member_id, org_id=org_id)
user_rooms = get_user_rooms(user_id=member_id, org_id=org_id)
members = get_all_organization_members(org_id)

if user_rooms != None:
Expand Down Expand Up @@ -409,7 +428,7 @@ def extract_user_room_data(room: dict, member_id: str, members: list) -> dict:
# gets starred rooms
def get_starred_rooms(member_id, org_id):
"""goes through database and returns starred rooms"""
response = get_rooms(member_id, org_id)
response = get_user_rooms(member_id, org_id)
if response:
data = []
for room in response:
Expand Down
6 changes: 3 additions & 3 deletions backend/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create_room(request, member_id):
else:
# print(" --------FAE------- \n\r")
user_ids = serializer.data["room_member_ids"]
user_rooms = get_rooms(user_ids[0], DB.organization_id)
user_rooms = get_user_rooms(user_ids[0], DB.organization_id)
if isinstance(user_rooms, list):
for room in user_rooms:
room_users = room["room_user_ids"]
Expand Down Expand Up @@ -129,7 +129,7 @@ def user_rooms(request, user_id):
if there is no room for the user_id it returns a 204 status response.
"""
if request.method == "GET":
res = get_rooms(user_id, DB.organization_id)
res = get_user_rooms(user_id, DB.organization_id)
if res is None:
return Response(
data="No rooms available", status=status.HTTP_204_NO_CONTENT
Expand Down Expand Up @@ -377,7 +377,7 @@ def group_member_add(request, room_id, member_id):
# =====================================================
# =====================================================

user_rooms = get_rooms(room_creator, DB.organization_id)
user_rooms = get_user_rooms(room_creator, DB.organization_id)
if user_rooms and isinstance(user_rooms, list):
for room in user_rooms:
room_users = room["room_user_ids"]
Expand Down
2 changes: 1 addition & 1 deletion backend/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def get_all_threads(request, member_id: str):
threads_list = LifoQueue()
# org_id = request.GET.get("")

rooms = get_rooms(user_id=member_id, org_id=DB.organization_id)
rooms = get_user_rooms(user_id=member_id, org_id=DB.organization_id)
if rooms:
# print(f"the room ", rooms)
for room in rooms:
Expand Down

0 comments on commit 73323ec

Please sign in to comment.