Skip to content

Commit 0c57f04

Browse files
committed
read receipts / more twitter events
1 parent bbe7cac commit 0c57f04

File tree

7 files changed

+123
-37
lines changed

7 files changed

+123
-37
lines changed

ROADMAP.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
# Features & roadmap
22

33
* Matrix → Twitter
4-
* [+] Message content
5-
* [+] Text
4+
* [] Message content
5+
* [] Text
66
* [ ] Formatting
7-
* [+] Media
8-
* [+] Images
9-
* [+] Videos
10-
* [+] Gifs
11-
* [+] Message reactions
7+
* [] Media
8+
* [] Images
9+
* [] Videos
10+
* [] Gifs
11+
* [] Message reactions
1212
* [ ] Typing notifications
13-
* [ ] Read receipts
13+
* [] Read receipts
1414
* Twitter → Matrix
15-
* [+] Message content
16-
* [+] Text
15+
* [] Message content
16+
* [] Text
1717
* [ ] Formatting
18-
* [+] Media
19-
* [+] Images
20-
* [+] Videos
21-
* [+] Gifs
22-
* [+] Message reactions
23-
* [+] Message history
24-
* [+] When creating portal
18+
* [] Media
19+
* [] Images
20+
* [] Videos
21+
* [] Gifs
22+
* [] Message reactions
23+
* [] Message history
24+
* [] When creating portal
2525
* [ ] Missed messages
26-
* [+] Avatars
26+
* [] Avatars
2727
* [ ] † Typing notifications
2828
* [ ] † Read receipts
2929
* Misc
30-
* [+] Automatic portal creation
31-
* [+] At startup
32-
* [+] When receiving invite or message
30+
* [] Automatic portal creation
31+
* [] At startup
32+
* [] When receiving invite or message
3333
* [ ] Provisioning API for logging in
3434
* [ ] Private chat creation by inviting Matrix puppet of Twitter user to new room
3535
* [ ] Option to use own Matrix account for messages sent from other Twitter clients

pkg/connector/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type TwitterClient struct {
4444
var (
4545
_ bridgev2.NetworkAPI = (*TwitterClient)(nil)
4646
_ bridgev2.ReactionHandlingNetworkAPI = (*TwitterClient)(nil)
47+
_ bridgev2.ReadReceiptHandlingNetworkAPI = (*TwitterClient)(nil)
4748
)
4849

4950
func NewTwitterClient(ctx context.Context, tc *TwitterConnector, login *bridgev2.UserLogin) (*TwitterClient, error) {

pkg/connector/handlematrix.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,22 @@ func (tc *TwitterClient) doHandleMatrixReaction(remove bool, conversationId, mes
116116

117117
tc.client.Logger.Debug().Any("reactionResponse", reactionResponse).Any("payload", reactionPayload).Msg("Reaction response")
118118
return nil
119+
}
120+
121+
func (tc *TwitterClient) HandleMatrixReadReceipt(ctx context.Context, msg *bridgev2.MatrixReadReceipt) error {
122+
params := &payload.MarkConversationReadQuery{
123+
ConversationID: string(msg.Portal.ID),
124+
}
125+
126+
if msg.ExactMessage != nil {
127+
params.LastReadEventID = string(msg.ExactMessage.ID)
128+
} else {
129+
lastMessage, err := tc.userLogin.Bridge.DB.Message.GetLastPartAtOrBeforeTime(ctx, msg.Portal.PortalKey, msg.ReadUpTo)
130+
if err != nil {
131+
return err
132+
}
133+
params.LastReadEventID = string(lastMessage.ID)
134+
}
135+
136+
return tc.client.MarkConversationRead(params)
119137
}

pkg/connector/handletwit.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,9 @@ func (tc *TwitterClient) HandleTwitterEvent(rawEvt any) {
3838
reactionRemoteEvent := tc.wrapReaction(evtData)
3939
tc.connector.br.QueueRemoteEvent(tc.userLogin, reactionRemoteEvent)
4040
case event.XEventConversationRead:
41-
/*
42-
eventData := &simplevent.Receipt{
43-
EventMeta: simplevent.EventMeta{
44-
Type: bridgev2.RemoteEventReadReceipt,
45-
LogContext: func(c zerolog.Context) zerolog.Context {
46-
return c.
47-
Str("conversation_id", evtData.Conversation.ConversationID).
48-
Str("last_read_event_id", evtData.LastReadEventID).
49-
Str("read_at", evtData.ReadAt.String())
50-
},
51-
PortalKey: tc.MakePortalKey(evtData.Conversation),
52-
},
53-
LastTarget: networkid.MessageID(evtData.LastReadEventID),
54-
Targets: []networkid.MessageID{networkid.MessageID(evtData.LastReadEventID)},
55-
}
56-
*/
41+
// conversation read events are only fired by yourself??
42+
// if another user reads your message this is never fired
43+
// they use user_updates and last_read_event_id to figure that out with the polling client
5744
tc.client.Logger.Info().
5845
Str("conversation_id", evtData.Conversation.ConversationID).
5946
Str("last_read_event_id", evtData.LastReadEventID).
@@ -78,6 +65,10 @@ func (tc *TwitterClient) HandleTwitterEvent(rawEvt any) {
7865
}
7966
tc.connector.br.QueueRemoteEvent(tc.userLogin, messageDeleteRemoteEvent)
8067
}
68+
case event.XEventConversationNameUpdate:
69+
tc.client.Logger.Info().Str("new_name", evtData.Name).Any("conversation_id", evtData.Conversation.ConversationID).Any("executor", evtData.Executor).Msg("XEventConversationNameUpdate")
70+
case event.XEventConversationDelete:
71+
tc.client.Logger.Info().Any("data", evtData).Msg("Deleted conversation")
8172
default:
8273
tc.client.Logger.Warn().Any("event_data", evtData).Msg("Received unhandled event case from twitter library")
8374
}

pkg/twittermeow/data/response/events.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ func (data *XInboxData) ToEventEntries() ([]interface{}, error) {
109109
AffectsSort: messageEventData.AffectsSort,
110110
Reactions: messageEventData.MessageReactions,
111111
}
112+
case event.XConversationNameUpdate:
113+
var convNameUpdateEventData types.ConversationNameUpdateData
114+
err = json.Unmarshal(jsonEvData, &convNameUpdateEventData)
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
updatedAt, err := methods.UnixStringMilliToTime(convNameUpdateEventData.Time)
120+
if err != nil {
121+
return nil, err
122+
}
123+
124+
updatedEntry = event.XEventConversationNameUpdate{
125+
Conversation: data.GetConversationByID(convNameUpdateEventData.ConversationID),
126+
Name: convNameUpdateEventData.ConversationName,
127+
Executor: data.GetUserByID(convNameUpdateEventData.ByUserID),
128+
EventID: convNameUpdateEventData.ID,
129+
AffectsSort: convNameUpdateEventData.AffectsSort,
130+
UpdatedAt: updatedAt,
131+
}
112132
case event.XMessageDeleteEvent:
113133
var messageDeletedEventData types.MessageDeleted
114134
err = json.Unmarshal(jsonEvData, &messageDeletedEventData)
@@ -148,6 +168,25 @@ func (data *XInboxData) ToEventEntries() ([]interface{}, error) {
148168
AffectsSort: convReadEventData.AffectsSort,
149169
LastReadEventID: convReadEventData.LastReadEventID,
150170
}
171+
case event.XConversationDeleteEvent:
172+
var convDeletedEventData types.ConversationDeletedData
173+
err = json.Unmarshal(jsonEvData, &convDeletedEventData)
174+
if err != nil {
175+
return nil, err
176+
}
177+
178+
deletedAt, err := methods.UnixStringMilliToTime(convDeletedEventData.Time)
179+
if err != nil {
180+
return nil, err
181+
}
182+
183+
updatedEntry = event.XEventConversationDelete{
184+
ConversationID: convDeletedEventData.ConversationID,
185+
EventID: convDeletedEventData.ID,
186+
DeletedAt: deletedAt,
187+
AffectsSort: convDeletedEventData.AffectsSort,
188+
LastEventID: convDeletedEventData.LastEventID,
189+
}
151190
case event.XConversationCreateEvent:
152191
var convCreatedEventData types.ConversationCreatedData
153192
err = json.Unmarshal(jsonEvData, &convCreatedEventData)
@@ -167,6 +206,7 @@ func (data *XInboxData) ToEventEntries() ([]interface{}, error) {
167206
AffectsSort: convCreatedEventData.AffectsSort,
168207
RequestID: convCreatedEventData.RequestID,
169208
}
209+
170210
case event.XConversationMetadataUpdateEvent:
171211
var convMetadataUpdateEventData types.ConversationMetadataUpdate
172212
err = json.Unmarshal(jsonEvData, &convMetadataUpdateEventData)

pkg/twittermeow/data/types/messaging.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ type ConversationCreatedData struct {
6969
RequestID string `json:"request_id,omitempty"`
7070
}
7171

72+
type ConversationDeletedData struct {
73+
ID string `json:"id,omitempty"`
74+
Time string `json:"time,omitempty"`
75+
AffectsSort bool `json:"affects_sort,omitempty"`
76+
ConversationID string `json:"conversation_id,omitempty"`
77+
LastEventID string `json:"last_event_id,omitempty"`
78+
}
79+
80+
type ConversationNameUpdateData struct {
81+
ID string `json:"id,omitempty"`
82+
Time string `json:"time,omitempty"`
83+
ConversationID string `json:"conversation_id,omitempty"`
84+
ConversationName string `json:"conversation_name,omitempty"`
85+
ByUserID string `json:"by_user_id,omitempty"`
86+
AffectsSort bool `json:"affects_sort,omitempty"`
87+
}
88+
7289
type ConversationType string
7390

7491
const (

pkg/twittermeow/event/event.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const (
1414
XReactionDeletedEvent XEventType = "reaction_delete"
1515
XConversationReadEvent XEventType = "conversation_read"
1616
XConversationMetadataUpdateEvent XEventType = "conversation_metadata_update"
17+
XConversationNameUpdate XEventType = "conversation_name_update"
1718
XConversationCreateEvent XEventType = "conversation_create"
19+
XConversationDeleteEvent XEventType = "remove_conversation"
1820
XDisableNotificationsEvent XEventType = "disable_notifications"
1921
)
2022

@@ -48,13 +50,30 @@ type XEventConversationCreated struct {
4850
RequestID string
4951
}
5052

53+
type XEventConversationDelete struct {
54+
ConversationID string
55+
EventID string
56+
DeletedAt time.Time
57+
AffectsSort bool
58+
LastEventID string
59+
}
60+
5161
type XEventConversationMetadataUpdate struct {
5262
Conversation types.Conversation
5363
EventID string
5464
UpdatedAt time.Time
5565
AffectsSort bool
5666
}
5767

68+
type XEventConversationNameUpdate struct {
69+
Conversation types.Conversation
70+
EventID string
71+
UpdatedAt time.Time
72+
Name string
73+
Executor types.User
74+
AffectsSort bool
75+
}
76+
5877
type XEventMessageDeleted struct {
5978
Conversation types.Conversation
6079
EventID string

0 commit comments

Comments
 (0)