-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
267 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.db* | ||
*.yaml | ||
*.log | ||
!example-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package connector | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
"maunium.net/go/mautrix/bridgev2" | ||
"maunium.net/go/mautrix/event" | ||
) | ||
|
||
var _ bridgev2.BackfillingNetworkAPI = (*DummyClient)(nil) | ||
|
||
func (dc *DummyClient) FetchMessages(ctx context.Context, fetchParams bridgev2.FetchMessagesParams) (resp *bridgev2.FetchMessagesResponse, err error) { | ||
resp = &bridgev2.FetchMessagesResponse{} | ||
|
||
if !dc.UserLogin.Bridge.Config.Backfill.Enabled { | ||
return | ||
} else if fetchParams.Portal == nil { | ||
return | ||
} else if time.Now().After(dc.Connector.Started.Add(dc.Connector.Config.Automation.Backfill.Timelimit)) { | ||
return | ||
} | ||
|
||
tsMassage := -time.Second | ||
if fetchParams.Forward { | ||
tsMassage *= -1 | ||
} | ||
nextTs := time.Now() | ||
if fetchParams.AnchorMessage != nil { | ||
nextTs = fetchParams.AnchorMessage.Timestamp.Add(tsMassage) | ||
} | ||
|
||
for i := 0; i < fetchParams.Count; i++ { | ||
sender := stablePortalUserIDByIndex(fetchParams.Portal.ID, rand.Intn(dc.Connector.Config.Automation.Portals.Members)) | ||
_, err := dc.UserLogin.Bridge.GetGhostByID(ctx, sender) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get ghost by id: %w", err) | ||
} | ||
|
||
msg := bridgev2.BackfillMessage{ | ||
ID: randomMessageID(), | ||
ConvertedMessage: &bridgev2.ConvertedMessage{ | ||
Parts: []*bridgev2.ConvertedMessagePart{ | ||
{ | ||
Type: event.EventMessage, | ||
Content: &event.MessageEventContent{ | ||
Body: string(sender), | ||
}, | ||
}, | ||
}, | ||
}, | ||
Timestamp: nextTs, | ||
Sender: bridgev2.EventSender{ | ||
Sender: sender, | ||
}, | ||
} | ||
|
||
resp.Messages = append(resp.Messages, &msg) | ||
nextTs = msg.Timestamp.Add(tsMassage) | ||
} | ||
|
||
// always claim we have more until timelimit is hit | ||
resp.HasMore = true | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Automation options | ||
automation: | ||
# Open management room for admins | ||
open_management_room: false | ||
# Login admins automatically | ||
login: false | ||
|
||
# Portal automation for admins | ||
portals: | ||
# How many portals to create | ||
count: 0 | ||
# How many members are initially in a portal | ||
members: 0 | ||
# How many messages are initially sent to the portal | ||
messages: 0 | ||
|
||
# Backfill automation | ||
backfill: | ||
# How long to do first startup infinite backfill | ||
timelimit: 0s |
Oops, something went wrong.