Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/outnote/_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def chat(self, chat_id):
return self.get(f"chats/{chat_id}", {"$expand": "members,lastMessagePreview"})

def chat_members(self, chat_id):
return self.list(f"chats/{chat_id}/members")
"""The people in a chat, each with `userId` and `displayName`. Reads them through the chat,
because Graph can throttle `chats/{id}/members` heavily (see issue #46)."""
chat = self.get(f"chats/{chat_id}", {"$expand": "members", "$select": "id"})
return chat.get("members") or []

def unread_chats(self, top=50):
"""Chats whose last message is newer than when I last read the chat
Expand Down
20 changes: 20 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,23 @@ def test_search_is_unchanged(monkeypatch):
c = search_client(monkeypatch, ([("1", "x")], True))
assert [r["id"] for r in c.search("w", "chatMessage", 3)] == ["1"]
assert c.bodies[0]["size"] == 3


# --- chat_members --------------------------------------------------------------
def test_chat_members_reads_them_through_the_chat(monkeypatch):
c = outnote.OutNote("tok")
seen = []

def get(path, params=None, **k):
seen.append((path, params))
return {"id": "c", "members": [{"userId": "u1"}, {"userId": "u2"}]}

monkeypatch.setattr(c, "get", get)
assert [m["userId"] for m in c.chat_members("c")] == ["u1", "u2"]
assert seen == [("chats/c", {"$expand": "members", "$select": "id"})]


def test_chat_members_of_a_chat_without_the_field_is_empty(monkeypatch):
c = outnote.OutNote("tok")
monkeypatch.setattr(c, "get", lambda *a, **k: {"id": "c"})
assert c.chat_members("c") == []
Loading