當前位置: 首頁>>代碼示例>>Python>>正文


Python DbClient.addMessageToInbox方法代碼示例

本文整理匯總了Python中dbclient.DbClient.addMessageToInbox方法的典型用法代碼示例。如果您正苦於以下問題:Python DbClient.addMessageToInbox方法的具體用法?Python DbClient.addMessageToInbox怎麽用?Python DbClient.addMessageToInbox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dbclient.DbClient的用法示例。


在下文中一共展示了DbClient.addMessageToInbox方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: dealWithUnencryptedMessage

# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import addMessageToInbox [as 別名]
	def dealWithUnencryptedMessage(message):
		'''Decide what to do with the given unencrypted message'''
		if message.messageType == Message.TYPE_CONTACT_REQUEST:
			print("Received a contact request from", message.senderId)
			# Check config to see whether we accept these or not
			if Config.getProperty(Config.KEY_ALLOW_FRIEND_REQUESTS) \
			  and MessageShuffler._isProfileStatusOk(message.senderId, [None, 'requested', 'untrusted', 'trusted']):
				# Call DbClient to store new message in inbox
				rowToStore = {"messageType":"contactrequest", "fromId":message.senderId,
					"fromName":message.senderName, "messageBody":message.message,
					"publicKey":message.publicKey, "timestamp":message.timestamp,
					"messageRead":False, "messageReplied":False}
				DbClient.addMessageToInbox(rowToStore)
		elif message.messageType == Message.TYPE_CONTACT_RESPONSE:
			print("It's an unencrypted contact response, so it must be a refusal")
			sender = DbClient.getProfile(message.senderId, False)
			if MessageShuffler._isProfileStatusOk(message.senderId, ['requested']):
				senderName = sender.get("displayName") if sender else ""
				ContactMaker.handleReceiveDeny(message.senderId)
				# Call DbClient to store new message in inbox
				rowToStore = {"messageType":"contactresponse", "fromId":message.senderId,
					"fromName":senderName, "messageBody":"", "accepted":False,
					"messageRead":False, "messageReplied":False, "timestamp":message.timestamp,
					"recipients":MessageShuffler.getOwnTorId()}
				DbClient.addMessageToInbox(rowToStore)
		else:
			print("Hä?  It's unencrypted but the message type is", message.messageType)
開發者ID:activityworkshop,項目名稱:Murmeli,代碼行數:29,代碼來源:messageshuffler.py

示例2: servePage

# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import addMessageToInbox [as 別名]
	def servePage(self, view, url, params):
		print("Compose: %s, params %s" % (url, ",".join(params)))
		if url == "/start":
			self.requirePageResources(['default.css'])
			parentHash = params.get("reply", None)
			recpts = params.get("sendto", None)
			# Build list of contacts to whom we can send
			userboxes = []
			for p in DbClient.getMessageableContacts():
				box = Bean()
				box.dispName = p['displayName']
				box.torid = p['torid']
				userboxes.append(box)
			pageParams = {"contactlist":userboxes, "parenthash" : parentHash if parentHash else "",
						 "webcachedir":Config.getWebCacheDir(), "recipientids":recpts}
			contents = self.buildPage({'pageTitle' : I18nManager.getText("composemessage.title"),
				'pageBody' : self.composetemplate.getHtml(pageParams),
				'pageFooter' : "<p>Footer</p>"})
			view.setHtml(contents)
			# If we've got no friends, then warn, can't send to anyone
			if not DbClient.hasFriends():
				view.page().mainFrame().evaluateJavaScript("window.alert('No friends :(');")

		elif url == "/send":
			print("Submit new message with params:", params)
			msgBody = params['messagebody']  # TODO: check body isn't empty, throw an exception?
			parentHash = params.get("parenthash", None)
			recpts = params['sendto']
			# Make a corresponding message object and pass it on
			msg = message.RegularMessage(sendTo=recpts, messageBody=msgBody, replyToHash=parentHash)
			msg.recipients = recpts.split(",")
			DbClient.addMessageToOutbox(msg)
			# Save a copy of the sent message
			sentMessage = {"messageType":"normal", "fromId":DbClient.getOwnTorId(),
				"messageBody":msgBody, "timestamp":msg.timestamp, "messageRead":True,
				"messageReplied":False, "recipients":recpts, "parentHash":parentHash}
			DbClient.addMessageToInbox(sentMessage)
			# Close window after successful send
			contents = self.buildPage({'pageTitle' : I18nManager.getText("messages.title"),
				'pageBody' : self.closingtemplate.getHtml(),
				'pageFooter' : "<p>Footer</p>"})
			view.setHtml(contents)
開發者ID:activityworkshop,項目名稱:Murmeli,代碼行數:44,代碼來源:pages.py

示例3: testConversationIdsFromParent

# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import addMessageToInbox [as 別名]
	def testConversationIdsFromParent(self):
		'''Check that the correct conversation id can be found based on a parent hash'''
		startId = DbClient.getNewConversationId()
		# Does it work on an empty inbox?
		DbClient._getInboxTable().remove()
		nextId = DbClient.getConversationId("some random hash")
		self.assertEqual(startId+1, nextId, "Should increment if hash not found in empty inbox")
		nextId = DbClient.getConversationId(None)
		self.assertEqual(startId+2, nextId, "Should increment if None hash given")
		nextId = DbClient.getConversationId("")
		self.assertEqual(startId+3, nextId, "Should increment if empty string hash given")
		# Now add a message with a hash
		rowToStore = {"messageType":"normal", "fromId":"BCD123EFG456HI78", "timestamp":"2012-01-08-13-18",
			"messageBody":"I do like a day beside the seaside", "recipients":"ABC123DEF456GH78"}
		DbClient.addMessageToInbox(rowToStore)
		nextId = DbClient.getConversationId("some random hash")
		self.assertEqual(startId+5, nextId, "Should increment if hash not found in inbox")
		nextId = DbClient.getConversationId("7b6dd00818a70515ba560efc5a42aab5")
		self.assertEqual(startId+4, nextId, "Should take the old id if hash was found in inbox")
		anotherId = DbClient.getConversationId("7b6dd00818a70515ba560efc5a42aab5")
		self.assertEqual(anotherId, nextId, "Should reuse the same id if hash was found in inbox")
開發者ID:activityworkshop,項目名稱:Murmeli,代碼行數:23,代碼來源:databasetest.py

示例4: dealWithAsymmetricMessage

# 需要導入模塊: from dbclient import DbClient [as 別名]
# 或者: from dbclient.DbClient import addMessageToInbox [as 別名]
	def dealWithAsymmetricMessage(message):
		'''Decide what to do with the given asymmetric message'''
		if message.senderId == MessageShuffler.getOwnTorId():
			print("*** Shouldn't receive a message from myself!")
			return
		# Sort message according to type
		if message.messageType == Message.TYPE_CONTACT_RESPONSE:
			print("Received a contact accept from", message.senderId, "name", message.senderName)
			if MessageShuffler._isProfileStatusOk(message.senderId, ['pending', 'requested', 'untrusted']):
				print(message.senderName, "'s public key is", message.senderKey)
				ContactMaker.handleReceiveAccept(message.senderId, message.senderName, message.senderKey)
				# Call DbClient to store new message in inbox
				rowToStore = {"messageType":"contactresponse", "fromId":message.senderId,
					"fromName":message.senderName, "messageBody":message.introMessage, "accepted":True,
					"messageRead":False, "messageReplied":False, "timestamp":message.timestamp,
					"recipients":MessageShuffler.getOwnTorId()}
				DbClient.addMessageToInbox(rowToStore)
			elif MessageShuffler._isProfileStatusOk(message.senderId, [None, 'blocked']):
				print("Received a contact response but I didn't send them a request!")
				print("Encrypted contents are:", message.encryptedContents)
				rowToStore = {"messageType":"contactresponse", "fromId":message.senderId,
					"fromName":message.senderName, "messageBody":message.introMessage, "accepted":True,
					"timestamp":message.timestamp, "encryptedMsg":message.encryptedContents}
				DbClient.addMessageToPendingContacts(rowToStore)
		elif message.messageType == Message.TYPE_STATUS_NOTIFY:
			if message.online:
				print("One of our contacts has just come online- ", message.senderId,
					"and hash is", message.profileHash)
				prof = DbClient.getProfile(userid=message.senderId, extend=False)
				if prof:
					storedHash = prof.get("profileHash", "empty")
					if message.profileHash != storedHash:
						reply = InfoRequestMessage(infoType=InfoRequestMessage.INFO_PROFILE)
						reply.recipients = [message.senderId]
						DbClient.addMessageToOutbox(reply)
					if message.ping:
						print("Now sending back a pong, too")
						reply = StatusNotifyMessage(online=True, ping=False, profileHash=None)
						reply.recipients = [message.senderId]
						DbClient.addMessageToOutbox(reply)
					else:
						print("It's already a pong so I won't reply")
				Contacts.comeOnline(message.senderId)
			else:
				print("One of our contacts is going offline -", message.senderId)
				Contacts.goneOffline(message.senderId)
		elif message.messageType == Message.TYPE_INFO_REQUEST:
			print("I've received an info request message for type", message.infoType)
			if MessageShuffler._isProfileStatusOk(message.senderId, ['trusted']):
				reply = InfoResponseMessage(message.messageType)
				reply.recipients = [message.senderId]
				DbClient.addMessageToOutbox(reply)
		elif message.messageType == Message.TYPE_INFO_RESPONSE:
			if message.profile and MessageShuffler._isProfileStatusOk(message.senderId, ['trusted', 'untrusted']):
				if message.profileHash:
					message.profile['profileHash'] = message.profileHash
				DbClient.updateContact(message.senderId, message.profile)
		elif message.messageType == Message.TYPE_ASYM_MESSAGE:
			print("It's a general kind of message, this should go in the Inbox, right?")
			if MessageShuffler._isProfileStatusOk(message.senderId, ['trusted', 'untrusted']):
				Contacts.comeOnline(message.senderId)
		else:
			# It's another asymmetric message type
			print("Hä?  What kind of asymmetric message type is that? ", message.messageType)
開發者ID:activityworkshop,項目名稱:Murmeli,代碼行數:66,代碼來源:messageshuffler.py


注:本文中的dbclient.DbClient.addMessageToInbox方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。