Adapt messages to changes in message
This commit is contained in:
parent
900bbaf86a
commit
6a0f4dc265
2 changed files with 18 additions and 18 deletions
|
|
@ -35,7 +35,7 @@ class Message():
|
||||||
Creates and returns a message created from the data.
|
Creates and returns a message created from the data.
|
||||||
NOTE: This also creates a session object using the data in "sender".
|
NOTE: This also creates a session object using the data in "sender".
|
||||||
|
|
||||||
data - A euphoria message: http://api.euphoria.io/#message
|
data - a euphoria message: http://api.euphoria.io/#message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sender = session.Session.from_data(data["sender"])
|
sender = session.Session.from_data(data["sender"])
|
||||||
|
|
@ -44,7 +44,7 @@ class Message():
|
||||||
deleted = data["deleted"] if "deleted" in data else None
|
deleted = data["deleted"] if "deleted" in data else None
|
||||||
truncated = data["truncated"] if "truncated" in data else None
|
truncated = data["truncated"] if "truncated" in data else None
|
||||||
|
|
||||||
return Message(
|
return self(
|
||||||
data["id"],
|
data["id"],
|
||||||
data["time"],
|
data["time"],
|
||||||
sender,
|
sender,
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ class Messages():
|
||||||
self.by_id = {}
|
self.by_id = {}
|
||||||
self.by_parent = {}
|
self.by_parent = {}
|
||||||
|
|
||||||
def add_raw(self, raw_message):
|
def add_from_data(self, data):
|
||||||
"""
|
"""
|
||||||
add_raw(raw_message) -> None
|
add_from_data(data) -> None
|
||||||
|
|
||||||
Create a message from raw data and add it.
|
Create a message from "raw" data and add it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mes = message.Message(raw_message)
|
mes = message.Message(data)
|
||||||
|
|
||||||
self.add(mes)
|
self.add(mes)
|
||||||
|
|
||||||
|
|
@ -27,14 +27,14 @@ class Messages():
|
||||||
Add a message to the structure.
|
Add a message to the structure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.remove(mes.id())
|
self.remove(mes.id)
|
||||||
|
|
||||||
self.by_id[mes.id()] = mes
|
self.by_id[mes.id] = mes
|
||||||
|
|
||||||
if mes.parent():
|
if mes.parent:
|
||||||
if not mes.parent() in self.by_parent:
|
if not mes.parent in self.by_parent:
|
||||||
self.by_parent[parent] = []
|
self.by_parent[mes.parent] = []
|
||||||
self.by_parent[mes.parent()].append(mes)
|
self.by_parent[mes.parent].append(mes)
|
||||||
|
|
||||||
def remove(self, mes):
|
def remove(self, mes):
|
||||||
"""
|
"""
|
||||||
|
|
@ -43,11 +43,11 @@ class Messages():
|
||||||
Remove a message from the structure.
|
Remove a message from the structure.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if mes.id() in self.by_id:
|
if mes.id in self.by_id:
|
||||||
self.by_id.pop(mes.id())
|
self.by_id.pop(mes.id)
|
||||||
|
|
||||||
if mes.parent() and mes in self.get_children(mes.parent()):
|
if mes.parent and mes in self.get_children(mes.parent):
|
||||||
self.by_parent[mes.parent()].remove(mes)
|
self.by_parent[mes.parent].remove(mes)
|
||||||
|
|
||||||
def get(self, mid):
|
def get(self, mid):
|
||||||
"""
|
"""
|
||||||
|
|
@ -67,7 +67,7 @@ class Messages():
|
||||||
Returns None if no parent was found.
|
Returns None if no parent was found.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.get(mes.parent())
|
return self.get(mes.parent)
|
||||||
|
|
||||||
def get_children(self, mes):
|
def get_children(self, mes):
|
||||||
"""
|
"""
|
||||||
|
|
@ -76,4 +76,4 @@ class Messages():
|
||||||
Returns a list of children of the given message.
|
Returns a list of children of the given message.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.by_parent[mes.id()]
|
return self.by_parent[mes.id]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue