Skip to content

Commit

Permalink
Merge pull request 'Merge upstream' (#1) from MirrorHub/mautrix-whats…
Browse files Browse the repository at this point in the history
  • Loading branch information
leytilera committed Feb 9, 2024
2 parents 7c692ae + 4efb226 commit 805d847
Show file tree
Hide file tree
Showing 42 changed files with 1,373 additions and 1,031 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version: ["1.20", "1.21"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: ${{ matrix.go-version }}
cache: true

- name: Install libolm
run: sudo apt-get install libolm-dev libolm3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*.log

/mautrix-whatsapp
/start
1 change: 1 addition & 0 deletions .idea/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude_types: [markdown]
Expand All @@ -13,3 +13,8 @@ repos:
hooks:
- id: go-imports-repo
- id: go-vet-repo-mod

- repo: https://github.com/beeper/pre-commit-go
rev: v0.2.2
hooks:
- id: zerolog-ban-msgf
68 changes: 67 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,72 @@
# v0.8.6 (unreleased)
# v0.10.5 (2023-12-16)

* Added support for sending media to channels.
* Fixed voting in polls (seems to have broken due to a server-side change).
* Improved memory usage for bridges with lots of portals.

# v0.10.4 (2023-11-16)

* Added support for channels in `join` and `open` commands.
* Added initial bridging of channel admin to room admin status.
* Fixed panic when trying to send message in a portal which has a relaybot set
if the relaybot user gets logged out of WhatsApp.

# v0.10.3 (2023-10-16)

* Added basic support for channels.
* Added default mime type for outgoing attachments when the origin Matrix
client forgets to specify the mime type.
* Fixed legacy backfill creating portals for chats without messages.
* Updated libwebp version used for encoding.

# v0.10.2 (security update)

* Stopped using libwebp for decoding webps.

# v0.10.1 (2023-09-16)

* Added support for double puppeting with arbitrary `as_token`s.
See [docs](https://docs.mau.fi/bridges/general/double-puppeting.html#appservice-method-new) for more info.
* Added retrying for media downloads when WhatsApp servers break and start
returning 429s and 503s.
* Fixed logging in with 8-letter code.
* Fixed syncing community announcement groups.
* Changed "Incoming call" message to explicitly say you have to open WhatsApp
on your phone to answer.

# v0.10.0 (2023-08-16)

* Bumped minimum Go version to 1.20.
* Added automatic re-requesting of undecryptable WhatsApp messages from primary
device.
* Added support for round video messages.
* Added support for logging in by entering a 8-letter code on the phone instead
of scanning a QR code.
* Note: due to a server-side change, code login may only work when `os_name`
and `browser_name` in the config are set in a specific way. This is fixed
in v0.10.1.

# v0.9.0 (2023-07-16)

* Removed MSC2716 support.
* Added legacy backfill support.
* Updated Docker image to Alpine 3.18.
* Changed all ogg audio messages from WhatsApp to be bridged as voice messages
to Matrix, as WhatsApp removes the voice message flag when forwarding for
some reason.
* Added Prometheus metric for WhatsApp connection failures
(thanks to [@Half-Shot] in [#620]).

[#620]: https://github.com/mautrix/whatsapp/pull/620

# v0.8.6 (2023-06-16)

* Implemented intentional mentions for outgoing messages.
* Added support for appservice websockets.
* Added additional index on message table to make bridging outgoing read
receipts and messages faster in chats with lots of messages.
* Fixed handling WhatsApp poll messages that only allow one choice.
* Fixed bridging new groups immediately when they're created.

# v0.8.5 (2023-05-16)

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM golang:1-alpine3.17 AS builder
FROM golang:1-alpine3.19 AS builder

RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev

COPY . /build
WORKDIR /build
RUN go build -o /usr/bin/mautrix-whatsapp

FROM alpine:3.17
FROM alpine:3.19

ENV UID=1337 \
GID=1337
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.17
FROM alpine:3.19

ENV UID=1337 \
GID=1337
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1-alpine3.17
FROM golang:1-alpine3.18

RUN apk add --no-cache git ca-certificates build-base su-exec olm-dev bash jq yq curl

Expand Down
25 changes: 12 additions & 13 deletions segment.go → analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,34 @@ import (
"maunium.net/go/mautrix/id"
)

const SegmentURL = "https://api.segment.io/v1/track"

type SegmentClient struct {
type AnalyticsClient struct {
url string
key string
userID string
log log.Logger
client http.Client
}

var Segment SegmentClient
var Analytics AnalyticsClient

func (sc *SegmentClient) trackSync(userID id.UserID, event string, properties map[string]interface{}) error {
func (sc *AnalyticsClient) trackSync(userID id.UserID, event string, properties map[string]interface{}) error {
var buf bytes.Buffer
var segmentUserID string
if Segment.userID != "" {
segmentUserID = Segment.userID
var analyticsUserID string
if Analytics.userID != "" {
analyticsUserID = Analytics.userID
} else {
segmentUserID = userID.String()
analyticsUserID = userID.String()
}
err := json.NewEncoder(&buf).Encode(map[string]interface{}{
"userId": segmentUserID,
"userId": analyticsUserID,
"event": event,
"properties": properties,
})
if err != nil {
return err
}

req, err := http.NewRequest("POST", SegmentURL, &buf)
req, err := http.NewRequest(http.MethodPost, sc.url, &buf)
if err != nil {
return err
}
Expand All @@ -70,11 +69,11 @@ func (sc *SegmentClient) trackSync(userID id.UserID, event string, properties ma
return nil
}

func (sc *SegmentClient) IsEnabled() bool {
func (sc *AnalyticsClient) IsEnabled() bool {
return len(sc.key) > 0
}

func (sc *SegmentClient) Track(userID id.UserID, event string, properties ...map[string]interface{}) {
func (sc *AnalyticsClient) Track(userID id.UserID, event string, properties ...map[string]interface{}) {
if !sc.IsEnabled() {
return
} else if len(properties) > 1 {
Expand Down
2 changes: 1 addition & 1 deletion backfillqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (user *User) HandleBackfillRequestsLoop(backfillTypes []database.BackfillTy
req := user.BackfillQueue.GetNextBackfill(user.MXID, backfillTypes, waitForBackfillTypes, reCheckChannel)
user.log.Infofln("Handling backfill request %s", req)

conv := user.bridge.DB.HistorySync.GetConversation(user.MXID, req.Portal)
conv := user.bridge.DB.HistorySync.GetConversation(user.MXID, *req.Portal)
if conv == nil {
user.log.Debugfln("Could not find history sync conversation data for %s", req.Portal.String())
req.MarkDone()
Expand Down
Loading

0 comments on commit 805d847

Please sign in to comment.