2024-09-25 16:01:35 +03:00
|
|
|
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
|
|
|
|
// Copyright (C) 2024 Tulir Asokan
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2024-09-16 15:38:39 +03:00
|
|
|
package waid
|
|
|
|
|
|
|
|
|
|
import (
|
2024-10-02 15:22:01 +03:00
|
|
|
"crypto/ecdh"
|
|
|
|
|
"crypto/rand"
|
2024-09-30 17:26:54 +03:00
|
|
|
"encoding/json"
|
2026-01-26 20:38:36 +02:00
|
|
|
"time"
|
2024-09-30 17:26:54 +03:00
|
|
|
|
2024-10-02 15:22:01 +03:00
|
|
|
"go.mau.fi/util/exerrors"
|
2024-09-16 15:38:39 +03:00
|
|
|
"go.mau.fi/util/jsontime"
|
2024-10-02 15:22:01 +03:00
|
|
|
"go.mau.fi/util/random"
|
2026-01-26 20:38:36 +02:00
|
|
|
"go.mau.fi/whatsmeow/appstate"
|
2024-09-16 15:38:39 +03:00
|
|
|
"go.mau.fi/whatsmeow/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UserLoginMetadata struct {
|
|
|
|
|
WADeviceID uint16 `json:"wa_device_id"`
|
|
|
|
|
PhoneLastSeen jsontime.Unix `json:"phone_last_seen"`
|
|
|
|
|
PhoneLastPinged jsontime.Unix `json:"phone_last_pinged"`
|
|
|
|
|
Timezone string `json:"timezone"`
|
2024-10-02 15:22:01 +03:00
|
|
|
PushKeys *PushKeys `json:"push_keys,omitempty"`
|
2025-03-11 18:43:51 +02:00
|
|
|
APNSEncPubKey []byte `json:"apns_enc_pubkey,omitempty"`
|
|
|
|
|
APNSEncPrivKey []byte `json:"apns_enc_privkey,omitempty"`
|
2025-07-22 16:33:26 +03:00
|
|
|
LoggedInAt jsontime.Unix `json:"logged_in_at,omitempty"`
|
2024-11-06 14:57:42 +01:00
|
|
|
|
2026-01-26 20:38:36 +02:00
|
|
|
AppStateRecoveryAttempted map[appstate.WAPatchName]time.Time `json:"app_state_recovery_attempted,omitempty"`
|
|
|
|
|
|
2024-11-06 14:57:42 +01:00
|
|
|
HistorySyncPortalsNeedCreating bool `json:"history_sync_portals_need_creating,omitempty"`
|
2026-01-20 13:14:48 +02:00
|
|
|
|
|
|
|
|
MData json.RawMessage `json:"mdata,omitempty"`
|
2024-10-02 15:22:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PushKeys struct {
|
|
|
|
|
P256DH []byte `json:"p256dh"`
|
|
|
|
|
Auth []byte `json:"auth"`
|
|
|
|
|
Private []byte `json:"private"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *UserLoginMetadata) GeneratePushKeys() {
|
|
|
|
|
privateKey := exerrors.Must(ecdh.P256().GenerateKey(rand.Reader))
|
|
|
|
|
m.PushKeys = &PushKeys{
|
|
|
|
|
P256DH: privateKey.Public().(*ecdh.PublicKey).Bytes(),
|
|
|
|
|
Auth: random.Bytes(16),
|
|
|
|
|
Private: privateKey.Bytes(),
|
|
|
|
|
}
|
2024-09-16 15:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MessageErrorType string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
MsgNoError MessageErrorType = ""
|
|
|
|
|
MsgErrDecryptionFailed MessageErrorType = "decryption_failed"
|
|
|
|
|
MsgErrMediaNotFound MessageErrorType = "media_not_found"
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-25 16:01:35 +03:00
|
|
|
type GroupInviteMeta struct {
|
|
|
|
|
JID types.JID `json:"jid"`
|
|
|
|
|
Code string `json:"code"`
|
|
|
|
|
Expiration int64 `json:"expiration,string"`
|
|
|
|
|
Inviter types.JID `json:"inviter"`
|
2025-10-21 17:42:25 +03:00
|
|
|
|
|
|
|
|
GroupName string `json:"group_name,omitempty"`
|
|
|
|
|
IsParentGroup bool `json:"is_parent_group,omitempty"`
|
2024-09-25 16:01:35 +03:00
|
|
|
}
|
|
|
|
|
|
2024-09-16 15:38:39 +03:00
|
|
|
type MessageMetadata struct {
|
2025-03-16 15:41:38 +02:00
|
|
|
SenderDeviceID uint16 `json:"sender_device_id,omitempty"`
|
|
|
|
|
Error MessageErrorType `json:"error,omitempty"`
|
|
|
|
|
BroadcastListJID *types.JID `json:"broadcast_list_jid,omitempty"`
|
|
|
|
|
GroupInvite *GroupInviteMeta `json:"group_invite,omitempty"`
|
|
|
|
|
FailedMediaMeta json.RawMessage `json:"media_meta,omitempty"`
|
|
|
|
|
DirectMediaMeta json.RawMessage `json:"direct_media_meta,omitempty"`
|
|
|
|
|
IsMatrixPoll bool `json:"is_matrix_poll,omitempty"`
|
|
|
|
|
Edits []types.MessageID `json:"edits,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (mm *MessageMetadata) CopyFrom(other any) {
|
|
|
|
|
otherMM := other.(*MessageMetadata)
|
|
|
|
|
mm.SenderDeviceID = otherMM.SenderDeviceID
|
|
|
|
|
mm.Error = otherMM.Error
|
|
|
|
|
if otherMM.BroadcastListJID != nil {
|
|
|
|
|
mm.BroadcastListJID = otherMM.BroadcastListJID
|
|
|
|
|
}
|
|
|
|
|
if otherMM.FailedMediaMeta != nil {
|
|
|
|
|
mm.FailedMediaMeta = otherMM.FailedMediaMeta
|
|
|
|
|
}
|
|
|
|
|
if otherMM.DirectMediaMeta != nil {
|
|
|
|
|
mm.DirectMediaMeta = otherMM.DirectMediaMeta
|
|
|
|
|
}
|
|
|
|
|
if otherMM.GroupInvite != nil {
|
|
|
|
|
mm.GroupInvite = otherMM.GroupInvite
|
|
|
|
|
}
|
|
|
|
|
mm.IsMatrixPoll = mm.IsMatrixPoll || otherMM.IsMatrixPoll
|
2024-09-16 15:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ReactionMetadata struct {
|
|
|
|
|
SenderDeviceID uint16 `json:"sender_device_id,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PortalMetadata struct {
|
2025-04-09 00:25:37 +03:00
|
|
|
DisappearingTimerSetAt int64 `json:"disappearing_timer_set_at,omitempty"`
|
2025-08-28 02:08:25 +02:00
|
|
|
TopicID string `json:"topic_id,omitempty"`
|
2025-04-09 00:25:37 +03:00
|
|
|
LastSync jsontime.Unix `json:"last_sync,omitempty"`
|
|
|
|
|
CommunityAnnouncementGroup bool `json:"is_cag,omitempty"`
|
|
|
|
|
AddressingMode types.AddressingMode `json:"addressing_mode,omitempty"`
|
2025-06-09 18:53:23 +05:30
|
|
|
LIDMigrationAttempted bool `json:"lid_migration_attempted,omitempty"`
|
2024-09-16 15:38:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GhostMetadata struct {
|
2024-09-26 18:44:25 +03:00
|
|
|
LastSync jsontime.Unix `json:"last_sync,omitempty"`
|
2024-09-16 15:38:39 +03:00
|
|
|
}
|