mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 10:19:16 +02:00
finalize new internal Messaging API, now not using wrappers anymore
This commit is contained in:
parent
aaf37821c4
commit
b709adddcf
5 changed files with 20 additions and 16 deletions
|
@ -8,6 +8,10 @@
|
||||||
as it's pretty clear Chat.send_X is going to send a message
|
as it's pretty clear Chat.send_X is going to send a message
|
||||||
to the chat)
|
to the chat)
|
||||||
|
|
||||||
|
- new Account.create_message() to create new messages
|
||||||
|
that are not in the database (yet)
|
||||||
|
|
||||||
|
|
||||||
0.6
|
0.6
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,7 @@ class Account(object):
|
||||||
|
|
||||||
def get_message_by_id(self, msg_id):
|
def get_message_by_id(self, msg_id):
|
||||||
""" return Message instance. """
|
""" return Message instance. """
|
||||||
return Message.from_id(self._dc_context, msg_id)
|
return Message.from_db(self._dc_context, msg_id)
|
||||||
|
|
||||||
def mark_seen_messages(self, messages):
|
def mark_seen_messages(self, messages):
|
||||||
""" mark the given set of messages as seen.
|
""" mark the given set of messages as seen.
|
||||||
|
|
|
@ -118,7 +118,7 @@ class Chat(object):
|
||||||
msg_id = lib.dc_send_text_msg(self._dc_context, self.id, msg)
|
msg_id = lib.dc_send_text_msg(self._dc_context, self.id, msg)
|
||||||
if msg_id == 0:
|
if msg_id == 0:
|
||||||
raise ValueError("message could not be send, does chat exist?")
|
raise ValueError("message could not be send, does chat exist?")
|
||||||
return Message.from_id(self._dc_context, msg_id)
|
return Message.from_db(self._dc_context, msg_id)
|
||||||
|
|
||||||
def send_file(self, path, mime_type="application/octet-stream"):
|
def send_file(self, path, mime_type="application/octet-stream"):
|
||||||
""" send a file and return the resulting Message instance.
|
""" send a file and return the resulting Message instance.
|
||||||
|
@ -133,7 +133,7 @@ class Chat(object):
|
||||||
msg_id = lib.dc_send_file_msg(self._dc_context, self.id, path, mtype)
|
msg_id = lib.dc_send_file_msg(self._dc_context, self.id, path, mtype)
|
||||||
if msg_id == 0:
|
if msg_id == 0:
|
||||||
raise ValueError("message could not be send, does chat exist?")
|
raise ValueError("message could not be send, does chat exist?")
|
||||||
return Message.from_id(self._dc_context, msg_id)
|
return Message.from_db(self._dc_context, msg_id)
|
||||||
|
|
||||||
def send_image(self, path):
|
def send_image(self, path):
|
||||||
""" send an image message and return the resulting Message instance.
|
""" send an image message and return the resulting Message instance.
|
||||||
|
@ -144,11 +144,10 @@ class Chat(object):
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise ValueError("path does not exist: {!r}".format(path))
|
raise ValueError("path does not exist: {!r}".format(path))
|
||||||
path = as_dc_charpointer(path)
|
msg = Message.new(self._dc_context, "image")
|
||||||
msg_id = lib.dc_send_image_msg(self._dc_context, self.id, path, ffi.NULL, 0, 0)
|
msg.set_file(path)
|
||||||
if msg_id == 0:
|
msg_id = lib.dc_send_msg(self._dc_context, self.id, msg._dc_msg)
|
||||||
raise ValueError("chat does not exist")
|
return Message.from_db(self._dc_context, msg_id)
|
||||||
return Message.from_id(self._dc_context, msg_id)
|
|
||||||
|
|
||||||
def get_messages(self):
|
def get_messages(self):
|
||||||
""" return list of messages in this chat.
|
""" return list of messages in this chat.
|
||||||
|
@ -159,7 +158,7 @@ class Chat(object):
|
||||||
lib.dc_get_chat_msgs(self._dc_context, self.id, 0, 0),
|
lib.dc_get_chat_msgs(self._dc_context, self.id, 0, 0),
|
||||||
lib.dc_array_unref
|
lib.dc_array_unref
|
||||||
)
|
)
|
||||||
return list(iter_array(dc_array, lambda x: Message.from_id(self._dc_context, x)))
|
return list(iter_array(dc_array, lambda x: Message.from_db(self._dc_context, x)))
|
||||||
|
|
||||||
def count_fresh_messages(self):
|
def count_fresh_messages(self):
|
||||||
""" return number of fresh messages in this chat.
|
""" return number of fresh messages in this chat.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
""" chatting related objects: Contact, Chat, Message. """
|
""" chatting related objects: Contact, Chat, Message. """
|
||||||
|
|
||||||
|
import os
|
||||||
from .cutil import from_dc_charpointer, as_dc_charpointer
|
from .cutil import from_dc_charpointer, as_dc_charpointer
|
||||||
from .capi import lib, ffi
|
from .capi import lib, ffi
|
||||||
from .types import property_with_doc
|
from .types import property_with_doc
|
||||||
|
@ -29,7 +30,7 @@ class Message(object):
|
||||||
return self._dc_msg_volatile
|
return self._dc_msg_volatile
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_id(cls, _dc_context, id):
|
def from_db(cls, _dc_context, id):
|
||||||
assert id > 0
|
assert id > 0
|
||||||
return cls(_dc_context, id)
|
return cls(_dc_context, id)
|
||||||
|
|
||||||
|
@ -37,17 +38,14 @@ class Message(object):
|
||||||
def new(cls, dc_context, view_type):
|
def new(cls, dc_context, view_type):
|
||||||
""" create a non-persistent method. """
|
""" create a non-persistent method. """
|
||||||
msg = cls(dc_context, 0)
|
msg = cls(dc_context, 0)
|
||||||
|
view_type_code = MessageType.get_typecode(view_type)
|
||||||
msg._dc_msg_volatile = ffi.gc(
|
msg._dc_msg_volatile = ffi.gc(
|
||||||
lib.dc_msg_new(dc_context),
|
lib.dc_msg_new(dc_context),
|
||||||
lib.dc_msg_unref
|
lib.dc_msg_unref
|
||||||
)
|
)
|
||||||
lib.dc_msg_set_type(msg._dc_msg, MessageType.get_typecode(view_type))
|
lib.dc_msg_set_type(msg._dc_msg, view_type_code)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def is_persistent(self):
|
|
||||||
""" return True if the message is persistent in the database. """
|
|
||||||
return self.id > 0
|
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
""" get the message in/out state.
|
""" get the message in/out state.
|
||||||
|
|
||||||
|
@ -71,6 +69,9 @@ class Message(object):
|
||||||
|
|
||||||
def set_file(self, path, mime_type=None):
|
def set_file(self, path, mime_type=None):
|
||||||
"""set file for this message. """
|
"""set file for this message. """
|
||||||
|
mtype = ffi.NULL if mime_type is None else mime_type
|
||||||
|
assert os.path.exists(path)
|
||||||
|
lib.dc_msg_set_file(self._dc_msg, as_dc_charpointer(path), mtype)
|
||||||
|
|
||||||
@property_with_doc
|
@property_with_doc
|
||||||
def basename(self):
|
def basename(self):
|
||||||
|
|
|
@ -99,7 +99,7 @@ class TestOfflineAccount:
|
||||||
assert message._dc_msg is message._dc_msg
|
assert message._dc_msg is message._dc_msg
|
||||||
message.set_text("hello")
|
message.set_text("hello")
|
||||||
assert message.text == "hello"
|
assert message.text == "hello"
|
||||||
assert not message.is_persistent()
|
assert message.id == 0
|
||||||
|
|
||||||
def test_message(self, acfactory):
|
def test_message(self, acfactory):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue