提交 2bc6e0b7 编写于 作者: L LittleCoder

Add logging of sending messages & fix bug of chatroom returned by sync

上级 b9a152f4
......@@ -98,6 +98,10 @@ def update_friend(self, userName):
return r if 1 < len(r) else r[0]
def update_local_chatrooms(core, l):
'''
get a list of chatrooms for updating local chatrooms
return a list of given chatrooms with updated info
'''
oldUsernameList = []
for chatroom in l:
# format NickName & DisplayName & self keys
......@@ -119,6 +123,7 @@ def update_local_chatrooms(core, l):
oldMember = utils.search_dict_list(
oldMemberList, 'UserName', member['UserName'])
if oldMember is not None:
#TODO
for k in oldMember:
member[k] = member.get(k) or oldMember[k]
else:
......@@ -158,12 +163,12 @@ def update_local_chatrooms(core, l):
def update_local_friends(core, l):
fullList = core.memberList + core.mpList
for friend in l:
utils.emoji_formatter(friend, 'NickName')
utils.emoji_formatter(friend, 'DisplayName')
oldInfoDict = utils.search_dict_list(
fullList, 'UserName', friend['UserName'])
if oldInfoDict is None:
oldInfoDict = copy.deepcopy(friend)
utils.emoji_formatter(oldInfoDict, 'NickName')
utils.emoji_formatter(oldInfoDict, 'DisplayName')
if oldInfoDict['VerifyFlag'] & 8 == 0:
core.memberList.append(oldInfoDict)
else:
......@@ -176,6 +181,10 @@ def update_local_friends(core, l):
oldInfoDict[k] = v
def update_local_uin(core, msg):
'''
content contains uins and StatusNotifyUserName contains username
they are in same order, so what I do is to pair them together
'''
uins = re.search('<username>([^<]*?)<', msg['Content'])
usernameChangedList = []
r = {
......@@ -232,7 +241,6 @@ def get_contact(self, update=False):
tempList = json.loads(r.content.decode('utf-8', 'replace'))['MemberList']
chatroomList, otherList = [], []
for m in tempList:
utils.emoji_formatter(m, 'NickName')
if m['Sex'] != 0:
otherList.append(m)
elif '@@' in m['UserName']:
......
......@@ -52,7 +52,11 @@ def load_login_status(self, fileDir,
'Ret': -1003, }})
else:
if contactList:
update_local_chatrooms(self, contactList)
for contact in contactList:
if '@@' in contact['UserName']:
update_local_chatrooms(self, [contact])
else:
update_local_chatrooms(self, [contact])
if msgList:
msgList = produce_msg(self, msgList)
for msg in msgList: self.msgList.put(msg)
......
......@@ -159,6 +159,7 @@ def web_init(self):
for item in dic['SyncKey']['List']])
self.storageClass.userName = dic['User']['UserName']
self.storageClass.nickName = dic['User']['NickName']
self.memberList.append(dic['User'])
return dic
def show_mobile_login(self):
......@@ -190,7 +191,13 @@ def start_receiving(self, exitCallback=None):
else:
msgList, contactList = self.get_msg()
if contactList:
chatroomMsg = update_local_chatrooms(self, contactList)
chatroomList, otherList = [], []
for contact in contactList:
if '@@' in contact['UserName']:
chatroomList.append(contact)
else:
otherList.append(contact)
chatroomMsg = update_local_chatrooms(self, chatroomList)
self.msgList.put(chatroomMsg)
if msgList:
msgList = produce_msg(self, msgList)
......
......@@ -231,10 +231,13 @@ def send_raw_msg(self, msgType, content, toUserName):
return ReturnValue(rawResponse=r)
def send_msg(self, msg='Test Message', toUserName=None):
logger.debug('Request to send a text message to %s: %s' % (toUserName, msg))
r = self.send_raw_msg(1, msg, toUserName)
return r
def upload_file(self, fileDir, isPicture=False, isVideo=False):
logger.debug('Request to upload a %s: %s' % (
'picture' if isPicture else 'video' if isVideo else 'file', fileDir))
if not utils.check_file(fileDir):
return ReturnValue({'BaseResponse': {
'ErrMsg': 'No file found in specific dir',
......@@ -267,6 +270,8 @@ def upload_file(self, fileDir, isPicture=False, isVideo=False):
return ReturnValue(rawResponse=r)
def send_file(self, fileDir, toUserName=None, mediaId=None):
logger.debug('Request to send a file(mediaId: %s) to %s: %s' % (
mediaId, toUserName, fileDir))
if toUserName is None: toUserName = self.storageClass.userName
if mediaId is None:
r = self.upload_file(fileDir)
......@@ -296,6 +301,8 @@ def send_file(self, fileDir, toUserName=None, mediaId=None):
return ReturnValue(rawResponse=r)
def send_image(self, fileDir, toUserName=None, mediaId=None):
logger.debug('Request to send a image(mediaId: %s) to %s: %s' % (
mediaId, toUserName, fileDir))
if toUserName is None: toUserName = self.storageClass.userName
if mediaId is None:
r = self.upload_file(fileDir, isPicture=not fileDir[-4:] == '.gif')
......@@ -326,6 +333,8 @@ def send_image(self, fileDir, toUserName=None, mediaId=None):
return ReturnValue(rawResponse=r)
def send_video(self, fileDir=None, toUserName=None, mediaId=None):
logger.debug('Request to send a video(mediaId: %s) to %s: %s' % (
mediaId, toUserName, fileDir))
if toUserName is None: toUserName = self.storageClass.userName
if mediaId is None:
r = self.upload_file(fileDir, isVideo=True)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册