diff --git a/itchat/components/contact.py b/itchat/components/contact.py index 08b8e51b..3026ba5c 100644 --- a/itchat/components/contact.py +++ b/itchat/components/contact.py @@ -132,8 +132,9 @@ def update_local_chatrooms(core, l): else: oldMemberList.append(member) else: - oldChatroom = templates.wrap_user_dict(chatroom) - core.chatroomList.append(oldChatroom) + core.chatroomList.append(chatroom) + oldChatroom = utils.search_dict_list( + core.chatroomList, 'UserName', chatroom['UserName']) # delete useless members if len(chatroom['MemberList']) != len(oldChatroom['MemberList']) and \ chatroom['MemberList']: diff --git a/itchat/components/messages.py b/itchat/components/messages.py index 7c60e06c..8f00bab1 100644 --- a/itchat/components/messages.py +++ b/itchat/components/messages.py @@ -246,8 +246,8 @@ def produce_group_chat(core, msg): msg['ActualNickName'] = '' msg['IsAt'] = False else: - msg['ActualNickName'] = member['DisplayName'] or member['NickName'] - atFlag = '@' + chatroom['Self'].get('DisplayName', core.storageClass.nickName) + msg['ActualNickName'] = member.get('DisplayName', '') or member['NickName'] + atFlag = '@' + (chatroom['Self'].get('DisplayName', '') or core.storageClass.nickName) msg['IsAt'] = ( (atFlag + (u'\u2005' if u'\u2005' in msg['Content'] else ' ')) in msg['Content'] or msg['Content'].endswith(atFlag)) diff --git a/itchat/storage/messagequeue.py b/itchat/storage/messagequeue.py index c1f6ae71..fcb89912 100644 --- a/itchat/storage/messagequeue.py +++ b/itchat/storage/messagequeue.py @@ -1,12 +1,14 @@ +import logging + try: import Queue as queue except ImportError: import queue +logger = logging.getLogger('itchat') + class Queue(queue.Queue): def put(self, message): - if 'IsAt' in message: - message['isAt'] = message['IsAt'] queue.Queue.put(self, Message(message)) class Message(dict): @@ -17,7 +19,18 @@ def download(self, fileName): return b'' def __getattr__(self, value): value = value[0].upper() + value[1:] - return self.get(value, '') + return self[value] + def __getitem__(self, value): + if value in ('isAdmin', 'isAt'): + v = value[0].upper() + value[1:] # ''[1:] == '' + logger.debug('%s is expired in 1.3.0, use %s instead.' % (value, v)) + value = v + return super(Message, self).__getitem__(value) + def get(self, v, d): + try: + return self[v] + except KeyError: + return d def __str__(self): return '{%s}' % ', '.join( ['%s: %s' % (repr(k),repr(v)) for k,v in self.items()])