comparison sat/plugins/plugin_comp_ap_gateway/events.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 26c3e1bc7fb7
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
111 be 111 be
112 @return: AP activity wrapping an Event object 112 @return: AP activity wrapping an Event object
113 """ 113 """
114 if not event_data.get("id"): 114 if not event_data.get("id"):
115 event_data["id"] = shortuuid.uuid() 115 event_data["id"] = shortuuid.uuid()
116 ap_account = await self.apg.getAPAccountFromJidAndNode( 116 ap_account = await self.apg.get_ap_account_from_jid_and_node(
117 author_jid, 117 author_jid,
118 self._events.namespace 118 self._events.namespace
119 ) 119 )
120 url_actor = self.apg.buildAPURL(TYPE_ACTOR, ap_account) 120 url_actor = self.apg.build_apurl(TYPE_ACTOR, ap_account)
121 url_item = self.apg.buildAPURL(TYPE_ITEM, ap_account, event_data["id"]) 121 url_item = self.apg.build_apurl(TYPE_ITEM, ap_account, event_data["id"])
122 ap_object = { 122 ap_object = {
123 "actor": url_actor, 123 "actor": url_actor,
124 "attributedTo": url_actor, 124 "attributedTo": url_actor,
125 "to": [NS_AP_PUBLIC], 125 "to": [NS_AP_PUBLIC],
126 "id": url_item, 126 "id": url_item,
244 @return: AP Item's Object and event data 244 @return: AP Item's Object and event data
245 @raise exceptions.DataError: something is invalid in the AP item 245 @raise exceptions.DataError: something is invalid in the AP item
246 """ 246 """
247 is_activity = self.apg.is_activity(ap_item) 247 is_activity = self.apg.is_activity(ap_item)
248 if is_activity: 248 if is_activity:
249 ap_object = await self.apg.apGetObject(ap_item, "object") 249 ap_object = await self.apg.ap_get_object(ap_item, "object")
250 if not ap_object: 250 if not ap_object:
251 log.warning(f'No "object" found in AP item {ap_item!r}') 251 log.warning(f'No "object" found in AP item {ap_item!r}')
252 raise exceptions.DataError 252 raise exceptions.DataError
253 else: 253 else:
254 ap_object = ap_item 254 ap_object = ap_item
255 255
256 # id 256 # id
257 if "_repeated" in ap_item: 257 if "_repeated" in ap_item:
258 # if the event is repeated, we use the original one ID 258 # if the event is repeated, we use the original one ID
259 repeated_uri = ap_item["_repeated"]["uri"] 259 repeated_uri = ap_item["_repeated"]["uri"]
260 parsed_uri = uri.parseXMPPUri(repeated_uri) 260 parsed_uri = uri.parse_xmpp_uri(repeated_uri)
261 object_id = parsed_uri["item"] 261 object_id = parsed_uri["item"]
262 else: 262 else:
263 object_id = ap_object.get("id") 263 object_id = ap_object.get("id")
264 if not object_id: 264 if not object_id:
265 raise exceptions.DataError('"id" is missing in AP object') 265 raise exceptions.DataError('"id" is missing in AP object')
266 266
267 if ap_item["type"] != TYPE_EVENT: 267 if ap_item["type"] != TYPE_EVENT:
268 raise exceptions.DataError("AP Object is not an event") 268 raise exceptions.DataError("AP Object is not an event")
269 269
270 # author 270 # author
271 actor = await self.apg.apGetSenderActor(ap_object) 271 actor = await self.apg.ap_get_sender_actor(ap_object)
272 272
273 account = await self.apg.getAPAccountFromId(actor) 273 account = await self.apg.get_ap_account_from_id(actor)
274 author_jid = self.apg.getLocalJIDFromAccount(account).full() 274 author_jid = self.apg.get_local_jid_from_account(account).full()
275 275
276 # name, start, end 276 # name, start, end
277 event_data = { 277 event_data = {
278 "id": object_id, 278 "id": object_id,
279 "name": {"": ap_object.get("name") or "unnamed"}, 279 "name": {"": ap_object.get("name") or "unnamed"},
368 }) 368 })
369 369
370 # comments 370 # comments
371 371
372 if ap_object.get("commentsEnabled"): 372 if ap_object.get("commentsEnabled"):
373 __, comments_node = await self.apg.getCommentsNodes(object_id, None) 373 __, comments_node = await self.apg.get_comments_nodes(object_id, None)
374 event_data["comments"] = { 374 event_data["comments"] = {
375 "service": author_jid, 375 "service": author_jid,
376 "node": comments_node, 376 "node": comments_node,
377 } 377 }
378 378