Commit 223386b8 authored by valtron's avatar valtron

implement is_favorite

parent 32927891
......@@ -162,14 +162,17 @@ class Backend:
ctc.groups.discard(group_id)
self._mark_modified(user)
def me_group_edit(self, sess, group_id, new_name):
def me_group_edit(self, sess, group_id, new_name, *, is_favorite = None):
user = sess.user
g = user.detail.groups.get(group_id)
if g is None:
raise error.GroupDoesNotExist()
if len(name) > MAX_GROUP_NAME_LENGTH:
raise error.GroupNameTooLong()
g.name = name
if name is not None:
if len(name) > MAX_GROUP_NAME_LENGTH:
raise error.GroupNameTooLong()
g.name = name
if is_favorite is not None:
g.is_favorite = is_favorite
self._mark_modified(user)
def me_group_contact_add(self, sess, group_id, contact_uuid):
......@@ -222,15 +225,13 @@ class Backend:
if sess_added == sess: continue
sess_added.send_event(event.AddedToListEvent(Lst.RL, user_adder))
def me_contact_edit(self, sess, contact_uuid, *, is_messenger_user = None, is_favorite = None):
def me_contact_edit(self, sess, contact_uuid, *, is_messenger_user = None):
user = sess.user
ctc = user.detail.contacts.get(contact_uuid)
if ctc is None:
raise error.ContactDoesNotExist()
if is_messenger_user is not None:
ctc.is_messenger_user = is_messenger_user
if is_favorite is not None:
ctc.is_favorite = is_favorite
self._mark_modified(user)
def me_contact_remove(self, sess, contact_uuid, lst):
......
......@@ -11,14 +11,13 @@ class User:
self.date_created = date_created
class Contact:
def __init__(self, user, groups, lists, status, *, is_messenger_user = None, is_favorite = None):
def __init__(self, user, groups, lists, status, *, is_messenger_user = None):
self.head = user
self.groups = groups
self.lists = lists
# `status`: status as known by the contact
self.status = status
self.is_messenger_user = _default_if_none(is_messenger_user, True)
self.is_favorite = _default_if_none(is_favorite, False)
def compute_visible_status(self, to_user):
# Set Contact.status based on BLP and Contact.lists
......@@ -32,10 +31,6 @@ class Contact:
self.status.message = true_status.message
self.status.media = true_status.media
def _default_if_none(x, default):
if x is None: return default
return x
def _is_blocking(blocker, blockee):
detail = blocker.detail
contact = detail.contacts.get(blockee.uuid)
......@@ -64,9 +59,14 @@ class UserDetail:
self.contacts = {}
class Group:
def __init__(self, id, name):
def __init__(self, id, name, *, is_favorite = None):
self.id = id
self.name = name
self.is_favorite = _default_if_none(is_favorite, False)
def _default_if_none(x, default):
if x is None: return default
return x
class Substatus(Enum):
FLN = object()
......
......@@ -70,7 +70,6 @@ class UserService:
ctc = Contact(
ctc_head, set(c['groups']), c['lists'], status,
is_messenger_user = c.get('is_messenger_user'),
is_favorite = c.get('is_favorite'),
)
detail.contacts[ctc.head.uuid] = ctc
return detail
......@@ -82,11 +81,13 @@ class UserService:
dbuser.name = user.status.name
dbuser.message = user.status.message
dbuser.settings = detail.settings
dbuser.groups = [{ 'id': g.id, 'name': g.name } for g in detail.groups.values()]
dbuser.groups = [{
'id': g.id, 'name': g.name,
'is_favorite': g.is_favorite,
} for g in detail.groups.values()]
dbuser.contacts = [{
'uuid': c.head.uuid, 'name': c.status.name, 'message': c.status.message,
'lists': c.lists, 'groups': list(c.groups),
'is_messenger_user': c.is_messenger_user,
'is_favorite': c.is_favorite,
} for c in detail.contacts.values()]
sess.add(dbuser)
......@@ -23,6 +23,7 @@ def create_app(backend):
'date_format': _date_format,
'cid_format': _cid_format,
'bool_to_str': _bool_to_str,
'contact_is_favorite': _contact_is_favorite,
})
# MSN >= 5
......@@ -196,7 +197,6 @@ async def handle_abservice(req):
if action_str == 'ABContactUpdate':
contact_uuid = _find_element(action, 'contactId')
is_messenger_user = _find_element(action, 'isMessengerUser')
# TODO: isFavorite is probably passed here in later WLM
backend.me_contact_edit(ns_sess, contact_uuid, is_messenger_user = is_messenger_user)
return render(req, 'abservice/ABContactUpdateResponse.xml', {
'cachekey': cachekey,
......@@ -213,7 +213,8 @@ async def handle_abservice(req):
if action_str == 'ABGroupUpdate':
group_id = str(_find_element(action, 'groupId'))
name = _find_element(action, 'name')
backend.me_group_edit(ns_sess, group_id, name)
is_favorite = _find_element(action, 'IsFavorite')
backend.me_group_edit(ns_sess, group_id, name, *, is_favorite = is_favorite)
return render(req, 'abservice/ABGroupUpdateResponse.xml', {
'cachekey': cachekey,
'host': settings.LOGIN_HOST,
......@@ -543,6 +544,11 @@ def _cid_format(uuid, *, decimal = False):
def _bool_to_str(b):
return 'true' if b else 'false'
def _contact_is_favorite(ctc):
for group in ctc.groups.values():
if group.is_favorite: return True
return False
async def handle_usertile(req, small=False):
uuid = req.match_info['uuid']
storage_path = _get_storage_path(uuid)
......
......@@ -26,7 +26,7 @@
<name>{{ group.name }}</name>
<IsNotMobileVisible>false</IsNotMobileVisible>
<IsPrivate>false</IsPrivate>
<IsFavorite>false</IsFavorite>
<IsFavorite>{{ bool_to_str(group.is_favorite) }}</IsFavorite>
</groupInfo>
<propertiesChanged />
<fDeleted>false</fDeleted>
......@@ -55,7 +55,7 @@
<IsNotMobileVisible>false</IsNotMobileVisible>
<isMobileIMEnabled>false</isMobileIMEnabled>
<isMessengerUser>{{ bool_to_str(contact.is_messenger_user) }}</isMessengerUser>
<isFavorite>{{ bool_to_str(contact.is_favorite) }}</isFavorite>
<isFavorite>{{ contact_is_favorite(contact) }}</isFavorite>
<isSmtp>false</isSmtp>
<hasSpace>false</hasSpace>
<spotWatchState>NoDevice</spotWatchState>
......
......@@ -26,7 +26,7 @@
<name>{{ group.name }}</name>
<IsNotMobileVisible>false</IsNotMobileVisible>
<IsPrivate>false</IsPrivate>
<IsFavorite>false</IsFavorite>
<IsFavorite>{{ bool_to_str(group.is_favorite) }}</IsFavorite>
</groupInfo>
<propertiesChanged />
<fDeleted>false</fDeleted>
......@@ -55,7 +55,7 @@
<IsNotMobileVisible>false</IsNotMobileVisible>
<isMobileIMEnabled>false</isMobileIMEnabled>
<isMessengerUser>{{ bool_to_str(contact.is_messenger_user) }}</isMessengerUser>
<isFavorite>{{ bool_to_str(contact.is_favorite) }}</isFavorite>
<isFavorite>{{ contact_is_favorite(contact) }}</isFavorite>
<isSmtp>false</isSmtp>
<hasSpace>false</hasSpace>
<spotWatchState>NoDevice</spotWatchState>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment