merge-requests/30/head
Bob Mottram 2021-10-13 12:15:06 +01:00
parent b8fbc8057b
commit 198381e99a
7 changed files with 37 additions and 65 deletions

View File

@ -12,6 +12,7 @@ from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from posts import getPersonBox from posts import getPersonBox
from session import postJson from session import postJson
from utils import hasObjectString
from utils import getFullDomain from utils import getFullDomain
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
@ -63,9 +64,7 @@ def outboxAvailability(baseDir: str, nickname: str, messageJson: {},
return False return False
if not hasActor(messageJson, debug): if not hasActor(messageJson, debug):
return False return False
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
return False
if not isinstance(messageJson['object'], str):
return False return False
actorNickname = getNicknameFromActor(messageJson['actor']) actorNickname = getNicknameFromActor(messageJson['actor'])

View File

@ -11,6 +11,7 @@ import os
import json import json
import time import time
from datetime import datetime from datetime import datetime
from utils import hasObjectString
from utils import hasObjectStringObject from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import removeDomainPort from utils import removeDomainPort
@ -349,13 +350,7 @@ def outboxBlock(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: not a block') print('DEBUG: not a block')
return False return False
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: no object in block')
return False
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: block object is not string')
return False return False
if debug: if debug:
print('DEBUG: c2s block request arrived in outbox') print('DEBUG: c2s block request arrived in outbox')
@ -468,8 +463,7 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
if hasObjectDict(postJsonObject): if hasObjectDict(postJsonObject):
postJsonObj = postJsonObject['object'] postJsonObj = postJsonObject['object']
else: else:
if postJsonObject.get('object'): if hasObjectString(postJsonObject, debug):
if isinstance(postJsonObject['object'], str):
alsoUpdatePostId = removeIdEnding(postJsonObject['object']) alsoUpdatePostId = removeIdEnding(postJsonObject['object'])
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
@ -597,8 +591,7 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
if hasObjectDict(postJsonObject): if hasObjectDict(postJsonObject):
postJsonObj = postJsonObject['object'] postJsonObj = postJsonObject['object']
else: else:
if postJsonObject.get('object'): if hasObjectString(postJsonObject, debug):
if isinstance(postJsonObject['object'], str):
alsoUpdatePostId = removeIdEnding(postJsonObject['object']) alsoUpdatePostId = removeIdEnding(postJsonObject['object'])
if postJsonObj.get('conversation'): if postJsonObj.get('conversation'):
@ -697,13 +690,7 @@ def outboxMute(baseDir: str, httpPrefix: str,
return return
if not messageJson['type'] == 'Ignore': if not messageJson['type'] == 'Ignore':
return return
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: no object in mute')
return
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: mute object is not string')
return return
if debug: if debug:
print('DEBUG: c2s mute request arrived in outbox') print('DEBUG: c2s mute request arrived in outbox')

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
import os import os
from datetime import datetime from datetime import datetime
from utils import hasObjectString
from utils import removeDomainPort from utils import removeDomainPort
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
@ -126,13 +127,7 @@ def outboxDelete(baseDir: str, httpPrefix: str,
if debug: if debug:
print('DEBUG: not a delete') print('DEBUG: not a delete')
return return
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: no object in delete')
return
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: delete object is not string')
return return
if debug: if debug:
print('DEBUG: c2s delete request arrived in outbox') print('DEBUG: c2s delete request arrived in outbox')

View File

@ -15,6 +15,7 @@ import random
from linked_data_sig import verifyJsonSignature from linked_data_sig import verifyJsonSignature
from languages import understoodPostLanguage from languages import understoodPostLanguage
from like import updateLikesCollection from like import updateLikesCollection
from utils import hasObjectString
from utils import hasObjectStringObject from utils import hasObjectStringObject
from utils import getReplyIntervalHours from utils import getReplyIntervalHours
from utils import canReplyTo from utils import canReplyTo
@ -896,13 +897,7 @@ def _receiveLike(recentPostsCache: {},
return False return False
if not hasActor(messageJson, debug): if not hasActor(messageJson, debug):
return False return False
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: ' + messageJson['type'] + ' has no object')
return False
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: ' + messageJson['type'] + ' object is not a string')
return False return False
if not messageJson.get('to'): if not messageJson.get('to'):
if debug: if debug:
@ -1305,13 +1300,7 @@ def _receiveDelete(session, handle: str, isGroup: bool, baseDir: str,
return False return False
if debug: if debug:
print('DEBUG: Delete activity arrived') print('DEBUG: Delete activity arrived')
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: ' + messageJson['type'] + ' has no object')
return False
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: ' + messageJson['type'] + ' object is not a string')
return False return False
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
deletePrefix = httpPrefix + '://' + domainFull + '/' deletePrefix = httpPrefix + '://' + domainFull + '/'
@ -1400,13 +1389,7 @@ def _receiveAnnounce(recentPostsCache: {},
return False return False
if debug: if debug:
print('DEBUG: receiving announce on ' + handle) print('DEBUG: receiving announce on ' + handle)
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: ' + messageJson['type'] + ' has no object')
return False
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: ' + messageJson['type'] + ' object is not a string')
return False return False
if not messageJson.get('to'): if not messageJson.get('to'):
if debug: if debug:

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
import os import os
from pprint import pprint from pprint import pprint
from utils import hasObjectString
from utils import hasObjectStringObject from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import removeDomainPort from utils import removeDomainPort
@ -345,13 +346,7 @@ def outboxLike(recentPostsCache: {},
if debug: if debug:
print('DEBUG: not a like') print('DEBUG: not a like')
return return
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
if debug:
print('DEBUG: no object in like')
return
if not isinstance(messageJson['object'], str):
if debug:
print('DEBUG: like object is not string')
return return
if debug: if debug:
print('DEBUG: c2s like request arrived in outbox') print('DEBUG: c2s like request arrived in outbox')

View File

@ -12,6 +12,7 @@ from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
from posts import getPersonBox from posts import getPersonBox
from session import postJson from session import postJson
from utils import hasObjectString
from utils import getFullDomain from utils import getFullDomain
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
@ -153,9 +154,7 @@ def outboxSkills(baseDir: str, nickname: str, messageJson: {},
return False return False
if not hasActor(messageJson, debug): if not hasActor(messageJson, debug):
return False return False
if not messageJson.get('object'): if not hasObjectString(messageJson, debug):
return False
if not isinstance(messageJson['object'], str):
return False return False
actorNickname = getNicknameFromActor(messageJson['actor']) actorNickname = getNicknameFromActor(messageJson['actor'])

View File

@ -1345,8 +1345,7 @@ def _getPublishedDate(postJsonObject: {}) -> str:
published = None published = None
if postJsonObject.get('published'): if postJsonObject.get('published'):
published = postJsonObject['published'] published = postJsonObject['published']
elif postJsonObject.get('object'): elif hasObjectDict(postJsonObject):
if isinstance(postJsonObject['object'], dict):
if postJsonObject['object'].get('published'): if postJsonObject['object'].get('published'):
published = postJsonObject['object']['published'] published = postJsonObject['object']['published']
if not published: if not published:
@ -3072,3 +3071,18 @@ def hasObjectStringObject(postJsonObject: {}, debug: bool) -> bool:
if debug: if debug:
print('No object field within dict ' + postJsonObject['id']) print('No object field within dict ' + postJsonObject['id'])
return False return False
def hasObjectString(postJsonObject: {}, debug: bool) -> bool:
"""Does the given post have an object string field?
"""
if postJsonObject.get('object'):
if isinstance(postJsonObject['object'], str):
return True
elif debug:
if postJsonObject.get('type'):
print('DEBUG: ' + postJsonObject['type'] +
' object is not a string')
if debug:
print('No object field within post ' + postJsonObject['id'])
return False