mirror of https://github.com/zulip/zulip.git
markdown: Refactor classes handling stream topic links.
The classes StreamPattern and StreamTopicPattern both had a separate copy of the function `find_stream_id` which did the same thing. Since another Pattern will be added as a part of #31920, it is a good idea to move that function into a superclass which is then inherited by all the related patterns. Fixes part of #31920
This commit is contained in:
parent
efa5b3cce1
commit
65c9b249b7
|
@ -1984,7 +1984,7 @@ class UserGroupMentionPattern(CompiledInlineProcessor):
|
|||
return None, None, None
|
||||
|
||||
|
||||
class StreamPattern(CompiledInlineProcessor):
|
||||
class StreamTopicMessageProcessor(CompiledInlineProcessor):
|
||||
def find_stream_id(self, name: str) -> int | None:
|
||||
db_data: DbData | None = self.zmd.zulip_db_data
|
||||
if db_data is None:
|
||||
|
@ -1992,6 +1992,8 @@ class StreamPattern(CompiledInlineProcessor):
|
|||
stream_id = db_data.stream_names.get(name)
|
||||
return stream_id
|
||||
|
||||
|
||||
class StreamPattern(StreamTopicMessageProcessor):
|
||||
@override
|
||||
def handleMatch( # type: ignore[override] # https://github.com/python/mypy/issues/10197
|
||||
self, m: Match[str], data: str
|
||||
|
@ -2016,14 +2018,7 @@ class StreamPattern(CompiledInlineProcessor):
|
|||
return el, m.start(), m.end()
|
||||
|
||||
|
||||
class StreamTopicPattern(CompiledInlineProcessor):
|
||||
def find_stream_id(self, name: str) -> int | None:
|
||||
db_data: DbData | None = self.zmd.zulip_db_data
|
||||
if db_data is None:
|
||||
return None
|
||||
stream_id = db_data.stream_names.get(name)
|
||||
return stream_id
|
||||
|
||||
class StreamTopicPattern(StreamTopicMessageProcessor):
|
||||
@override
|
||||
def handleMatch( # type: ignore[override] # https://github.com/python/mypy/issues/10197
|
||||
self, m: Match[str], data: str
|
||||
|
|
Loading…
Reference in New Issue