Repository navigation
feat: 馃幐 Add message unsend functionality and chat removal handling #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -780,6 +780,22 @@ func (lc *LineClient) handleOperation(ctx context.Context, op line.Operation) { | |||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if op.Type == 64 || op.Type == 65 { | ||||||||||||||
| chatMid := op.Param1 | ||||||||||||||
| msgID := op.Param2 | ||||||||||||||
| lc.UserLogin.Bridge.Log.Info().Str("msg_id", msgID).Str("chat_mid", chatMid).Int("op_type", op.Type).Msg("Received unsend operation") | ||||||||||||||
|
|
||||||||||||||
| ts, _ := op.CreatedTime.Int64() | ||||||||||||||
| lc.UserLogin.Bridge.QueueRemoteEvent(lc.UserLogin, &simplevent.MessageRemove{ | ||||||||||||||
| EventMeta: simplevent.EventMeta{ | ||||||||||||||
| Type: bridgev2.RemoteEventMessageRemove, | ||||||||||||||
| PortalKey: networkid.PortalKey{ID: makePortalID(chatMid), Receiver: lc.UserLogin.ID}, | ||||||||||||||
| Timestamp: time.UnixMilli(ts), | ||||||||||||||
| }, | ||||||||||||||
| TargetMessage: networkid.MessageID(msgID), | ||||||||||||||
| }) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if op.Type == 140 { | ||||||||||||||
| go func() { | ||||||||||||||
| param2, err := line.ParseReactionParam2(op.Param2) | ||||||||||||||
|
|
@@ -1506,9 +1522,11 @@ func (lc *LineClient) LogoutRemote(ctx context.Context) {} | |||||||||||||
|
|
||||||||||||||
| func (lc *LineClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures { | ||||||||||||||
| return &event.RoomFeatures{ | ||||||||||||||
| MaxTextLength: 5000, | ||||||||||||||
| Reply: event.CapLevelFullySupported, | ||||||||||||||
| ReadReceipts: true, | ||||||||||||||
| MaxTextLength: 5000, | ||||||||||||||
| Reply: event.CapLevelFullySupported, | ||||||||||||||
| ReadReceipts: true, | ||||||||||||||
| Delete: event.CapLevelPartialSupport, | ||||||||||||||
| DeleteChatForEveryone: true, | ||||||||||||||
| File: event.FileFeatureMap{ | ||||||||||||||
| event.MsgImage: { | ||||||||||||||
| MimeTypes: map[string]event.CapabilitySupportLevel{ | ||||||||||||||
|
|
@@ -2244,6 +2262,34 @@ func (lc *LineClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.Mat | |||||||||||||
| }, nil | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (lc *LineClient) HandleMatrixMessageRemove(ctx context.Context, msg *bridgev2.MatrixMessageRemove) error { | ||||||||||||||
| client := line.NewClient(lc.AccessToken) | ||||||||||||||
|
|
||||||||||||||
| reqSeq := int(time.Now().UnixMilli() % 1_000_000_000) | ||||||||||||||
| lc.reqSeqMu.Lock() | ||||||||||||||
| if lc.sentReqSeqs == nil { | ||||||||||||||
| lc.sentReqSeqs = make(map[int]time.Time) | ||||||||||||||
| } | ||||||||||||||
| lc.sentReqSeqs[reqSeq] = time.Now() | ||||||||||||||
| lc.reqSeqMu.Unlock() | ||||||||||||||
|
|
||||||||||||||
| return client.UnsendMessage(int64(reqSeq), string(msg.TargetMessage.ID)) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (lc *LineClient) HandleMatrixLeaveRoom(ctx context.Context, portal *bridgev2.Portal) error { | ||||||||||||||
| client := line.NewClient(lc.AccessToken) | ||||||||||||||
|
|
||||||||||||||
| reqSeq := int(time.Now().UnixMilli() % 1_000_000_000) | ||||||||||||||
| lc.reqSeqMu.Lock() | ||||||||||||||
| if lc.sentReqSeqs == nil { | ||||||||||||||
| lc.sentReqSeqs = make(map[int]time.Time) | ||||||||||||||
| } | ||||||||||||||
| lc.sentReqSeqs[reqSeq] = time.Now() | ||||||||||||||
| lc.reqSeqMu.Unlock() | ||||||||||||||
|
Comment on lines
+2283
to
+2288
|
||||||||||||||
| lc.reqSeqMu.Lock() | |
| if lc.sentReqSeqs == nil { | |
| lc.sentReqSeqs = make(map[int]time.Time) | |
| } | |
| lc.sentReqSeqs[reqSeq] = time.Now() | |
| lc.reqSeqMu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HandleMatrixMessageRemovestores the generatedreqSeqinlc.sentReqSeqs, but there is no corresponding cleanup path for these entries (the only cleanup happens for operations withop.Type == 25), so every Matrix-initiated delete will leak an entry in this map for the lifetime of the process. Either avoid addingreqSeqfor operations that don't get an op 25 echo, or extend the cleanup logic to remove entries for the operation types used byunsendMessageso the map doesn't grow without bound.