1
0
Fork 0

feat: set group name and topic

Implements: https://todo.sr.ht/~nicoco/slidge-whatsapp/24
This commit is contained in:
nicoco 2024-02-10 11:24:52 +01:00
parent 6440e97331
commit 69a4e27395
2 changed files with 43 additions and 0 deletions

View File

@ -42,6 +42,8 @@ class MUC(LegacyMUC[str, str, Participant, str]):
_ALL_INFO_FILLED_ON_STARTUP = True
HAS_DESCRIPTION = False
def __init__(self, *a, **kw):
super().__init__(*a, **kw)
self.sent = dict[str, str]()
@ -110,6 +112,19 @@ class MUC(LegacyMUC[str, str, Participant, str]):
self.legacy_id, await get_bytes_temp(data) if data else ""
)
async def on_set_config(
self,
name: Optional[str],
description: Optional[str],
):
# there are no group descriptions in WA, but topics=subjects
if self.name != name:
self.session.whatsapp.SetGroupName(self.legacy_id, name)
async def on_set_subject(self, subject: str):
if self.subject != subject:
self.session.whatsapp.SetGroupTopic(self.legacy_id, subject)
class Bookmarks(LegacyBookmarks[str, MUC]):
session: "Session"

View File

@ -493,6 +493,34 @@ func (s *Session) SetAvatar(resourceID, avatarPath string) (string, error) {
}
}
// SetGroupName updates the name of a WhatsApp group
func (s *Session) SetGroupName(resourceID, name string) error {
if s.client == nil || s.client.Store.ID == nil {
return fmt.Errorf("Cannot set group name for unauthenticated session")
}
jid, err := types.ParseJID(resourceID)
if err != nil {
return fmt.Errorf("Could not parse JID for group name change: %s", err)
}
return s.client.SetGroupName(jid, name)
}
// SetGroupTopic updates the topic of a WhatsApp group
func (s *Session) SetGroupTopic(resourceID, topic string) error {
if s.client == nil || s.client.Store.ID == nil {
return fmt.Errorf("Cannot set group topic for unauthenticated session")
}
jid, err := types.ParseJID(resourceID)
if err != nil {
return fmt.Errorf("Could not parse JID for group topic change: %s", err)
}
return s.client.SetGroupTopic(jid, "", "", topic)
}
// FindContact attempts to check for a registered contact on WhatsApp corresponding to the given
// phone number, returning a concrete instance if found; typically, only the contact JID is set. No
// error is returned if no contact was found, but any unexpected errors will otherwise be returned