forked from indymedia/epicyon
Support c2s posts
parent
543f1eb142
commit
0a348ac02a
129
posts.py
129
posts.py
|
@ -251,7 +251,7 @@ def deleteAllPosts(baseDir: str,nickname: str, domain: str) -> None:
|
||||||
|
|
||||||
def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
|
def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
|
||||||
toUrl: str, ccUrl: str, https: bool, content: str, \
|
toUrl: str, ccUrl: str, https: bool, content: str, \
|
||||||
followersOnly: bool, saveToFile: bool, \
|
followersOnly: bool, saveToFile: bool, clientToServer: bool, \
|
||||||
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
|
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
|
||||||
"""Creates a message
|
"""Creates a message
|
||||||
"""
|
"""
|
||||||
|
@ -276,43 +276,68 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
|
||||||
if subject:
|
if subject:
|
||||||
summary=subject
|
summary=subject
|
||||||
sensitive=True
|
sensitive=True
|
||||||
newPost = {
|
if not clientToServer:
|
||||||
'id': newPostId+'/activity',
|
newPost = {
|
||||||
'type': 'Create',
|
'id': newPostId+'/activity',
|
||||||
'actor': prefix+'://'+domain+'/users/'+nickname,
|
'type': 'Create',
|
||||||
'published': published,
|
'actor': prefix+'://'+domain+'/users/'+nickname,
|
||||||
'to': [toUrl],
|
'published': published,
|
||||||
'cc': [],
|
'to': [toUrl],
|
||||||
'object': {'id': newPostId,
|
'cc': [],
|
||||||
'type': 'Note',
|
'object': {
|
||||||
'summary': summary,
|
'id': newPostId,
|
||||||
'inReplyTo': inReplyTo,
|
'type': 'Note',
|
||||||
'published': published,
|
'summary': summary,
|
||||||
'url': prefix+'://'+domain+'/@'+nickname+'/'+statusNumber,
|
'inReplyTo': inReplyTo,
|
||||||
'attributedTo': prefix+'://'+domain+'/users/'+nickname,
|
'published': published,
|
||||||
'to': [toUrl],
|
'url': prefix+'://'+domain+'/@'+nickname+'/'+statusNumber,
|
||||||
'cc': [],
|
'attributedTo': prefix+'://'+domain+'/users/'+nickname,
|
||||||
'sensitive': sensitive,
|
'to': [toUrl],
|
||||||
'atomUri': prefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber,
|
'cc': [],
|
||||||
'inReplyToAtomUri': inReplyToAtomUri,
|
'sensitive': sensitive,
|
||||||
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
|
'atomUri': prefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber,
|
||||||
'content': content,
|
'inReplyToAtomUri': inReplyToAtomUri,
|
||||||
'contentMap': {
|
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
|
||||||
'en': content
|
'content': content,
|
||||||
},
|
'contentMap': {
|
||||||
'attachment': [],
|
'en': content
|
||||||
'tag': [],
|
},
|
||||||
'replies': {}
|
'attachment': [],
|
||||||
# 'id': 'https://'+domain+'/users/'+nickname+'/statuses/'+statusNumber+'/replies',
|
'tag': [],
|
||||||
# 'type': 'Collection',
|
'replies': {}
|
||||||
# 'first': {
|
# 'id': 'https://'+domain+'/users/'+nickname+'/statuses/'+statusNumber+'/replies',
|
||||||
# 'type': 'CollectionPage',
|
# 'type': 'Collection',
|
||||||
# 'partOf': 'https://'+domain+'/users/'+nickname+'/statuses/'+statusNumber+'/replies',
|
# 'first': {
|
||||||
# 'items': []
|
# 'type': 'CollectionPage',
|
||||||
# }
|
# 'partOf': 'https://'+domain+'/users/'+nickname+'/statuses/'+statusNumber+'/replies',
|
||||||
#}
|
# 'items': []
|
||||||
|
# }
|
||||||
|
#}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
newPost = {
|
||||||
|
'id': newPostId,
|
||||||
|
'type': 'Note',
|
||||||
|
'summary': summary,
|
||||||
|
'inReplyTo': inReplyTo,
|
||||||
|
'published': published,
|
||||||
|
'url': prefix+'://'+domain+'/@'+nickname+'/'+statusNumber,
|
||||||
|
'attributedTo': prefix+'://'+domain+'/users/'+nickname,
|
||||||
|
'to': [toUrl],
|
||||||
|
'cc': [],
|
||||||
|
'sensitive': sensitive,
|
||||||
|
'atomUri': prefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber,
|
||||||
|
'inReplyToAtomUri': inReplyToAtomUri,
|
||||||
|
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
|
||||||
|
'content': content,
|
||||||
|
'contentMap': {
|
||||||
|
'en': content
|
||||||
|
},
|
||||||
|
'attachment': [],
|
||||||
|
'tag': [],
|
||||||
|
'replies': {}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ccUrl:
|
if ccUrl:
|
||||||
if len(ccUrl)>0:
|
if len(ccUrl)>0:
|
||||||
newPost['cc']=ccUrl
|
newPost['cc']=ccUrl
|
||||||
|
@ -326,8 +351,10 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
|
||||||
commentjson.dump(newPost, fp, indent=4, sort_keys=False)
|
commentjson.dump(newPost, fp, indent=4, sort_keys=False)
|
||||||
return newPost
|
return newPost
|
||||||
|
|
||||||
def createPublicPost(baseDir: str,nickname: str, domain: str, port: int,https: bool, \
|
def createPublicPost(baseDir: str,
|
||||||
content: str, followersOnly: bool, saveToFile: bool, \
|
nickname: str, domain: str, port: int,https: bool, \
|
||||||
|
content: str, followersOnly: bool, saveToFile: bool,
|
||||||
|
clientToServer: bool, \
|
||||||
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
|
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
|
||||||
"""Public post to the outbox
|
"""Public post to the outbox
|
||||||
"""
|
"""
|
||||||
|
@ -337,7 +364,7 @@ def createPublicPost(baseDir: str,nickname: str, domain: str, port: int,https: b
|
||||||
return createPostBase(baseDir,nickname, domain, port, \
|
return createPostBase(baseDir,nickname, domain, port, \
|
||||||
'https://www.w3.org/ns/activitystreams#Public', \
|
'https://www.w3.org/ns/activitystreams#Public', \
|
||||||
prefix+'://'+domain+'/users/'+nickname+'/followers', \
|
prefix+'://'+domain+'/users/'+nickname+'/followers', \
|
||||||
https, content, followersOnly, saveToFile, \
|
https, content, followersOnly, saveToFile, clientToServer, \
|
||||||
inReplyTo, inReplyToAtomUri, subject)
|
inReplyTo, inReplyToAtomUri, subject)
|
||||||
|
|
||||||
def threadSendPost(session,postJsonObject: {},federationList: [],inboxUrl: str, \
|
def threadSendPost(session,postJsonObject: {},federationList: [],inboxUrl: str, \
|
||||||
|
@ -368,8 +395,8 @@ def threadSendPost(session,postJsonObject: {},federationList: [],inboxUrl: str,
|
||||||
def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
|
def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
|
||||||
toNickname: str, toDomain: str, toPort: int, cc: str, \
|
toNickname: str, toDomain: str, toPort: int, cc: str, \
|
||||||
https: bool, content: str, followersOnly: bool, \
|
https: bool, content: str, followersOnly: bool, \
|
||||||
saveToFile: bool, federationList: [], sendThreads: [], \
|
saveToFile: bool, clientToServer: bool, federationList: [], \
|
||||||
postLog: [], cachedWebfingers: {},personCache: {}, \
|
sendThreads: [], postLog: [], cachedWebfingers: {},personCache: {}, \
|
||||||
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> int:
|
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> int:
|
||||||
"""Post to another inbox
|
"""Post to another inbox
|
||||||
"""
|
"""
|
||||||
|
@ -399,21 +426,27 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
|
||||||
if not toPersonId:
|
if not toPersonId:
|
||||||
return 4
|
return 4
|
||||||
|
|
||||||
postJsonObject=createPostBase(baseDir,nickname,domain,port, \
|
postJsonObject = \
|
||||||
toPersonId,cc,https,content, \
|
createPostBase(baseDir,nickname,domain,port, \
|
||||||
followersOnly,saveToFile, \
|
toPersonId,cc,https,content, \
|
||||||
inReplyTo,inReplyToAtomUri, \
|
followersOnly,saveToFile,clientToServer, \
|
||||||
subject)
|
inReplyTo,inReplyToAtomUri, \
|
||||||
|
subject)
|
||||||
|
|
||||||
# get the senders private key
|
# get the senders private key
|
||||||
privateKeyPem=getPersonKey(nickname,domain,baseDir,'private')
|
privateKeyPem=getPersonKey(nickname,domain,baseDir,'private')
|
||||||
if len(privateKeyPem)==0:
|
if len(privateKeyPem)==0:
|
||||||
return 5
|
return 5
|
||||||
|
|
||||||
|
if not clientToServer:
|
||||||
|
postPath='/inbox'
|
||||||
|
else:
|
||||||
|
postPath='/outbox'
|
||||||
|
|
||||||
# construct the http header
|
# construct the http header
|
||||||
signatureHeaderJson = \
|
signatureHeaderJson = \
|
||||||
createSignedHeader(privateKeyPem, nickname, domain, port, \
|
createSignedHeader(privateKeyPem, nickname, domain, port, \
|
||||||
'/inbox', https, withDigest, postJsonObject)
|
postPath, https, withDigest, postJsonObject)
|
||||||
|
|
||||||
# Keep the number of threads being used small
|
# Keep the number of threads being used small
|
||||||
while len(sendThreads)>10:
|
while len(sendThreads)>10:
|
||||||
|
|
20
tests.py
20
tests.py
|
@ -110,13 +110,14 @@ def createServerAlice(path: str,domain: str,port: int,federationList: []):
|
||||||
nickname='alice'
|
nickname='alice'
|
||||||
https=False
|
https=False
|
||||||
useTor=False
|
useTor=False
|
||||||
|
clientToServer=False
|
||||||
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,https,True)
|
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,https,True)
|
||||||
deleteAllPosts(path,nickname,domain)
|
deleteAllPosts(path,nickname,domain)
|
||||||
followPerson(path,nickname,domain,'bob','127.0.0.100:61936',federationList)
|
followPerson(path,nickname,domain,'bob','127.0.0.100:61936',federationList)
|
||||||
followerOfPerson(path,nickname,domain,'bob','127.0.0.100:61936',federationList)
|
followerOfPerson(path,nickname,domain,'bob','127.0.0.100:61936',federationList)
|
||||||
createPublicPost(path,nickname, domain, port,https, "No wise fish would go anywhere without a porpoise", False, True)
|
createPublicPost(path,nickname, domain, port,https, "No wise fish would go anywhere without a porpoise", False, True, clientToServer)
|
||||||
createPublicPost(path,nickname, domain, port,https, "Curiouser and curiouser!", False, True)
|
createPublicPost(path,nickname, domain, port,https, "Curiouser and curiouser!", False, True, clientToServer)
|
||||||
createPublicPost(path,nickname, domain, port,https, "In the gardens of memory, in the palace of dreams, that is where you and I shall meet", False, True)
|
createPublicPost(path,nickname, domain, port,https, "In the gardens of memory, in the palace of dreams, that is where you and I shall meet", False, True, clientToServer)
|
||||||
global testServerAliceRunning
|
global testServerAliceRunning
|
||||||
testServerAliceRunning = True
|
testServerAliceRunning = True
|
||||||
print('Server running: Alice')
|
print('Server running: Alice')
|
||||||
|
@ -131,13 +132,14 @@ def createServerBob(path: str,domain: str,port: int,federationList: []):
|
||||||
nickname='bob'
|
nickname='bob'
|
||||||
https=False
|
https=False
|
||||||
useTor=False
|
useTor=False
|
||||||
|
clientToServer=False
|
||||||
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,https,True)
|
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,https,True)
|
||||||
deleteAllPosts(path,nickname,domain)
|
deleteAllPosts(path,nickname,domain)
|
||||||
followPerson(path,nickname,domain,'alice','127.0.0.50:61935',federationList)
|
followPerson(path,nickname,domain,'alice','127.0.0.50:61935',federationList)
|
||||||
followerOfPerson(path,nickname,domain,'alice','127.0.0.50:61935',federationList)
|
followerOfPerson(path,nickname,domain,'alice','127.0.0.50:61935',federationList)
|
||||||
createPublicPost(path,nickname, domain, port,https, "It's your life, live it your way.", False, True)
|
createPublicPost(path,nickname, domain, port,https, "It's your life, live it your way.", False, True, clientToServer)
|
||||||
createPublicPost(path,nickname, domain, port,https, "One of the things I've realised is that I am very simple", False, True)
|
createPublicPost(path,nickname, domain, port,https, "One of the things I've realised is that I am very simple", False, True, clientToServer)
|
||||||
createPublicPost(path,nickname, domain, port,https, "Quantum physics is a bit of a passion of mine", False, True)
|
createPublicPost(path,nickname, domain, port,https, "Quantum physics is a bit of a passion of mine", False, True, clientToServer)
|
||||||
global testServerBobRunning
|
global testServerBobRunning
|
||||||
testServerBobRunning = True
|
testServerBobRunning = True
|
||||||
print('Server running: Bob')
|
print('Server running: Bob')
|
||||||
|
@ -191,10 +193,11 @@ def testPostMessageBetweenServers():
|
||||||
alicePostLog = []
|
alicePostLog = []
|
||||||
followersOnly=False
|
followersOnly=False
|
||||||
saveToFile=True
|
saveToFile=True
|
||||||
|
clientToServer=False
|
||||||
ccUrl=None
|
ccUrl=None
|
||||||
alicePersonCache={}
|
alicePersonCache={}
|
||||||
aliceCachedWebfingers={}
|
aliceCachedWebfingers={}
|
||||||
sendResult = sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, 'bob', bobDomain, bobPort, ccUrl, https, 'Why is a mouse when it spins?', followersOnly, saveToFile, federationList, aliceSendThreads, alicePostLog, aliceCachedWebfingers,alicePersonCache,inReplyTo, inReplyToAtomUri, subject)
|
sendResult = sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, 'bob', bobDomain, bobPort, ccUrl, https, 'Why is a mouse when it spins?', followersOnly, saveToFile, clientToServer, federationList, aliceSendThreads, alicePostLog, aliceCachedWebfingers,alicePersonCache,inReplyTo, inReplyToAtomUri, subject)
|
||||||
print('sendResult: '+str(sendResult))
|
print('sendResult: '+str(sendResult))
|
||||||
|
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
|
@ -275,6 +278,7 @@ def testCreatePerson():
|
||||||
domain='badgerdomain.com'
|
domain='badgerdomain.com'
|
||||||
port=80
|
port=80
|
||||||
https=True
|
https=True
|
||||||
|
clientToServer=False
|
||||||
baseDir=currDir+'/.tests_createperson'
|
baseDir=currDir+'/.tests_createperson'
|
||||||
if os.path.isdir(baseDir):
|
if os.path.isdir(baseDir):
|
||||||
shutil.rmtree(baseDir)
|
shutil.rmtree(baseDir)
|
||||||
|
@ -286,7 +290,7 @@ def testCreatePerson():
|
||||||
setPreferredNickname(baseDir,nickname,domain,'badger')
|
setPreferredNickname(baseDir,nickname,domain,'badger')
|
||||||
setBio(baseDir,nickname,domain,'Randomly roaming in your backyard')
|
setBio(baseDir,nickname,domain,'Randomly roaming in your backyard')
|
||||||
archivePosts(nickname,domain,baseDir,4)
|
archivePosts(nickname,domain,baseDir,4)
|
||||||
createPublicPost(baseDir,nickname, domain, port,https, "G'day world!", False, True, None, None, 'Not suitable for Vogons')
|
createPublicPost(baseDir,nickname, domain, port,https, "G'day world!", False, True, clientToServer, None, None, 'Not suitable for Vogons')
|
||||||
|
|
||||||
os.chdir(currDir)
|
os.chdir(currDir)
|
||||||
shutil.rmtree(baseDir)
|
shutil.rmtree(baseDir)
|
||||||
|
|
Loading…
Reference in New Issue