mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/matrix: use beeper inbox state endpoint if available
This commit is contained in:
parent
52b5649abd
commit
e939f164d2
4 changed files with 39 additions and 14 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/util/ptr"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
|
|
@ -118,7 +119,7 @@ func (as *ASIntent) SendState(ctx context.Context, roomID id.RoomID, eventType e
|
|||
}
|
||||
}
|
||||
|
||||
func (as *ASIntent) MarkRead(ctx context.Context, roomID id.RoomID, eventID id.EventID, ts time.Time) error {
|
||||
func (as *ASIntent) MarkRead(ctx context.Context, roomID id.RoomID, eventID id.EventID, ts time.Time) (err error) {
|
||||
extraData := map[string]any{}
|
||||
if !ts.IsZero() {
|
||||
extraData["ts"] = ts.UnixMilli()
|
||||
|
|
@ -132,25 +133,32 @@ func (as *ASIntent) MarkRead(ctx context.Context, roomID id.RoomID, eventID id.E
|
|||
req.FullyRead = eventID
|
||||
req.BeeperFullyReadExtra = extraData
|
||||
}
|
||||
err := as.Matrix.SetReadMarkers(ctx, roomID, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if as.Matrix.IsCustomPuppet {
|
||||
err = as.Matrix.SetRoomAccountData(ctx, roomID, event.AccountDataMarkedUnread.Type, &event.MarkedUnreadEventContent{
|
||||
Unread: false,
|
||||
if as.Matrix.IsCustomPuppet && as.Connector.SpecVersions.Supports(mautrix.BeeperFeatureInboxState) {
|
||||
err = as.Matrix.SetBeeperInboxState(ctx, roomID, &mautrix.ReqSetBeeperInboxState{
|
||||
MarkedUnread: ptr.Ptr(false),
|
||||
ReadMarkers: &req,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
err = as.Matrix.SetReadMarkers(ctx, roomID, &req)
|
||||
if err == nil && as.Matrix.IsCustomPuppet {
|
||||
err = as.Matrix.SetRoomAccountData(ctx, roomID, event.AccountDataMarkedUnread.Type, &event.MarkedUnreadEventContent{
|
||||
Unread: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
func (as *ASIntent) MarkUnread(ctx context.Context, roomID id.RoomID, unread bool) error {
|
||||
return as.Matrix.SetRoomAccountData(ctx, roomID, event.AccountDataMarkedUnread.Type, &event.MarkedUnreadEventContent{
|
||||
Unread: unread,
|
||||
})
|
||||
if as.Matrix.IsCustomPuppet && as.Connector.SpecVersions.Supports(mautrix.BeeperFeatureInboxState) {
|
||||
return as.Matrix.SetBeeperInboxState(ctx, roomID, &mautrix.ReqSetBeeperInboxState{
|
||||
MarkedUnread: ptr.Ptr(unread),
|
||||
})
|
||||
} else {
|
||||
return as.Matrix.SetRoomAccountData(ctx, roomID, event.AccountDataMarkedUnread.Type, &event.MarkedUnreadEventContent{
|
||||
Unread: unread,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (as *ASIntent) MarkTyping(ctx context.Context, roomID id.RoomID, typingType bridgev2.TypingType, timeout time.Duration) error {
|
||||
|
|
|
|||
|
|
@ -1932,6 +1932,12 @@ func (cli *Client) SetReadMarkers(ctx context.Context, roomID id.RoomID, content
|
|||
return
|
||||
}
|
||||
|
||||
func (cli *Client) SetBeeperInboxState(ctx context.Context, roomID id.RoomID, content *ReqSetBeeperInboxState) (err error) {
|
||||
urlPath := cli.BuildClientURL("unstable", "com.beeper.inbox", "user", cli.UserID, "rooms", roomID, "inbox_state")
|
||||
_, err = cli.MakeRequest(ctx, http.MethodPost, urlPath, content, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *Client) AddTag(ctx context.Context, roomID id.RoomID, tag event.RoomTag, order float64) error {
|
||||
return cli.AddTagWithCustomData(ctx, roomID, tag, &event.TagMetadata{
|
||||
Order: json.Number(strconv.FormatFloat(order, 'e', -1, 64)),
|
||||
|
|
|
|||
10
requests.go
10
requests.go
|
|
@ -365,6 +365,16 @@ type ReqSetReadMarkers struct {
|
|||
BeeperFullyReadExtra interface{} `json:"com.beeper.fully_read.extra,omitempty"`
|
||||
}
|
||||
|
||||
type BeeperInboxDone struct {
|
||||
Delta int64 `json:"at_delta"`
|
||||
}
|
||||
|
||||
type ReqSetBeeperInboxState struct {
|
||||
MarkedUnread *bool `json:"marked_unread,omitempty"`
|
||||
Done *BeeperInboxDone `json:"done,omitempty"`
|
||||
ReadMarkers *ReqSetReadMarkers `json:"read_markers,omitempty"`
|
||||
}
|
||||
|
||||
type ReqSendReceipt struct {
|
||||
ThreadID string `json:"thread_id,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ var (
|
|||
BeeperFeatureAutojoinInvites = UnstableFeature{UnstableFlag: "com.beeper.room_create_autojoin_invites"}
|
||||
BeeperFeatureArbitraryProfileMeta = UnstableFeature{UnstableFlag: "com.beeper.arbitrary_profile_meta"}
|
||||
BeeperFeatureAccountDataMute = UnstableFeature{UnstableFlag: "com.beeper.account_data_mute"}
|
||||
BeeperFeatureInboxState = UnstableFeature{UnstableFlag: "com.beeper.inbox_state"}
|
||||
)
|
||||
|
||||
func (versions *RespVersions) Supports(feature UnstableFeature) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue