slidge-whatsapp 0.2.7__cp311-cp311-manylinux_2_36_x86_64.whl → 0.3.0__cp311-cp311-manylinux_2_36_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of slidge-whatsapp might be problematic. Click here for more details.
- slidge_whatsapp/contact.py +15 -3
- slidge_whatsapp/event.go +144 -48
- slidge_whatsapp/gateway.go +7 -63
- slidge_whatsapp/gateway.py +2 -3
- slidge_whatsapp/generated/_whatsapp.cpython-311-x86_64-linux-gnu.h +173 -156
- slidge_whatsapp/generated/_whatsapp.cpython-311-x86_64-linux-gnu.so +0 -0
- slidge_whatsapp/generated/build.py +132 -118
- slidge_whatsapp/generated/whatsapp.c +1597 -1325
- slidge_whatsapp/generated/whatsapp.go +963 -852
- slidge_whatsapp/generated/whatsapp.py +1165 -1040
- slidge_whatsapp/generated/whatsapp_go.h +173 -156
- slidge_whatsapp/go.mod +18 -15
- slidge_whatsapp/go.sum +38 -26
- slidge_whatsapp/group.py +34 -30
- slidge_whatsapp/media/media.go +1 -1
- slidge_whatsapp/session.go +34 -17
- slidge_whatsapp/session.py +46 -14
- slidge_whatsapp/vendor/github.com/beeper/argo-go/LICENSE +9 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/block/blockreader.go +329 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/block/blockwriter.go +417 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/codec/decoder.go +652 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/codec/encoder.go +985 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/header/header.go +135 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/internal/util/util.go +133 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/label/label.go +384 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/label/wiremarkers.go +37 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/pkg/bitset/bitset.go +197 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/pkg/buf/buf.go +420 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/pkg/varint/varint.go +246 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/wire/wire.go +614 -0
- slidge_whatsapp/vendor/github.com/beeper/argo-go/wirecodec/decode.go +341 -0
- slidge_whatsapp/vendor/github.com/elliotchance/orderedmap/v3/LICENSE +21 -0
- slidge_whatsapp/vendor/github.com/elliotchance/orderedmap/v3/list.go +95 -0
- slidge_whatsapp/vendor/github.com/elliotchance/orderedmap/v3/orderedmap.go +187 -0
- slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/fitz.go +1 -0
- slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/fitz_cgo.go +3 -0
- slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/fitz_nocgo.go +4 -5
- slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/purego_darwin.go +11 -1
- slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/purego_linux.go +10 -0
- slidge_whatsapp/vendor/github.com/gen2brain/go-fitz/purego_windows.go +12 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/.gitignore +0 -2
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/CHANGELOG.md +30 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/COPYRIGHT.txt +6 -1
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/README.md +14 -17
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi.go +1 -1
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi2.go +7 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/LICENSE +21 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/darwin_amd64/libffi.8.dylib +0 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/darwin_arm64/libffi.8.dylib +0 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/assets/libffi/windows_amd64/libffi-8.dll +0 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/cif.go +15 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/cif_arm64.go +16 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed.go +49 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed_darwin_amd64.go +10 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed_darwin_arm64.go +10 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/embed_windows_amd64.go +10 -0
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/ffi.go +51 -13
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/init.go +22 -9
- slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/README.md +2 -0
- slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c +3096 -1651
- slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h +188 -128
- slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3_opt_userauth.go +13 -140
- slidge_whatsapp/vendor/github.com/mattn/go-sqlite3/sqlite3ext.h +4 -0
- slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.23.go +2 -2
- slidge_whatsapp/vendor/github.com/petermattis/goid/runtime_go1.25.go +37 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/LICENSE +19 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/argmap.go +37 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/collections.go +148 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/comment.go +31 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/decode.go +216 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/definition.go +110 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/directive.go +43 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/document.go +89 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/dumper.go +159 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/fragment.go +41 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/operation.go +32 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/path.go +72 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/selection.go +41 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/source.go +19 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/type.go +68 -0
- slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/value.go +122 -0
- slidge_whatsapp/vendor/go.mau.fi/util/exhttp/handleerrors.go +60 -26
- slidge_whatsapp/vendor/go.mau.fi/util/exhttp/networkerror.go +2 -1
- slidge_whatsapp/vendor/go.mau.fi/util/exstrings/stringutil.go +28 -0
- slidge_whatsapp/vendor/go.mau.fi/util/exsync/event.go +19 -3
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/.pre-commit-config.yaml +3 -3
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/decode.go +1 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/hash.go +1 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate.go +5 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/argo/argo-wire-type-store.argo +63 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/argo/argo.go +62 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/argo/name-to-queryids.json +306 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/armadillomessage.go +3 -2
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/call.go +1 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/client.go +15 -18
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/connectionevents.go +5 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download.go +4 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/errors.go +3 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/group.go +97 -25
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/internals.go +22 -10
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/message.go +10 -9
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/msgsecret.go +2 -14
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/newsletter.go +83 -7
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/notification.go +5 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair-code.go +2 -2
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/presence.go +15 -6
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waBotMetadata/WABotMetadata.pb.go +5156 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waBotMetadata/WABotMetadata.proto +516 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.pb.go +30 -3
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.proto +3 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.go +8532 -11526
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.proto +132 -438
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.go +52 -23
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.proto +3 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.pb.go +225 -73
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.proto +21 -5
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.go +884 -441
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.proto +40 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.go +60 -38
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.proto +3 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/receipt.go +8 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/send.go +6 -4
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +1 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/noop.go +3 -2
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/sqlstore/store.go +25 -5
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/store.go +3 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/call.go +1 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/events/events.go +8 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/jid.go +2 -1
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/user.go +2 -0
- slidge_whatsapp/vendor/go.mau.fi/whatsmeow/user.go +12 -8
- slidge_whatsapp/vendor/golang.org/x/crypto/curve25519/curve25519.go +1 -1
- slidge_whatsapp/vendor/golang.org/x/net/http2/config.go +44 -2
- slidge_whatsapp/vendor/golang.org/x/net/http2/gotrack.go +14 -3
- slidge_whatsapp/vendor/golang.org/x/net/http2/http2.go +7 -29
- slidge_whatsapp/vendor/golang.org/x/net/http2/server.go +53 -71
- slidge_whatsapp/vendor/golang.org/x/net/http2/transport.go +20 -74
- slidge_whatsapp/vendor/golang.org/x/sys/unix/affinity_linux.go +1 -3
- slidge_whatsapp/vendor/golang.org/x/sys/unix/mkerrors.sh +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_darwin.go +1 -55
- slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_solaris.go +1 -1
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux.go +47 -16
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +3 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +4 -4
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +1 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux.go +168 -12
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_386.go +17 -1
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go +18 -2
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go +17 -1
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +17 -1
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +18 -2
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +16 -0
- slidge_whatsapp/vendor/golang.org/x/sys/windows/types_windows.go +6 -0
- slidge_whatsapp/vendor/golang.org/x/sys/windows/zsyscall_windows.go +483 -483
- slidge_whatsapp/vendor/google.golang.org/protobuf/encoding/protowire/wire.go +25 -1
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb +0 -0
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/filedesc/editions.go +10 -5
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/filedesc/presence.go +33 -0
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/genid/api_gen.go +6 -0
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +68 -22
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/impl/codec_message_opaque.go +2 -1
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/impl/message_opaque.go +8 -37
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/impl/presence.go +0 -3
- slidge_whatsapp/vendor/google.golang.org/protobuf/internal/version/version.go +1 -1
- slidge_whatsapp/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +8 -0
- slidge_whatsapp/vendor/modules.txt +43 -23
- {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/METADATA +5 -4
- {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/RECORD +208 -161
- {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/WHEEL +1 -1
- slidge_whatsapp/vendor/github.com/jupiterrider/ffi/abi_amd64.go +0 -7
- slidge_whatsapp/vendor/golang.org/x/net/http2/config_go124.go +0 -61
- slidge_whatsapp/vendor/golang.org/x/net/http2/config_pre_go124.go +0 -16
- slidge_whatsapp/vendor/golang.org/x/net/http2/timer.go +0 -20
- {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info}/entry_points.txt +0 -0
- {slidge_whatsapp-0.2.7.dist-info → slidge_whatsapp-0.3.0.dist-info/licenses}/LICENSE +0 -0
slidge_whatsapp/contact.py
CHANGED
|
@@ -2,6 +2,7 @@ from datetime import datetime, timezone
|
|
|
2
2
|
from typing import TYPE_CHECKING
|
|
3
3
|
|
|
4
4
|
from slidge import LegacyContact, LegacyRoster
|
|
5
|
+
from slidge.util.types import Avatar
|
|
5
6
|
from slixmpp.exceptions import XMPPError
|
|
6
7
|
|
|
7
8
|
from . import config
|
|
@@ -28,6 +29,12 @@ class Contact(LegacyContact[str]):
|
|
|
28
29
|
else:
|
|
29
30
|
self.online(last_seen=last_seen)
|
|
30
31
|
|
|
32
|
+
async def update_info(self) -> None:
|
|
33
|
+
if whatsapp.IsAnonymousJID(self.legacy_id):
|
|
34
|
+
self.log.error(
|
|
35
|
+
"Contact for anonymous participant added: %s", self.legacy_id
|
|
36
|
+
)
|
|
37
|
+
|
|
31
38
|
|
|
32
39
|
class Roster(LegacyRoster[str, Contact]):
|
|
33
40
|
session: "Session"
|
|
@@ -54,9 +61,12 @@ class Roster(LegacyRoster[str, Contact]):
|
|
|
54
61
|
contact.name = data.Name
|
|
55
62
|
contact.is_friend = True
|
|
56
63
|
try:
|
|
57
|
-
|
|
58
|
-
if
|
|
59
|
-
|
|
64
|
+
unique_id = ""
|
|
65
|
+
if contact.avatar is not None:
|
|
66
|
+
unique_id = contact.avatar.unique_id or ""
|
|
67
|
+
avatar = self.session.whatsapp.GetAvatar(data.JID, unique_id)
|
|
68
|
+
if avatar.URL and unique_id != avatar.ID:
|
|
69
|
+
await contact.set_avatar(Avatar(url=avatar.URL, unique_id=avatar.ID))
|
|
60
70
|
elif avatar.URL == "" and avatar.ID == "":
|
|
61
71
|
await contact.set_avatar(None)
|
|
62
72
|
except RuntimeError as err:
|
|
@@ -67,6 +77,8 @@ class Roster(LegacyRoster[str, Contact]):
|
|
|
67
77
|
return contact
|
|
68
78
|
|
|
69
79
|
async def legacy_id_to_jid_username(self, legacy_id: str) -> str:
|
|
80
|
+
if not "@" in legacy_id:
|
|
81
|
+
raise XMPPError("item-not-found", "Invalid contact ID, not a JID")
|
|
70
82
|
return "+" + legacy_id[: legacy_id.find("@")]
|
|
71
83
|
|
|
72
84
|
async def jid_username_to_legacy_id(self, jid_username: str) -> str:
|
slidge_whatsapp/event.go
CHANGED
|
@@ -46,6 +46,7 @@ type EventPayload struct {
|
|
|
46
46
|
QRCode string
|
|
47
47
|
PairDeviceID string
|
|
48
48
|
Connect Connect
|
|
49
|
+
LoggedOut LoggedOut
|
|
49
50
|
Contact Contact
|
|
50
51
|
Presence Presence
|
|
51
52
|
Message Message
|
|
@@ -66,6 +67,11 @@ type Connect struct {
|
|
|
66
67
|
Error string // The connection error, if any.
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
// LoggedOut repreents event data related to an explicit or implicit log-out event.
|
|
71
|
+
type LoggedOut struct {
|
|
72
|
+
Reason string // The human-readable reason for logging out, if any.
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
// A Avatar represents a small image set for a Contact or Group.
|
|
70
76
|
type Avatar struct {
|
|
71
77
|
ID string // The unique ID for this avatar, used for persistent caching.
|
|
@@ -82,10 +88,25 @@ type Contact struct {
|
|
|
82
88
|
// NewContactEvent returns event data meant for [Session.propagateEvent] for the contact information
|
|
83
89
|
// given. Unknown or invalid contact information will return an [EventUnknown] event with nil data.
|
|
84
90
|
func newContactEvent(jid types.JID, info types.ContactInfo) (EventKind, *EventPayload) {
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
contact := newContact(jid, info)
|
|
92
|
+
if contact.JID == "" {
|
|
93
|
+
return EventUnknown, nil
|
|
87
94
|
}
|
|
88
95
|
|
|
96
|
+
return EventContact, &EventPayload{Contact: contact}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// NewContact returns a concrete [Contact] instance for the JID and additional information given.
|
|
100
|
+
// In cases where a valid contact can't be returned, [Contact.JID] will be left empty.
|
|
101
|
+
func newContact(jid types.JID, info types.ContactInfo) Contact {
|
|
102
|
+
// Don't instantiate hidden contacts, as these are better handled as group participants
|
|
103
|
+
if jid.Server == types.HiddenUserServer {
|
|
104
|
+
return Contact{}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Find valid contact name from list of alternatives, or return empty contact if none could
|
|
108
|
+
// be found.
|
|
109
|
+
var contact = Contact{JID: jid.ToNonAD().String()}
|
|
89
110
|
for _, n := range []string{info.FullName, info.FirstName, info.BusinessName, info.PushName} {
|
|
90
111
|
if n != "" {
|
|
91
112
|
contact.Name = n
|
|
@@ -93,12 +114,11 @@ func newContactEvent(jid types.JID, info types.ContactInfo) (EventKind, *EventPa
|
|
|
93
114
|
}
|
|
94
115
|
}
|
|
95
116
|
|
|
96
|
-
// Don't attempt to synchronize contacts with no user-readable name.
|
|
97
117
|
if contact.Name == "" {
|
|
98
|
-
return
|
|
118
|
+
return Contact{}
|
|
99
119
|
}
|
|
100
120
|
|
|
101
|
-
return
|
|
121
|
+
return contact
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
// PresenceKind represents the different kinds of activity states possible in WhatsApp.
|
|
@@ -122,6 +142,10 @@ type Presence struct {
|
|
|
122
142
|
// NewPresenceEvent returns event data meant for [Session.propagateEvent] for the primitive presence
|
|
123
143
|
// event given.
|
|
124
144
|
func newPresenceEvent(evt *events.Presence) (EventKind, *EventPayload) {
|
|
145
|
+
if evt.From.Server == types.HiddenUserServer {
|
|
146
|
+
return EventUnknown, nil
|
|
147
|
+
}
|
|
148
|
+
|
|
125
149
|
var presence = Presence{
|
|
126
150
|
JID: evt.From.ToNonAD().String(),
|
|
127
151
|
Kind: PresenceAvailable,
|
|
@@ -169,9 +193,11 @@ type Message struct {
|
|
|
169
193
|
Location Location // The location metadata for messages, if any.
|
|
170
194
|
Poll Poll // The multiple-choice poll contained in the message, if any.
|
|
171
195
|
Album Album // The image album message, if any.
|
|
196
|
+
GroupInvite Group // Group information for the invite group included in this message, if any.
|
|
172
197
|
MentionJIDs []string // A list of JIDs mentioned in this message, if any.
|
|
173
198
|
Receipts []Receipt // The receipt statuses for the message, typically provided alongside historical messages.
|
|
174
199
|
Reactions []Message // Reactions attached to message, typically provided alongside historical messages.
|
|
200
|
+
IsHistory bool // Whether or not the message is derived from message history.
|
|
175
201
|
}
|
|
176
202
|
|
|
177
203
|
// A Attachment represents additional binary data (e.g. images, videos, documents) provided alongside
|
|
@@ -253,14 +279,13 @@ type Album struct {
|
|
|
253
279
|
|
|
254
280
|
// NewMessageEvent returns event data meant for [Session.propagateEvent] for the primive message
|
|
255
281
|
// event given. Unknown or invalid messages will return an [EventUnknown] event with nil data.
|
|
256
|
-
func newMessageEvent(client *whatsmeow.Client, evt *events.Message) (EventKind, *EventPayload) {
|
|
282
|
+
func newMessageEvent(ctx context.Context, client *whatsmeow.Client, evt *events.Message) (EventKind, *EventPayload) {
|
|
257
283
|
// Set basic data for message, to be potentially amended depending on the concrete version of
|
|
258
284
|
// the underlying message.
|
|
259
|
-
var ctx = context.Background()
|
|
260
285
|
var message = Message{
|
|
261
286
|
Kind: MessagePlain,
|
|
262
287
|
ID: evt.Info.ID,
|
|
263
|
-
JID: evt.Info.Sender.ToNonAD().String(),
|
|
288
|
+
JID: getPreferredJID(ctx, client, evt.Info.Sender, evt.Info.SenderAlt).ToNonAD().String(),
|
|
264
289
|
Body: evt.Message.GetConversation(),
|
|
265
290
|
Timestamp: evt.Info.Timestamp.Unix(),
|
|
266
291
|
IsCarbon: evt.Info.IsFromMe,
|
|
@@ -378,7 +403,18 @@ func newMessageEvent(client *whatsmeow.Client, evt *events.Message) (EventKind,
|
|
|
378
403
|
message.Body = e.GetText()
|
|
379
404
|
}
|
|
380
405
|
|
|
381
|
-
|
|
406
|
+
// Handle group-chat invite link in text message.
|
|
407
|
+
if code, ok := strings.CutPrefix(e.GetMatchedText(), whatsmeow.InviteLinkPrefix); ok {
|
|
408
|
+
if info, err := client.GetGroupInfoFromLink(e.GetMatchedText()); err != nil {
|
|
409
|
+
client.Log.Errorf("Failed getting group info from invite: %s", err)
|
|
410
|
+
} else if _, err := client.JoinGroupWithLink(code); err != nil {
|
|
411
|
+
client.Log.Errorf("Failed joining group with invite: %s", err)
|
|
412
|
+
} else {
|
|
413
|
+
message.GroupInvite = newGroup(ctx, client, info)
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
message = getMessageWithContext(message, e.GetContextInfo())
|
|
417
|
+
}
|
|
382
418
|
}
|
|
383
419
|
|
|
384
420
|
// Ignore obviously invalid messages.
|
|
@@ -424,6 +460,7 @@ func getMessageAttachments(ctx context.Context, client *whatsmeow.Client, messag
|
|
|
424
460
|
message.GetVideoMessage(),
|
|
425
461
|
message.GetDocumentMessage(),
|
|
426
462
|
message.GetStickerMessage(),
|
|
463
|
+
message.GetPtvMessage(),
|
|
427
464
|
}
|
|
428
465
|
|
|
429
466
|
for _, msg := range kinds {
|
|
@@ -837,10 +874,9 @@ func getBaseMediaType(typ string) string {
|
|
|
837
874
|
//
|
|
838
875
|
// Typically, this will return [EventMessage] events with appropriate [Message] payloads; unknown or
|
|
839
876
|
// invalid messages will return an [EventUnknown] event with nil data.
|
|
840
|
-
func newEventFromHistory(client *whatsmeow.Client, info *waWeb.WebMessageInfo) (EventKind, *EventPayload) {
|
|
877
|
+
func newEventFromHistory(ctx context.Context, client *whatsmeow.Client, info *waWeb.WebMessageInfo) (EventKind, *EventPayload) {
|
|
841
878
|
// Handle message as group message is remote JID is a group JID in the absence of any other,
|
|
842
879
|
// specific signal, or don't handle at all if no group JID is found.
|
|
843
|
-
var ctx = context.Background()
|
|
844
880
|
var jid = info.GetKey().GetRemoteJID()
|
|
845
881
|
if j, _ := types.ParseJID(jid); j.Server != types.GroupServer {
|
|
846
882
|
return EventUnknown, nil
|
|
@@ -855,10 +891,15 @@ func newEventFromHistory(client *whatsmeow.Client, info *waWeb.WebMessageInfo) (
|
|
|
855
891
|
Body: info.GetMessage().GetConversation(),
|
|
856
892
|
Timestamp: int64(info.GetMessageTimestamp()),
|
|
857
893
|
IsCarbon: info.GetKey().GetFromMe(),
|
|
894
|
+
IsHistory: true,
|
|
858
895
|
}
|
|
859
896
|
|
|
860
897
|
if info.Participant != nil {
|
|
861
|
-
|
|
898
|
+
jid, err := types.ParseJID(info.GetParticipant())
|
|
899
|
+
if err != nil {
|
|
900
|
+
return EventUnknown, nil
|
|
901
|
+
}
|
|
902
|
+
message.JID = getPreferredJID(ctx, client, jid).ToNonAD().String()
|
|
862
903
|
} else if info.GetKey().GetFromMe() {
|
|
863
904
|
message.JID = client.Store.ID.ToNonAD().String()
|
|
864
905
|
} else {
|
|
@@ -873,9 +914,13 @@ func newEventFromHistory(client *whatsmeow.Client, info *waWeb.WebMessageInfo) (
|
|
|
873
914
|
case waWeb.WebMessageInfo_CIPHERTEXT:
|
|
874
915
|
return EventUnknown, nil
|
|
875
916
|
case waWeb.WebMessageInfo_CALL_MISSED_VOICE, waWeb.WebMessageInfo_CALL_MISSED_VIDEO:
|
|
917
|
+
jid, err := types.ParseJID(info.GetKey().GetParticipant())
|
|
918
|
+
if err != nil {
|
|
919
|
+
return EventUnknown, nil
|
|
920
|
+
}
|
|
876
921
|
return EventCall, &EventPayload{Call: Call{
|
|
877
922
|
State: CallMissed,
|
|
878
|
-
JID:
|
|
923
|
+
JID: getPreferredJID(ctx, client, jid).ToNonAD().String(),
|
|
879
924
|
Timestamp: int64(info.GetMessageTimestamp()),
|
|
880
925
|
}}
|
|
881
926
|
case waWeb.WebMessageInfo_REVOKE:
|
|
@@ -891,10 +936,14 @@ func newEventFromHistory(client *whatsmeow.Client, info *waWeb.WebMessageInfo) (
|
|
|
891
936
|
// Handle emoji reaction to existing message.
|
|
892
937
|
for _, r := range info.GetReactions() {
|
|
893
938
|
if r.GetText() != "" {
|
|
939
|
+
jid, err := types.ParseJID(r.GetKey().GetParticipant())
|
|
940
|
+
if err != nil {
|
|
941
|
+
continue
|
|
942
|
+
}
|
|
894
943
|
message.Reactions = append(message.Reactions, Message{
|
|
895
944
|
Kind: MessageReaction,
|
|
896
945
|
ID: r.GetKey().GetID(),
|
|
897
|
-
JID:
|
|
946
|
+
JID: getPreferredJID(ctx, client, jid).ToNonAD().String(),
|
|
898
947
|
Body: r.GetText(),
|
|
899
948
|
Timestamp: r.GetSenderTimestampMS() / 1000,
|
|
900
949
|
IsCarbon: r.GetKey().GetFromMe(),
|
|
@@ -920,7 +969,15 @@ func newEventFromHistory(client *whatsmeow.Client, info *waWeb.WebMessageInfo) (
|
|
|
920
969
|
if client.Store.ID.ToNonAD().String() == r.GetUserJID() {
|
|
921
970
|
continue
|
|
922
971
|
}
|
|
923
|
-
|
|
972
|
+
jid, err := types.ParseJID(r.GetUserJID())
|
|
973
|
+
if err != nil {
|
|
974
|
+
continue
|
|
975
|
+
}
|
|
976
|
+
var receipt = Receipt{
|
|
977
|
+
JID: getPreferredJID(ctx, client, jid).ToNonAD().String(),
|
|
978
|
+
GroupJID: message.GroupJID,
|
|
979
|
+
MessageIDs: []string{message.ID},
|
|
980
|
+
}
|
|
924
981
|
switch info.GetStatus() {
|
|
925
982
|
case waWeb.WebMessageInfo_DELIVERY_ACK:
|
|
926
983
|
receipt.Kind = ReceiptDelivered
|
|
@@ -938,7 +995,6 @@ func newEventFromHistory(client *whatsmeow.Client, info *waWeb.WebMessageInfo) (
|
|
|
938
995
|
if message.Body == "" {
|
|
939
996
|
message.Body = e.GetText()
|
|
940
997
|
}
|
|
941
|
-
|
|
942
998
|
message = getMessageWithContext(message, e.GetContextInfo())
|
|
943
999
|
}
|
|
944
1000
|
|
|
@@ -971,8 +1027,10 @@ type ChatState struct {
|
|
|
971
1027
|
|
|
972
1028
|
// NewChatStateEvent returns event data meant for [Session.propagateEvent] for the primitive
|
|
973
1029
|
// chat-state event given.
|
|
974
|
-
func newChatStateEvent(evt *events.ChatPresence) (EventKind, *EventPayload) {
|
|
975
|
-
var state = ChatState{
|
|
1030
|
+
func newChatStateEvent(ctx context.Context, client *whatsmeow.Client, evt *events.ChatPresence) (EventKind, *EventPayload) {
|
|
1031
|
+
var state = ChatState{
|
|
1032
|
+
JID: getPreferredJID(ctx, client, evt.Sender, evt.SenderAlt).ToNonAD().String(),
|
|
1033
|
+
}
|
|
976
1034
|
if evt.IsGroup {
|
|
977
1035
|
state.GroupJID = evt.Chat.ToNonAD().String()
|
|
978
1036
|
}
|
|
@@ -1009,10 +1067,10 @@ type Receipt struct {
|
|
|
1009
1067
|
|
|
1010
1068
|
// NewReceiptEvent returns event data meant for [Session.propagateEvent] for the primive receipt
|
|
1011
1069
|
// event given. Unknown or invalid receipts will return an [EventUnknown] event with nil data.
|
|
1012
|
-
func newReceiptEvent(evt *events.Receipt) (EventKind, *EventPayload) {
|
|
1070
|
+
func newReceiptEvent(ctx context.Context, client *whatsmeow.Client, evt *events.Receipt) (EventKind, *EventPayload) {
|
|
1013
1071
|
var receipt = Receipt{
|
|
1014
1072
|
MessageIDs: slices.Clone(evt.MessageIDs),
|
|
1015
|
-
JID: evt.Sender.ToNonAD().String(),
|
|
1073
|
+
JID: getPreferredJID(ctx, client, evt.Sender, evt.SenderAlt).ToNonAD().String(),
|
|
1016
1074
|
Timestamp: evt.Timestamp.Unix(),
|
|
1017
1075
|
IsCarbon: evt.IsFromMe,
|
|
1018
1076
|
}
|
|
@@ -1059,14 +1117,15 @@ type Group struct {
|
|
|
1059
1117
|
Subject GroupSubject // The longer-form, user-defined description for this group.
|
|
1060
1118
|
Nickname string // Our own nickname in this group-chat.
|
|
1061
1119
|
Participants []GroupParticipant // The list of participant contacts for this group, including ourselves.
|
|
1120
|
+
InviteCode string // The code for inviting members to this group-chat.
|
|
1062
1121
|
}
|
|
1063
1122
|
|
|
1064
1123
|
// A GroupSubject represents the user-defined group description and attached metadata thereof, for a
|
|
1065
1124
|
// given [Group].
|
|
1066
1125
|
type GroupSubject struct {
|
|
1067
|
-
Subject
|
|
1068
|
-
SetAt
|
|
1069
|
-
|
|
1126
|
+
Subject string // The user-defined group description.
|
|
1127
|
+
SetAt int64 // The exact time this group description was set at, as a timestamp.
|
|
1128
|
+
SetBy string // The name of the user that set the subject.
|
|
1070
1129
|
}
|
|
1071
1130
|
|
|
1072
1131
|
// GroupParticipantAction represents the distinct set of actions that can be taken when encountering
|
|
@@ -1096,10 +1155,11 @@ func (a GroupParticipantAction) toParticipantChange() whatsmeow.ParticipantChang
|
|
|
1096
1155
|
}
|
|
1097
1156
|
|
|
1098
1157
|
// A GroupParticipant represents a contact who is currently joined in a given group. Participants in
|
|
1099
|
-
// WhatsApp can
|
|
1158
|
+
// WhatsApp can generally be derived back to their individual [Contact]; there are no anonymous groups
|
|
1100
1159
|
// in WhatsApp.
|
|
1101
1160
|
type GroupParticipant struct {
|
|
1102
1161
|
JID string // The WhatsApp JID for this participant.
|
|
1162
|
+
Nickname string // The user-set name for this participant, typically only set for anonymous participants.
|
|
1103
1163
|
Affiliation GroupAffiliation // The set of priviledges given to this specific participant.
|
|
1104
1164
|
Action GroupParticipantAction // The specific action to take for this participant; typically to add.
|
|
1105
1165
|
}
|
|
@@ -1107,59 +1167,67 @@ type GroupParticipant struct {
|
|
|
1107
1167
|
// NewGroupParticipant returns a [GroupParticipant], filling fields from the internal participant
|
|
1108
1168
|
// type. This is a no-op if [types.GroupParticipant.Error] is non-zero, and other fields may only
|
|
1109
1169
|
// be set optionally.
|
|
1110
|
-
func newGroupParticipant(
|
|
1111
|
-
if
|
|
1170
|
+
func newGroupParticipant(ctx context.Context, client *whatsmeow.Client, participant types.GroupParticipant) GroupParticipant {
|
|
1171
|
+
if participant.Error > 0 {
|
|
1112
1172
|
return GroupParticipant{}
|
|
1113
1173
|
}
|
|
1114
|
-
var
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1174
|
+
var jid = getPreferredJID(ctx, client, participant.JID, participant.PhoneNumber)
|
|
1175
|
+
var p = GroupParticipant{
|
|
1176
|
+
JID: jid.ToNonAD().String(),
|
|
1177
|
+
}
|
|
1178
|
+
if participant.IsSuperAdmin {
|
|
1179
|
+
p.Affiliation = GroupAffiliationOwner
|
|
1180
|
+
} else if participant.IsAdmin {
|
|
1181
|
+
p.Affiliation = GroupAffiliationAdmin
|
|
1119
1182
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1183
|
+
if IsAnonymousJID(p.JID) {
|
|
1184
|
+
if c, err := client.Store.Contacts.GetContact(ctx, participant.JID); err == nil {
|
|
1185
|
+
p.Nickname = c.PushName
|
|
1186
|
+
}
|
|
1123
1187
|
}
|
|
1188
|
+
return p
|
|
1124
1189
|
}
|
|
1125
1190
|
|
|
1126
1191
|
// NewGroupEvent returns event data meant for [Session.propagateEvent] for the primive group event
|
|
1127
1192
|
// given. Group data returned by this function can be partial, and callers should take care to only
|
|
1128
1193
|
// handle non-empty values.
|
|
1129
|
-
func newGroupEvent(evt *events.GroupInfo) (EventKind, *EventPayload) {
|
|
1194
|
+
func newGroupEvent(ctx context.Context, client *whatsmeow.Client, evt *events.GroupInfo) (EventKind, *EventPayload) {
|
|
1130
1195
|
var group = Group{JID: evt.JID.ToNonAD().String()}
|
|
1131
1196
|
if evt.Name != nil {
|
|
1132
1197
|
group.Name = evt.Name.Name
|
|
1133
1198
|
}
|
|
1134
1199
|
if evt.Topic != nil {
|
|
1200
|
+
topicJID := getPreferredJID(ctx, client, evt.Topic.TopicSetBy, evt.Topic.TopicSetByPN)
|
|
1135
1201
|
group.Subject = GroupSubject{
|
|
1136
|
-
Subject:
|
|
1137
|
-
SetAt:
|
|
1138
|
-
|
|
1202
|
+
Subject: evt.Topic.Topic,
|
|
1203
|
+
SetAt: evt.Topic.TopicSetAt.Unix(),
|
|
1204
|
+
}
|
|
1205
|
+
if c, err := client.Store.Contacts.GetContact(ctx, topicJID); err == nil {
|
|
1206
|
+
group.Subject.SetBy = c.PushName
|
|
1139
1207
|
}
|
|
1140
1208
|
}
|
|
1141
1209
|
for _, p := range evt.Join {
|
|
1142
1210
|
group.Participants = append(group.Participants, GroupParticipant{
|
|
1143
|
-
JID: p.ToNonAD().String(),
|
|
1211
|
+
JID: getPreferredJID(ctx, client, p).ToNonAD().String(),
|
|
1144
1212
|
Action: GroupParticipantActionAdd,
|
|
1145
1213
|
})
|
|
1146
1214
|
}
|
|
1147
1215
|
for _, p := range evt.Leave {
|
|
1148
1216
|
group.Participants = append(group.Participants, GroupParticipant{
|
|
1149
|
-
JID: p.ToNonAD().String(),
|
|
1217
|
+
JID: getPreferredJID(ctx, client, p).ToNonAD().String(),
|
|
1150
1218
|
Action: GroupParticipantActionRemove,
|
|
1151
1219
|
})
|
|
1152
1220
|
}
|
|
1153
1221
|
for _, p := range evt.Promote {
|
|
1154
1222
|
group.Participants = append(group.Participants, GroupParticipant{
|
|
1155
|
-
JID: p.ToNonAD().String(),
|
|
1223
|
+
JID: getPreferredJID(ctx, client, p).ToNonAD().String(),
|
|
1156
1224
|
Action: GroupParticipantActionPromote,
|
|
1157
1225
|
Affiliation: GroupAffiliationAdmin,
|
|
1158
1226
|
})
|
|
1159
1227
|
}
|
|
1160
1228
|
for _, p := range evt.Demote {
|
|
1161
1229
|
group.Participants = append(group.Participants, GroupParticipant{
|
|
1162
|
-
JID: p.ToNonAD().String(),
|
|
1230
|
+
JID: getPreferredJID(ctx, client, p).ToNonAD().String(),
|
|
1163
1231
|
Action: GroupParticipantActionDemote,
|
|
1164
1232
|
Affiliation: GroupAffiliationNone,
|
|
1165
1233
|
})
|
|
@@ -1170,26 +1238,32 @@ func newGroupEvent(evt *events.GroupInfo) (EventKind, *EventPayload) {
|
|
|
1170
1238
|
// NewGroup returns a concrete [Group] for the primitive data given. This function will generally
|
|
1171
1239
|
// populate fields with as much data as is available from the remote, and is therefore should not
|
|
1172
1240
|
// be called when partial data is to be returned.
|
|
1173
|
-
func newGroup(client *whatsmeow.Client, info *types.GroupInfo) Group {
|
|
1241
|
+
func newGroup(ctx context.Context, client *whatsmeow.Client, info *types.GroupInfo) Group {
|
|
1174
1242
|
var participants []GroupParticipant
|
|
1175
1243
|
for i := range info.Participants {
|
|
1176
|
-
p := newGroupParticipant(info.Participants[i])
|
|
1244
|
+
p := newGroupParticipant(ctx, client, info.Participants[i])
|
|
1177
1245
|
if p.JID == "" {
|
|
1178
1246
|
continue
|
|
1179
1247
|
}
|
|
1180
1248
|
participants = append(participants, p)
|
|
1181
1249
|
}
|
|
1182
|
-
|
|
1250
|
+
|
|
1251
|
+
var topicJID = getPreferredJID(ctx, client, info.TopicSetBy, info.TopicSetByPN)
|
|
1252
|
+
var group = Group{
|
|
1183
1253
|
JID: info.JID.ToNonAD().String(),
|
|
1184
1254
|
Name: info.Name,
|
|
1185
1255
|
Subject: GroupSubject{
|
|
1186
|
-
Subject:
|
|
1187
|
-
SetAt:
|
|
1188
|
-
SetByJID: info.TopicSetBy.ToNonAD().String(),
|
|
1256
|
+
Subject: info.Topic,
|
|
1257
|
+
SetAt: info.TopicSetAt.Unix(),
|
|
1189
1258
|
},
|
|
1190
1259
|
Nickname: client.Store.PushName,
|
|
1191
1260
|
Participants: participants,
|
|
1192
1261
|
}
|
|
1262
|
+
if c, err := client.Store.Contacts.GetContact(ctx, topicJID); err == nil {
|
|
1263
|
+
group.Subject.SetBy = c.PushName
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
return group
|
|
1193
1267
|
}
|
|
1194
1268
|
|
|
1195
1269
|
// CallState represents the state of the call to synchronize with.
|
|
@@ -1234,3 +1308,25 @@ func newCallEvent(state CallState, meta types.BasicCallMeta) (EventKind, *EventP
|
|
|
1234
1308
|
Timestamp: meta.Timestamp.Unix(),
|
|
1235
1309
|
}}
|
|
1236
1310
|
}
|
|
1311
|
+
|
|
1312
|
+
// GetPreferredJID returns one of the [type.JID] values for the given senders, preferring the first
|
|
1313
|
+
// non-empty, non-hidden sender; if none are found, mappings from LID to JID are tried, or otherwise,
|
|
1314
|
+
// the first JID given is returned.
|
|
1315
|
+
func getPreferredJID(ctx context.Context, client *whatsmeow.Client, def types.JID, alt ...types.JID) types.JID {
|
|
1316
|
+
var jids = append([]types.JID{def}, alt...)
|
|
1317
|
+
for _, s := range jids {
|
|
1318
|
+
if !s.IsEmpty() && s.Server != types.HiddenUserServer {
|
|
1319
|
+
return s
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
for _, s := range jids {
|
|
1324
|
+
if !s.IsEmpty() && s.Server == types.HiddenUserServer {
|
|
1325
|
+
if p, _ := client.Store.LIDs.GetPNForLID(ctx, s); !p.IsEmpty() {
|
|
1326
|
+
return p
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
return def
|
|
1332
|
+
}
|
slidge_whatsapp/gateway.go
CHANGED
|
@@ -3,9 +3,6 @@ package whatsapp
|
|
|
3
3
|
import (
|
|
4
4
|
// Standard library.
|
|
5
5
|
"context"
|
|
6
|
-
"fmt"
|
|
7
|
-
"log/slog"
|
|
8
|
-
"os"
|
|
9
6
|
"runtime"
|
|
10
7
|
|
|
11
8
|
// Internal packages.
|
|
@@ -40,6 +37,12 @@ func (d LinkedDevice) JID() types.JID {
|
|
|
40
37
|
return jid
|
|
41
38
|
}
|
|
42
39
|
|
|
40
|
+
// IsAnonymousJID returns true if the JID given is not addressible, that is, if it's actually a LID.
|
|
41
|
+
func IsAnonymousJID(id string) bool {
|
|
42
|
+
jid, _ := types.ParseJID(id)
|
|
43
|
+
return jid.Server == types.HiddenUserServer
|
|
44
|
+
}
|
|
45
|
+
|
|
43
46
|
// A Gateway represents a persistent process for establishing individual sessions between linked
|
|
44
47
|
// devices and WhatsApp.
|
|
45
48
|
type Gateway struct {
|
|
@@ -63,13 +66,7 @@ func NewGateway() *Gateway {
|
|
|
63
66
|
// Init performs initialization procedures for the Gateway, and is expected to be run before any
|
|
64
67
|
// calls to [Gateway.Session].
|
|
65
68
|
func (w *Gateway) Init() error {
|
|
66
|
-
w.logger =
|
|
67
|
-
module: "Slidge",
|
|
68
|
-
logger: slog.New(
|
|
69
|
-
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel(w.LogLevel)}),
|
|
70
|
-
),
|
|
71
|
-
}
|
|
72
|
-
|
|
69
|
+
w.logger = walog.Stdout("slidge", w.LogLevel, false)
|
|
73
70
|
container, err := sqlstore.New(context.Background(), "sqlite3", w.DBPath, w.logger)
|
|
74
71
|
if err != nil {
|
|
75
72
|
return err
|
|
@@ -130,56 +127,3 @@ func (w *Gateway) CleanupSession(device LinkedDevice) error {
|
|
|
130
127
|
|
|
131
128
|
return nil
|
|
132
129
|
}
|
|
133
|
-
|
|
134
|
-
// A LogLevel represents a mapping between Python standard logging levels and Go standard logging
|
|
135
|
-
// levels.
|
|
136
|
-
type logLevel string
|
|
137
|
-
|
|
138
|
-
var _ slog.Leveler = logLevel("")
|
|
139
|
-
|
|
140
|
-
// Level returns the Go equivalent logging level for the Python logging level represented.
|
|
141
|
-
func (l logLevel) Level() slog.Level {
|
|
142
|
-
switch l {
|
|
143
|
-
case "FATAL", "CRITICAL", "ERROR":
|
|
144
|
-
return slog.LevelError
|
|
145
|
-
case "WARN", "WARNING":
|
|
146
|
-
return slog.LevelWarn
|
|
147
|
-
case "DEBUG":
|
|
148
|
-
return slog.LevelDebug
|
|
149
|
-
default:
|
|
150
|
-
return slog.LevelInfo
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// A Logger represents a mapping between a WhatsMeow logger and Go standard logging functions.
|
|
155
|
-
type logger struct {
|
|
156
|
-
module string
|
|
157
|
-
logger *slog.Logger
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
var _ walog.Logger = logger{}
|
|
161
|
-
|
|
162
|
-
// Errorf handles the given message as representing a (typically) fatal error.
|
|
163
|
-
func (l logger) Errorf(msg string, args ...any) {
|
|
164
|
-
l.logger.Error(fmt.Sprintf(msg, args...))
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Warn handles the given message as representing a non-fatal error or warning thereof.
|
|
168
|
-
func (l logger) Warnf(msg string, args ...any) {
|
|
169
|
-
l.logger.Warn(fmt.Sprintf(msg, args...))
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Infof handles the given message as representing an informational notice.
|
|
173
|
-
func (l logger) Infof(msg string, args ...any) {
|
|
174
|
-
l.logger.Info(fmt.Sprintf(msg, args...))
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Debugf handles the given message as representing an internal-only debug message.
|
|
178
|
-
func (l logger) Debugf(msg string, args ...any) {
|
|
179
|
-
l.logger.Debug(fmt.Sprintf(msg, args...))
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Sub is a no-op and will return the receiver itself.
|
|
183
|
-
func (l logger) Sub(module string) walog.Logger {
|
|
184
|
-
return logger{logger: l.logger.With(slog.String("module", l.module+"."+module))}
|
|
185
|
-
}
|
slidge_whatsapp/gateway.py
CHANGED
|
@@ -2,7 +2,7 @@ from logging import getLevelName, getLogger
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
|
-
from slidge import BaseGateway, FormField,
|
|
5
|
+
from slidge import BaseGateway, FormField, global_config
|
|
6
6
|
|
|
7
7
|
from . import config
|
|
8
8
|
from .generated import whatsapp
|
|
@@ -62,13 +62,12 @@ class Gateway(BaseGateway):
|
|
|
62
62
|
"""
|
|
63
63
|
pass
|
|
64
64
|
|
|
65
|
-
async def unregister(self,
|
|
65
|
+
async def unregister(self, session: "Session"): # type:ignore[override]
|
|
66
66
|
"""
|
|
67
67
|
Logout from the active WhatsApp session. This will also force a remote log-out, and thus
|
|
68
68
|
require pairing on next login. For simply disconnecting the active session, look at the
|
|
69
69
|
:meth:`.Session.disconnect` function.
|
|
70
70
|
"""
|
|
71
|
-
session: "Session" = self.get_session_from_user(user) # type:ignore
|
|
72
71
|
session.whatsapp.Logout()
|
|
73
72
|
try:
|
|
74
73
|
device_id = session.user.legacy_module_data["device_id"]
|