Comments (8)
So in essence the MessageEvent class gets converted to a shell that contains a Message object and reexports some Message methods?
from chatexchange.
It probably wouldn't even re-export any methods. You'd need to do event.message.reply(foo)
.
Having a distinct, de-duplicated Message object would let you do things like:
def on_event(event, wrapper):
if isinstance(event, events.MessageStarred):
print event.message.owner_name, "has a message starred!"
which would currently be impossible because the user_name associated with the MessageStarred event is the user doing the starring, not the owner of the starred message. This new approach would have that information available as long as we had previously observed.
Similarly, you would be able to easily:
print "in reply to:", event.message.parent.text_content
instead of needing to keep track of the messages to find the one to associate with the parent_id yourself.
from chatexchange.
This would be nice.
We'd need to be able to fetch messages if they're not cached, though -- maybe by fetching the history. (there may be a json endpoint, too).
I'll look into this tomorrow.
-----Original Message-----
From: "Jeremy Banks" [email protected]
Sent: 5/4/2014 11:02 AM
To: "Manishearth/ChatExchange" [email protected]
Cc: "Manish Goregaokar" [email protected]
Subject: Re: [ChatExchange] Message class (#51)
We might also want a message.watch(on_change) method, which can be used to be notified when any properties on a message have changed, in case you need to re-render it in a client, for example.
—
Reply to this email directly or view it on GitHub.
from chatexchange.
I've implemented the basic Message class described above, without any capability to automatically fetch missing data (fields are left as None for now). The Message is just built out of information from Events seen by a wrapper.
We'll need to test different events to find out what the user_id represents for each. If edit events represent the editor, not the owner, then we should use those edit events to update .editor_user_name
and .editor_user_id
properties.
from chatexchange.
r+, if you're waiting for my review, otherwise, carry on :)
from chatexchange.
I was hoping for a review to make sure I wasn't doing anything disagreeable, but I'm not finished yet. :)
I'm adding a simple web-based chat viewer example, which I think will make a good way to show changes to previous Messages, when they're edited or whatever.
from chatexchange.
Keeping in mind your comments on #43...
Basically, I envision something like this:
def init(self): self.gettergroups={"access":False,"info":False,...} self.info() def access(self): # do some GETting # initialize related params @lazy('access','owner') @property def owner(self): "NOP" #The decorator does the magic. #etc etc
I've implemented a pretty simple accessor for us to use when implementing lazy lookup of missing values.
class Message(object):
# ...
content_source = LazyFrom('_scrape_source')
def _scrape_source(self):
self.content_source = self.wrapper.getSomething(
'/mesages/%s?plain=true' % (self.message_id,))
room_id = LazyFrom('_scrape_timeline')
content = LazyFrom('_scrape_timeline')
def _scrape_timeline(self):
# ...
self.content = ...
self.room_id = ...
The update methods just assign to the attributes as normal, the only difference is that when a attribute is missing, we invoke a specified method to populate it. Our Event code can continue setting/updating known attributes on their message instances, as they have been.
Here's the current implementation of LazyFrom:
class LazyFrom(object):
"""
A accessor used when multiple lazy attributes depend on a common
source of data.
"""
def __init__(self, method_name, backing_attr_name):
"""
method_name is the name of the method that will be invoked if
the value is not known. It must asign a value for the attribute
attribute (through this accessor).
"""
self.method_name = method_name
self.values = weakref.WeakKeyDictionary()
def __get__(self, obj, cls):
if obj is None:
raise AttributeError()
if obj not in self.values:
method = getattr(obj, self.method_name)
method()
return self.values[obj]
def __set__(self, obj, value):
self.values[obj] = value
def __delete__(self, obj):
del self.values[obj]
Does this seem like an reasonable approach, @Manishearth?
from chatexchange.
This seems to be a good way of doing it. I find descriptors a bit annoying to work with, but that's a personal preference :)
from chatexchange.
Related Issues (20)
- Entities not parsed
- Error when trying to call `Client.getme` HOT 3
- Upload Python3-compatible version to PyPI HOT 3
- Better documentation HOT 2
- Unable to log in properly HOT 1
- [Support] When running something using this CE engine in PyCharm, "failed to get `usr` cookie from Stack Exchange OpenID" HOT 4
- "Limit concurrent jobs" to 1 in Travis settings for this repo HOT 1
- Update PyPI package to latest version HOT 6
- 500 Internal Server Error HOT 1
- 500 Error when reading messages HOT 1
- SE is removing OpenID HOT 9
- make: *** [run-example] Error 1 HOT 3
- Incorrect epydoc tags in docstrings HOT 2
- Travis CI migration to travis-ci.com from travis-ci.org HOT 2
- Migrate CI testing to GitHub Actions HOT 1
- Did the format of the TOO_FAST_RE message change? HOT 1
- Posting to a frozen room should fail, but doesn't HOT 2
- Logout abandons pending queued messages
- Could we get a new version uploaded to PyPI? HOT 3
- chatexchange.browser.LoginError: failed to get `acct` cookie from Stack Exchange OpenID, check credentials provided for accuracy HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatexchange.