Skip to content

Commit

Permalink
Merge branch 'dkasak-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Mar 6, 2019
2 parents 0019efd + 34d45b0 commit 53df974
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions nio/rooms.py
Expand Up @@ -46,7 +46,10 @@


class MatrixRoom(object):
"""Represents a Matrix room."""

def __init__(self, room_id, own_user_id, encrypted=False):
"""Initialize a MatrixRoom object."""
# type: (str, str, bool) -> None
# yapf: disable
self.room_id = room_id # type: str
Expand All @@ -63,8 +66,7 @@ def __init__(self, room_id, own_user_id, encrypted=False):

@property
def display_name(self):
"""
Calculate display name for a room.
"""Calculate display name for a room.
Prefer returning the room name if it exists, falling back to
a group-style name if not.
Expand All @@ -82,9 +84,9 @@ def display_name(self):
return self.group_name()

def named_room_name(self):
"""
Return the name of the room, if it's a named room. Otherwise return
None.
"""Return the name of the room, if it's a named room.
Otherwise, return None.
"""
if self.name and self.name != '#':
return self.name if self.name.startswith('#') else '#' + self.name
Expand All @@ -96,9 +98,10 @@ def named_room_name(self):
return None

def group_name(self):
"""
Return the group-style name of the room, i.e. a name based on the room
members.
"""Return the group-style name of the room.
In other words, a display name based on the names of room members. This
is used for ad-hoc groups of people (usually direct chats).
"""
# Sort user display names, excluding our own user and using the
# mxid as the sorting key.
Expand All @@ -122,8 +125,7 @@ def group_name(self):
return "Empty room?"

def user_name(self, user_id):
"""
Get disambiguated display name for a user.
"""Get disambiguated display name for a user.
Returns display name of a user if display name is unique or returns
a display name in form "<display name> (<matrix id>)" if there is
Expand All @@ -138,16 +140,12 @@ def user_name(self, user_id):
return user.name

def user_name_clashes(self, name):
"""
Get a list of users that have same display name.
"""

"""Get a list of users that have same display name."""
return self.names[name]

@property
def machine_name(self):
"""
Calculate an unambiguous, unique machine name for a room.
"""Calculate an unambiguous, unique machine name for a room.
Either use the more human-friendly canonical alias, if it exists, or
the internal room ID if not.
Expand All @@ -159,17 +157,15 @@ def machine_name(self):

@property
def is_named(self):
"""
Is this a named room?
"""Determine whether a room is name.
A named room is a room with either the name or a canonical alias set.
"""
return self.canonical_alias or self.name

@property
def is_group(self):
"""
Is this an ad hoc group of users?
"""Determine whether a room is an ad-hoc group (often a direct chat).
A group is an unnamed room with no canonical alias.
"""
Expand Down

0 comments on commit 53df974

Please sign in to comment.