comparison libervia/backend/plugins/plugin_xep_0422.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
70 message_elt: domish.Element, 70 message_elt: domish.Element,
71 origin_id: str, 71 origin_id: str,
72 clear: Optional[bool] = None, 72 clear: Optional[bool] = None,
73 shell: Optional[bool] = None, 73 shell: Optional[bool] = None,
74 children: Optional[List[domish.Element]] = None, 74 children: Optional[List[domish.Element]] = None,
75 external: Optional[List[Union[str, Tuple[str, str]]]] = None 75 external: Optional[List[Union[str, Tuple[str, str]]]] = None,
76 ) -> domish.Element: 76 ) -> domish.Element:
77 """Generate, add and return <apply-to> element 77 """Generate, add and return <apply-to> element
78 78
79 @param message_elt: wrapping <message> element 79 @param message_elt: wrapping <message> element
80 @param origin_id: origin ID of the target message 80 @param origin_id: origin ID of the target message
110 external_elt["element-namespace"] = ns 110 external_elt["element-namespace"] = ns
111 return apply_to_elt 111 return apply_to_elt
112 112
113 @async_lru(maxsize=5) 113 @async_lru(maxsize=5)
114 async def get_fastened_elts( 114 async def get_fastened_elts(
115 self, 115 self, client: SatXMPPEntity, message_elt: domish.Element
116 client: SatXMPPEntity,
117 message_elt: domish.Element
118 ) -> Optional[FastenMetadata]: 116 ) -> Optional[FastenMetadata]:
119 """Get fastened elements 117 """Get fastened elements
120 118
121 if the message contains no <apply-to> element, None is returned 119 if the message contains no <apply-to> element, None is returned
122 """ 120 """
125 except StopIteration: 123 except StopIteration:
126 return None 124 return None
127 else: 125 else:
128 origin_id = apply_to_elt.getAttribute("id") 126 origin_id = apply_to_elt.getAttribute("id")
129 if not origin_id: 127 if not origin_id:
130 log.warning( 128 log.warning(f"Received invalid fastening message: {message_elt.toXml()}")
131 f"Received invalid fastening message: {message_elt.toXml()}"
132 )
133 return None 129 return None
134 elements = apply_to_elt.children 130 elements = apply_to_elt.children
135 if not elements: 131 if not elements:
136 log.warning(f"No element to fasten: {message_elt.toXml()}") 132 log.warning(f"No element to fasten: {message_elt.toXml()}")
137 return None 133 return None
138 history = await self.host.memory.storage.get( 134 history = await self.host.memory.storage.get(
139 client, 135 client,
140 History, 136 History,
141 History.origin_id, 137 History.origin_id,
142 origin_id, 138 origin_id,
143 (History.messages, History.subjects, History.thread) 139 (History.messages, History.subjects, History.thread),
144 ) 140 )
145 return FastenMetadata( 141 return FastenMetadata(
146 elements, 142 elements,
147 origin_id, 143 origin_id,
148 history, 144 history,