diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-04-27 00:51:53 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-30 21:13:20 +0200 |
commit | 216b36702a18e4b165762447a138f8adfd0ca010 (patch) | |
tree | 73e3eb34c4c7ecf444ba9494074ff4bf2c1985db /wee_slack.py | |
parent | 93d6ba7de163271e7a39b07643b41d1bcc7c25f8 (diff) | |
download | wee-slack-216b36702a18e4b165762447a138f8adfd0ca010.tar.gz |
Set hashed_messages[message.hash] if not present in hash_message
A channel and a thread channel in that channel has the same message
instances, but different hashed_messages dictionaries. Therefore,
message.hash may be set, without it being present in hashed_messages.
Insert it into hashed_messages in hash_message if that is the case.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/wee_slack.py b/wee_slack.py index 66e2e4b..90540cf 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1634,38 +1634,41 @@ class SlackChannelCommon(object): def calc_hash(ts): return sha1_hex(str(ts)) - if ts in self.messages and not self.messages[ts].hash: - message = self.messages[ts] - tshash = calc_hash(message.ts) - hl = 3 - - for i in range(hl, len(tshash) + 1): - shorthash = tshash[:i] - if self.hashed_messages.get(shorthash) == ts: - message.hash = shorthash - return shorthash - - shorthash = tshash[:hl] - while any(x.startswith(shorthash) for x in self.hashed_messages): - hl += 1 - shorthash = tshash[:hl] + message = self.messages.get(ts) + if message is not None: + if not message.hash: + tshash = calc_hash(message.ts) + hl = 3 + + for i in range(hl, len(tshash) + 1): + shorthash = tshash[:i] + if self.hashed_messages.get(shorthash) == ts: + message.hash = shorthash + return shorthash - if shorthash[:-1] in self.hashed_messages: - col_ts = self.hashed_messages.pop(shorthash[:-1]) - col_new_hash = calc_hash(col_ts)[:hl] - self.hashed_messages[col_new_hash] = col_ts - col_msg = self.messages.get(col_ts) - if col_msg: - col_msg.hash = col_new_hash - self.change_message(str(col_msg.ts)) - if col_msg.thread_channel: - col_msg.thread_channel.rename() - - self.hashed_messages[shorthash] = message.ts - message.hash = shorthash - return shorthash - elif ts in self.messages: - return self.messages[ts].hash + shorthash = tshash[:hl] + while any(x.startswith(shorthash) for x in self.hashed_messages): + hl += 1 + shorthash = tshash[:hl] + + if shorthash[:-1] in self.hashed_messages: + col_ts = self.hashed_messages.pop(shorthash[:-1]) + col_new_hash = calc_hash(col_ts)[:hl] + self.hashed_messages[col_new_hash] = col_ts + col_msg = self.messages.get(col_ts) + if col_msg: + col_msg.hash = col_new_hash + self.change_message(str(col_msg.ts)) + if col_msg.thread_channel: + col_msg.thread_channel.rename() + + message.hash = shorthash + self.hashed_messages[message.hash] = message.ts + + elif message.hash not in self.hashed_messages: + self.hashed_messages[message.hash] = message.ts + + return message.hash def mark_read(self, ts=None, update_remote=True, force=False, post_data={}): if self.new_messages or force: |