aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-07-29 16:44:05 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-07-29 22:31:44 +0200
commitf71af881d287c634941e3bc4b3ce0244479c82bd (patch)
tree9230a799eaa02414f362674a347ae7b7106d1348 /wee_slack.py
parent2b3b969dffcaee7d2dfe23d4bcedf57c685567dc (diff)
downloadwee-slack-f71af881d287c634941e3bc4b3ce0244479c82bd.tar.gz
Set correct id on all the lines of a message
Instead of only updating the last line printed with the id of the message (ts.minor, set in the date_printed field), update all of the lines that is printed for that message. This is necessary for updating all of the lines on changes, instead of only the last. This will be implemented in the next commit. This assumes that the lines after the first in messages always has an empty prefix, and that the first line of a message always has a prefix. This holds for the messages I have seen (single-line, multi-line as well as me-messages and joins/quits). Other approaches I considered was to count the number of newlines in the message and update the same number of lines, or to check the existing date_printed field of the messages and update the ones that had 10 digits or more (since current timestamps has that, and the slack id currently has 6 digits). However, I dropped them in favor of the prefix solution which seems better.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 680ff6b..7fd6313 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2751,10 +2751,17 @@ def modify_print_time(buffer, new_id, time):
struct_hdata_line = w.hdata_get('line')
struct_hdata_line_data = w.hdata_get('line_data')
- # get a pointer to the data in line_pointer via layout of struct_hdata_line
- data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data')
- if data:
- w.hdata_update(struct_hdata_line_data, data, {"date_printed": new_id})
+ prefix = ''
+ while not prefix and line_pointer:
+ # get a pointer to the data in line_pointer via layout of struct_hdata_line
+ data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data')
+ if data:
+ prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix')
+ w.hdata_update(struct_hdata_line_data, data, {"date_printed": new_id})
+ # move backwards one line and repeat, so all the lines of the message are set
+ # exit when you reach a prefix, which means you have reached the
+ # first line of the message, or if you hit the end
+ line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1)
return w.WEECHAT_RC_OK