def ego_feed(self):
return EgoFeed(self)
+ def thread_feed(self, id, full):
+ return ThreadFeed(self, id, full)
+
def cache_status(self, status):
self.status_cache[status['id']] = status
super().__init__(client, "notifications", {"types[]":['mention']},
get=lambda item: item['status'])
+class ThreadFeed(Feed):
+ def __init__(self, client, post_id, full):
+ super().__init__(client)
+ self.post_id = post_id
+ self.want_full = full
+
+ def start(self):
+ status = cstatus = self.client.get_status_by_id(self.post_id)
+ context = self.client.get(f"statuses/{self.post_id}/context")
+ if self.want_full and len(context["ancestors"]) > 0:
+ cstatus = context["ancestors"][0]
+ cid = cstatus["id"]
+ context = self.client.get(f"statuses/{cid}/context")
+ self.data = context["ancestors"] + [cstatus] + context["descendants"]
+ self.is_full = len(context["ancestors"]) == 0
+
+ def min_index(self):
+ return 0
+ def max_index(self):
+ return len(self.data)
+ def __getitem__(self, n):
+ return self.data[n]
+
+ def extend_past(self):
+ return False
+ def extend_future(self):
+ return False
+
class EgoFeed(IncrementalServerFeed):
def __init__(self, client):
super().__init__(client, "notifications", {
self.favourite_mode()
elif ch in {ctrl('b')}:
self.boost_mode()
+ elif ch in {'t', 'T'}:
+ self.thread_mode()
elif self.mode == 'select':
if ch in {'q', 'Q'}:
self.mode = 'normal'
elif (self.select_type == 'boost' and
ch in {'d', 'D'}):
self.boost_complete(-1)
+ elif (self.select_type == 'thread' and
+ ch in {' '}):
+ self.thread_complete(False)
+ elif (self.select_type == 'thread' and
+ ch in {'f', 'F'}):
+ self.thread_complete(True)
def unprime(self):
pass # not supported
pass # not supported
def boost_mode(self):
pass # not supported
+ def thread_mode(self):
+ pass # not supported
class ObjectFile(File):
def __init__(self, cc, constructor, feed, title):
sl.keys.append(('SPACE', 'Boost'))
if self.statuses[self.select_target].boosted:
sl.keys.append(('D', 'Unboost'))
+ elif self.select_type == 'thread':
+ sl.keys.append(('SPACE', 'Show Thread Context'))
+ sl.keys.append(('F', 'Show Full Thread'))
sl.keys.append(('-', None))
sl.keys.append(('+', None))
sl.keys.append(('Q', 'Quit'))
self.mode = 'select'
self.select_type = 'boost'
self.select_target = self.index_by_line[self.linepos-1]
+ def thread_mode(self):
+ if self.items_are_statuses:
+ self.mode = 'select'
+ self.select_type = 'thread'
+ self.select_target = self.index_by_line[self.linepos-1]
def prev_select_target(self):
self.select_target = max(self.minpos, self.select_target-1)
def next_select_target(self):
data = self.cc.post(f"statuses/{reply_id}/{verb}")
target.update_fave_boost(data)
+ def thread_complete(self, full):
+ self.mode = 'normal'
+ target = self.statuses[self.select_target]
+ reply_id = target.get_reply_id()
+ feed = self.cc.thread_feed(reply_id, full)
+ feed.start()
+ if feed.is_full:
+ title = "Full thread of post " + reply_id
+ else:
+ title = "Thread context of post " + reply_id
+ self.push_to(StatusFile(
+ self.cc, feed, text.ColouredString(title, "H")))
+
def move_to(self, pos):
old_linepos = self.linepos
self.linepos = pos