mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +03:00
Merge pull request #2332 from deltachat/adb-issue-2327
Add sticker viewtype
This commit is contained in:
@@ -46,9 +46,13 @@ class Message(object):
|
|||||||
def new_empty(cls, account, view_type):
|
def new_empty(cls, account, view_type):
|
||||||
""" create a non-persistent message.
|
""" create a non-persistent message.
|
||||||
|
|
||||||
:param: view_type is "text", "audio", "video", "file"
|
:param: view_type is the message type code or one of the strings:
|
||||||
|
"text", "audio", "video", "file", "sticker"
|
||||||
"""
|
"""
|
||||||
view_type_code = get_viewtype_code_from_name(view_type)
|
if isinstance(view_type, int):
|
||||||
|
view_type_code = view_type
|
||||||
|
else:
|
||||||
|
view_type_code = get_viewtype_code_from_name(view_type)
|
||||||
return Message(account, ffi.gc(
|
return Message(account, ffi.gc(
|
||||||
lib.dc_msg_new(account._dc_context, view_type_code),
|
lib.dc_msg_new(account._dc_context, view_type_code),
|
||||||
lib.dc_msg_unref
|
lib.dc_msg_unref
|
||||||
@@ -339,6 +343,10 @@ class Message(object):
|
|||||||
""" return True if it's a gif message. """
|
""" return True if it's a gif message. """
|
||||||
return self._view_type == const.DC_MSG_GIF
|
return self._view_type == const.DC_MSG_GIF
|
||||||
|
|
||||||
|
def is_sticker(self):
|
||||||
|
""" return True if it's a sticker message. """
|
||||||
|
return self._view_type == const.DC_MSG_STICKER
|
||||||
|
|
||||||
def is_audio(self):
|
def is_audio(self):
|
||||||
""" return True if it's an audio message. """
|
""" return True if it's an audio message. """
|
||||||
return self._view_type == const.DC_MSG_AUDIO
|
return self._view_type == const.DC_MSG_AUDIO
|
||||||
@@ -359,21 +367,22 @@ class Message(object):
|
|||||||
# some code for handling DC_MSG_* view types
|
# some code for handling DC_MSG_* view types
|
||||||
|
|
||||||
_view_type_mapping = {
|
_view_type_mapping = {
|
||||||
const.DC_MSG_TEXT: 'text',
|
'text': const.DC_MSG_TEXT,
|
||||||
const.DC_MSG_IMAGE: 'image',
|
'image': const.DC_MSG_IMAGE,
|
||||||
const.DC_MSG_GIF: 'gif',
|
'gif': const.DC_MSG_GIF,
|
||||||
const.DC_MSG_AUDIO: 'audio',
|
'audio': const.DC_MSG_AUDIO,
|
||||||
const.DC_MSG_VIDEO: 'video',
|
'video': const.DC_MSG_VIDEO,
|
||||||
const.DC_MSG_FILE: 'file'
|
'file': const.DC_MSG_FILE,
|
||||||
|
'sticker': const.DC_MSG_STICKER,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_viewtype_code_from_name(view_type_name):
|
def get_viewtype_code_from_name(view_type_name):
|
||||||
for code, value in _view_type_mapping.items():
|
code = _view_type_mapping.get(view_type_name)
|
||||||
if value == view_type_name:
|
if code is not None:
|
||||||
return code
|
return code
|
||||||
raise ValueError("message typecode not found for {!r}, "
|
raise ValueError("message typecode not found for {!r}, "
|
||||||
"available {!r}".format(view_type_name, list(_view_type_mapping.values())))
|
"available {!r}".format(view_type_name, list(_view_type_mapping.keys())))
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user