Expand 'getroster' command to include groupchat subjects

Roster Item Exchange messages now add contacts to roster groups with names based
off the group chats you share with those contacts, to make organizing your
roster less painful.
This commit is contained in:
eta 2021-05-28 16:53:42 +01:00
parent d45cb53e61
commit 4698d41d65
2 changed files with 17 additions and 2 deletions

View file

@ -151,6 +151,15 @@
while (sqlite:step-statement get-stmt)
collect (with-bound-columns (localpart subject) get-stmt (cons localpart subject)))))
(defun get-contact-chat-subjects (uid wa-jid)
"Get a list of chat subjects for each chat the remote contact identifed by WA-JID is in, for the user with ID UID."
(with-prepared-statements
((get-stmt "SELECT DISTINCT user_chats.subject FROM user_chats, user_chat_members WHERE user_chats.id = user_chat_members.chat_id AND user_chat_members.wa_jid = ? AND user_chats.user_id = ?"))
(bind-parameters get-stmt wa-jid uid)
(loop
while (sqlite:step-statement get-stmt)
collect (with-bound-columns (subject) get-stmt subject))))
(defun insert-xmpp-message (xm)
"Inserts XM, a groupchat XMPP-MESSAGE, into the database."
(assert (uiop:string-prefix-p "g" (conversation xm)) () "Tried to insert XMPP message for non-groupchat conversation ~A" (conversation xm))

View file

@ -967,14 +967,20 @@ Returns three values: avatar data (as two values), and a generalized boolean spe
"@"
(component-name comp)))
(ct-name (get-contact-name uid ct-localpart
:no-phone-number t)))
:no-phone-number t))
(groupchat-subjects
(get-contact-chat-subjects uid ct-localpart)))
(when ct-name
(cxml:with-element "item"
(cxml:attribute "action" "add")
(cxml:attribute "jid" ct-jid)
(cxml:attribute "name" ct-name)
(cxml:with-element "group"
(cxml:text "WhatsApp")))))))))))
(cxml:text "WhatsApp"))
(dolist (subj groupchat-subjects)
(cxml:with-element "group"
(cxml:text
(format nil "WA: ~A" subj)))))))))))))
(defun handle-admin-command (comp from body uid)
"Handles an admin command sent to COMP."