1
0
Fork 0

feat: moderate messages from XMPP

Includes a fix for the role of admin and
owner to "moderator", or else gajim wouldn't
display the option to actually moderate a
message.

Implements: https://todo.sr.ht/~nicoco/slidge-whatsapp/21
This commit is contained in:
nicoco 2024-02-10 14:19:02 +01:00
parent 69a4e27395
commit 0bf051a7d6
3 changed files with 32 additions and 1 deletions

View File

@ -90,8 +90,10 @@ class MUC(LegacyMUC[str, str, Participant, str]):
participant.affiliation = "member"
if data.Affiliation == whatsapp.GroupAffiliationAdmin:
participant.affiliation = "admin"
participant.role = "moderator"
elif data.Affiliation == whatsapp.GroupAffiliationOwner:
participant.affiliation = "owner"
participant.role = "moderator"
def replace_mentions(self, t: str):
return replace_mentions(

View File

@ -220,7 +220,18 @@ func (s *Session) SendMessage(message Message) error {
payload = s.client.BuildEdit(s.device.JID().ToNonAD(), message.ID, s.getMessagePayload(message))
case MessageRevoke:
// Don't send message, but revoke existing message by ID.
payload = s.client.BuildRevoke(s.device.JID().ToNonAD(), types.EmptyJID, message.ID)
var originJID types.JID
if message.OriginJID == "" {
// A message retraction by the person who sent it
originJID = types.EmptyJID
} else {
// A message moderation
originJID, err = types.ParseJID(message.OriginJID)
if err != nil {
return fmt.Errorf("Could not parse sender JID for message: %s", err)
}
}
payload = s.client.BuildRevoke(jid, originJID, message.ID)
case MessageReaction:
// Send message as emoji reaction to a given message.
payload = &proto.Message{

View File

@ -387,6 +387,24 @@ class Session(BaseSession[str, Recipient]):
)
self.whatsapp.SendMessage(message)
async def on_moderate(
self,
muc: MUC, # type:ignore
legacy_msg_id: str,
reason: Optional[str],
):
message = whatsapp.Message(
Kind=whatsapp.MessageRevoke,
ID=legacy_msg_id,
JID=muc.legacy_id,
OriginJID=muc.get_message_sender(legacy_msg_id),
)
self.whatsapp.SendMessage(message)
# Apparently, no revoke event is received by whatsmeow after sending
# the revoke message, so we need to "echo" it here.
part = await muc.get_user_participant()
part.moderate(legacy_msg_id)
async def on_correct(
self,
c: Recipient,