def message_header(message: Message) -> Dict[str, Any]: if message.recipient.type == Recipient.PERSONAL: narrow_link = get_narrow_url(user, message) header = f"You and {message.sender.full_name}" header_html = f"<a style='color: #ffffff;' href='{narrow_link}'>{header}</a>" elif message.recipient.type == Recipient.HUDDLE: display_recipient = get_display_recipient(message.recipient) assert not isinstance(display_recipient, str) narrow_link = get_narrow_url(user, message, display_recipient=display_recipient) other_recipients = [ r["full_name"] for r in display_recipient if r["id"] != user.id ] header = "You and {}".format(", ".join(other_recipients)) header_html = f"<a style='color: #ffffff;' href='{narrow_link}'>{header}</a>" else: stream_id = message.recipient.type_id stream = stream_map.get(stream_id, None) if stream is None: # Some of our callers don't populate stream_map, so # we just populate the stream from the database. stream = Stream.objects.only("id", "name").get(id=stream_id) narrow_link = get_narrow_url(user, message, stream=stream) header = f"{stream.name} > {message.topic_name()}" stream_link = stream_narrow_url(user.realm, stream) header_html = f"<a href='{stream_link}'>{stream.name}</a> > <a href='{narrow_link}'>{message.topic_name()}</a>" return { "plain": header, "html": header_html, "stream_message": message.recipient.type_name() == "stream", }
def message_header(user_profile: UserProfile, message: Message) -> Dict[str, Any]: if message.recipient.type == Recipient.PERSONAL: narrow_link = get_narrow_url(user_profile, message) header = f"You and {message.sender.full_name}" header_html = f"<a style='color: #ffffff;' href='{narrow_link}'>{header}</a>" elif message.recipient.type == Recipient.HUDDLE: display_recipient = get_display_recipient(message.recipient) assert not isinstance(display_recipient, str) narrow_link = get_narrow_url(user_profile, message, display_recipient=display_recipient) other_recipients = [ r['full_name'] for r in display_recipient if r['id'] != user_profile.id ] header = "You and {}".format(", ".join(other_recipients)) header_html = f"<a style='color: #ffffff;' href='{narrow_link}'>{header}</a>" else: stream = Stream.objects.only( 'id', 'name').get(id=message.recipient.type_id) narrow_link = get_narrow_url(user_profile, message, stream=stream) header = f"{stream.name} > {message.topic_name()}" stream_link = stream_narrow_url(user_profile.realm, stream) header_html = f"<a href='{stream_link}'>{stream.name}</a> > <a href='{narrow_link}'>{message.topic_name()}</a>" return { "plain": header, "html": header_html, "stream_message": message.recipient.type_name() == "stream" }
def message_header(user_profile: UserProfile, message: Message) -> Dict[str, Any]: if message.recipient.type == Recipient.PERSONAL: header = "You and %s" % (message.sender.full_name,) html_link = personal_narrow_url( realm=user_profile.realm, sender=message.sender, ) header_html = "<a style='color: #ffffff;' href='%s'>%s</a>" % (html_link, header) elif message.recipient.type == Recipient.HUDDLE: disp_recipient = get_display_recipient(message.recipient) assert not isinstance(disp_recipient, str) other_recipients = [r['full_name'] for r in disp_recipient if r['id'] != user_profile.id] header = "You and %s" % (", ".join(other_recipients),) other_user_ids = [r['id'] for r in disp_recipient if r['id'] != user_profile.id] html_link = huddle_narrow_url( realm=user_profile.realm, other_user_ids=other_user_ids, ) header_html = "<a style='color: #ffffff;' href='%s'>%s</a>" % (html_link, header) else: stream = Stream.objects.only('id', 'name').get(id=message.recipient.type_id) header = "%s > %s" % (stream.name, message.topic_name()) stream_link = stream_narrow_url(user_profile.realm, stream) topic_link = topic_narrow_url(user_profile.realm, stream, message.topic_name()) header_html = "<a href='%s'>%s</a> > <a href='%s'>%s</a>" % ( stream_link, stream.name, topic_link, message.topic_name()) return {"plain": header, "html": header_html, "stream_message": message.recipient.type_name() == "stream"}