diff --git a/db.lisp b/db.lisp index 9fc5e38..0ed319f 100644 --- a/db.lisp +++ b/db.lisp @@ -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)) diff --git a/stuff.lisp b/stuff.lisp index 4c21f06..2f3b5eb 100644 --- a/stuff.lisp +++ b/stuff.lisp @@ -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."