Skip to content

Commit

Permalink
Fix isAt, Self bugs in 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Mar 29, 2017
1 parent 04bcc11 commit 61b19d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions itchat/components/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
4 changes: 2 additions & 2 deletions itchat/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion itchat/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, platform

VERSION = '1.3.3'
VERSION = '1.3.4'
BASE_URL = 'https://login.weixin.qq.com'
OS = platform.system() #Windows, Linux, Darwin
DIR = os.getcwd()
Expand Down
19 changes: 16 additions & 3 deletions itchat/storage/messagequeue.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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=None):
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()])
Expand Down

0 comments on commit 61b19d7

Please sign in to comment.