Skip to content
Open
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
50 changes: 29 additions & 21 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def __init__(self, controller: Any) -> None:
self.users: List[MinimalUserData] = []
self._update_users_data_from_initial_data()

self.new_user_input = True
self._start_presence_updates()
while len(self.users) == 0:
time.sleep(0.01)

self.stream_dict: Dict[int, Any] = {}
self.muted_streams: Set[int] = set()
self.pinned_streams: List[StreamData] = []
Expand Down Expand Up @@ -239,9 +244,6 @@ def __init__(self, controller: Any) -> None:
],
)

self.new_user_input = True
self._start_presence_updates()

def user_settings(self) -> UserSettings:
return deepcopy(self._user_settings)

Expand Down Expand Up @@ -441,7 +443,10 @@ def _start_presence_updates(self) -> None:
response = self._notify_server_of_presence()
if response["result"] == "success":
self.initial_data["presences"] = response["presences"]

self._presence_timestamp = response.get("server_timestamp", time.time())
self._update_users_data_from_initial_data()

if hasattr(self.controller, "view"):
view = self.controller.view
view.users_view.update_user_list(user_list=self.users)
Expand Down Expand Up @@ -1181,6 +1186,7 @@ def get_user_info(self, user_id: int) -> Optional[TidiedUserInfo]:
def _update_users_data_from_initial_data(self) -> None:
# Dict which stores the active/idle status of users (by email)
presences = self.initial_data["presences"]
server_timestamp = self._presence_timestamp

# Construct a dict of each user in the realm to look up by email
# and a user-id to email mapping
Expand Down Expand Up @@ -1225,25 +1231,27 @@ def _update_users_data_from_initial_data(self) -> None:
* UserStatus, an arbitrary one is chosen.
"""
aggregate_status: UserStatus = "offline"
for client in presences[email].items():
client_name = client[0]
status = client[1]["status"]
timestamp = client[1]["timestamp"]
if client_name == "aggregated":
continue
elif (
time.time() - timestamp
server_aggregate_status = "offline"
for client_name, client_presence in presences[email].items():
status = client_presence["status"]
timestamp = client_presence["timestamp"]
if (
server_timestamp - timestamp
) < self.server_presence_offline_threshold_secs:
if status == "active":
aggregate_status = "active"
if status == "idle" and aggregate_status != "active":
aggregate_status = status
if status == "offline" and (
aggregate_status != "active" and aggregate_status != "idle"
):
aggregate_status = status

status = aggregate_status
if client_name == "aggregated":
server_aggregate_status = status
else:
if status == "active":
aggregate_status = "active"
if status == "idle" and aggregate_status != "active":
aggregate_status = status
if status == "offline" and (
aggregate_status != "active"
and aggregate_status != "idle"
):
aggregate_status = status

status = server_aggregate_status
else:
# Set status of users not in the `presence` list
# as 'inactive'. They will not be displayed in the
Expand Down