mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
hipchat: Rework stream/subscriber logic.
We now account for streams having users that
may be deleted. We do a couple things:
- use a loop instead of map
- only pass in users to hipchat_subscriber
- early-exit if there are not users
- skip owner/members logic for public streams
This commit is contained in:
@@ -207,7 +207,7 @@ def convert_room_data(raw_data: List[ZerverFieldsT],
|
|||||||
for d in raw_data
|
for d in raw_data
|
||||||
]
|
]
|
||||||
|
|
||||||
def invite_only(v: str) -> bool:
|
def get_invite_only(v: str) -> bool:
|
||||||
if v == 'public':
|
if v == 'public':
|
||||||
return False
|
return False
|
||||||
elif v == 'private':
|
elif v == 'private':
|
||||||
@@ -215,45 +215,51 @@ def convert_room_data(raw_data: List[ZerverFieldsT],
|
|||||||
else:
|
else:
|
||||||
raise Exception('unexpected value')
|
raise Exception('unexpected value')
|
||||||
|
|
||||||
def process(in_dict: ZerverFieldsT) -> ZerverFieldsT:
|
streams = []
|
||||||
|
|
||||||
|
for in_dict in flat_data:
|
||||||
now = int(timezone_now().timestamp())
|
now = int(timezone_now().timestamp())
|
||||||
stream_id = stream_id_mapper.get(in_dict['id'])
|
stream_id = stream_id_mapper.get(in_dict['id'])
|
||||||
|
|
||||||
out_dict = build_stream(
|
invite_only = get_invite_only(in_dict['privacy'])
|
||||||
|
|
||||||
|
stream = build_stream(
|
||||||
date_created=now,
|
date_created=now,
|
||||||
realm_id=realm_id,
|
realm_id=realm_id,
|
||||||
name=in_dict['name'],
|
name=in_dict['name'],
|
||||||
description=in_dict['topic'],
|
description=in_dict['topic'],
|
||||||
stream_id=stream_id,
|
stream_id=stream_id,
|
||||||
deactivated=in_dict['is_archived'],
|
deactivated=in_dict['is_archived'],
|
||||||
invite_only=invite_only(in_dict['privacy']),
|
invite_only=invite_only,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not user_id_mapper.has(in_dict['owner']):
|
if invite_only:
|
||||||
raise Exception('bad owner')
|
users = {
|
||||||
|
|
||||||
owner = user_id_mapper.get(in_dict['owner'])
|
|
||||||
members = {
|
|
||||||
user_id_mapper.get(key)
|
user_id_mapper.get(key)
|
||||||
for key in in_dict['members']
|
for key in in_dict['members']
|
||||||
if user_id_mapper.has(key)
|
if user_id_mapper.has(key)
|
||||||
}
|
} # type: Set[int]
|
||||||
|
|
||||||
|
if user_id_mapper.has(in_dict['owner']):
|
||||||
|
owner = user_id_mapper.get(in_dict['owner'])
|
||||||
|
users.add(owner)
|
||||||
|
|
||||||
|
if not users:
|
||||||
|
continue
|
||||||
|
|
||||||
subscriber_handler.set_info(
|
subscriber_handler.set_info(
|
||||||
stream_id=stream_id,
|
stream_id=stream_id,
|
||||||
owner=owner,
|
users=users,
|
||||||
members=members,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# unmapped fields:
|
# unmapped fields:
|
||||||
# guest_access_url: no Zulip equivalent
|
# guest_access_url: no Zulip equivalent
|
||||||
# created: we just use "now"
|
# created: we just use "now"
|
||||||
# members: no good sample data
|
|
||||||
# owners: no good sample data
|
|
||||||
# participants: no good sample data
|
# participants: no good sample data
|
||||||
return out_dict
|
|
||||||
|
|
||||||
return list(map(process, flat_data))
|
streams.append(stream)
|
||||||
|
|
||||||
|
return streams
|
||||||
|
|
||||||
def make_realm(realm_id: int) -> ZerverFieldsT:
|
def make_realm(realm_id: int) -> ZerverFieldsT:
|
||||||
NOW = float(timezone_now().timestamp())
|
NOW = float(timezone_now().timestamp())
|
||||||
|
|||||||
@@ -1,37 +1,15 @@
|
|||||||
from typing import Any, Dict, Set
|
from typing import Any, Dict, Set
|
||||||
|
|
||||||
class SubscriberHandler:
|
class SubscriberHandler:
|
||||||
'''
|
|
||||||
A note on ids here: we borrow Hipchat ids as Zulip
|
|
||||||
ids during the conversion phase. (They get re-mapped
|
|
||||||
during import, but that doesn't concern use here.)
|
|
||||||
|
|
||||||
So these are all synonymous:
|
|
||||||
|
|
||||||
HipChat room_id == Zulip stream_id
|
|
||||||
member ids = hipchat user ids = Zulip user_id
|
|
||||||
owner id = hipchat user id = Zulip user_id
|
|
||||||
|
|
||||||
In this class, when it's somewhat arbitrary whether
|
|
||||||
to call something a "room" or a "stream", we use
|
|
||||||
the Zulip naming.
|
|
||||||
'''
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.stream_info = dict() # type: Dict[int, Dict[str, Any]]
|
self.stream_info = dict() # type: Dict[int, Set[int]]
|
||||||
|
|
||||||
def set_info(self,
|
def set_info(self,
|
||||||
stream_id: int,
|
stream_id: int,
|
||||||
owner: int,
|
users: Set[int]) -> None:
|
||||||
members: Set[int]) -> None:
|
self.stream_info[stream_id] = users
|
||||||
# Our callers are basically giving us
|
|
||||||
# data straight out of rooms.json.
|
|
||||||
self.stream_info[stream_id] = dict(
|
|
||||||
owner=owner,
|
|
||||||
members=members,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_users(self,
|
def get_users(self,
|
||||||
stream_id: int) -> Set[int]:
|
stream_id: int) -> Set[int]:
|
||||||
info = self.stream_info[stream_id]
|
users = self.stream_info[stream_id]
|
||||||
users = info['members'] | {info['owner']}
|
|
||||||
return users
|
return users
|
||||||
|
|||||||
Reference in New Issue
Block a user