Skip to content
Snippets Groups Projects
Commit e4972cc3 authored by Johann Jacobsohn's avatar Johann Jacobsohn
Browse files

open paper discussion thread in browser

parent b735407c
Branches
No related tags found
No related merge requests found
......@@ -9,7 +9,9 @@ UI:
4. paper (open discussion) (open paper)
"""
import subprocess
from dataclasses import dataclass
from functools import partial
from mattermostdriver import Driver
import urwid
import configargparse
......@@ -21,6 +23,7 @@ CHANNEL = "n5myem9yc7fyzb9am7ym5o41ry"
@dataclass
class PostDTO:
""""Encapsulate Mattermost Posts."""
id: str
message: str
......@@ -38,7 +41,8 @@ class Mattermost:
def retrieve_all_messages(self):
"""Retrieve all messages from mattermost, unfiltered for papers."""
posts = self.mattermost.posts.get_posts_for_channel(CHANNEL)
return [PostDTO(m['message']) for m in posts['posts'].values()]
return [PostDTO(m['id'], m['message'])
for m in posts['posts'].values()]
def filter_incoming(self, posts):
"""Filter messages from mattermost to only papers."""
......@@ -67,10 +71,12 @@ class Papersurfer:
div = urwid.Divider(u'-')
self.mtm = Mattermost(username, password)
papers = [msg.message for msg in self.mtm.retrieve()]
papers = self.mtm.retrieve()
body = []
for paper in papers:
button = urwid.Button(paper)
button = urwid.Button(paper.message)
urwid.connect_signal(button, 'click',
partial(self.handle_paper, paper))
body.append(urwid.AttrMap(button, None, focus_map='reversed'))
self.listcontent = urwid.SimpleFocusListWalker(body)
......@@ -97,6 +103,13 @@ class Papersurfer:
"""Handle exitbutton click and exit."""
raise urwid.ExitMainLoop()
def handle_paper(self, post, _):
self.open_post(post)
def open_post(self, post):
link = f"https://mattermost.cen.uni-hamburg.de/ifg/pl/{post.id}"
subprocess.call(["xdg-open", link])
def parse_args():
"""Parse command line arguments and config file."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment