Skip to content

Commit

Permalink
Handle full-res media arriving and other message changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 15, 2024
1 parent 5cb7e0c commit 1c347fe
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 135 deletions.
10 changes: 4 additions & 6 deletions backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,12 @@ func (portal *Portal) backfillSendBatch(ctx context.Context, converted []*Conver
events = append(events, evt)
if dbm.MXID == "" {
dbm.MXID = evt.ID
if part.PendingMedia {
dbm.Status.MediaParts[""] = database.MediaPart{PendingMedia: true}
if part.MediaMeta.PendingMedia || part.MediaMeta.MediaID != "" {
dbm.Status.MediaParts[""] = part.MediaMeta
}
} else {
dbm.Status.MediaParts[part.ID] = database.MediaPart{
EventID: evt.ID,
PendingMedia: part.PendingMedia,
}
part.MediaMeta.EventID = evt.ID
dbm.Status.MediaParts[part.ID] = part.MediaMeta
}
}
if dbm.MXID != "" {
Expand Down
7 changes: 5 additions & 2 deletions database/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ func (mq *MessageQuery) DeleteAllInChat(ctx context.Context, chat Key) error {
}

type MediaPart struct {
EventID id.EventID `json:"mxid,omitempty"`
PendingMedia bool `json:"pending_media,omitempty"`
EventID id.EventID `json:"mxid,omitempty"`
PendingMedia bool `json:"pending_media,omitempty"`
MediaID string `json:"media_id,omitempty"`
ActionMessageID string `json:"action_message_id,omitempty"`
}

type MessageStatus struct {
Expand All @@ -103,6 +105,7 @@ type MessageStatus struct {
MediaStatus string `json:"media_status,omitempty"`
MediaParts map[string]MediaPart `json:"media_parts,omitempty"`
PartCount int `json:"part_count,omitempty"`
TextHash string `json:"text_hash,omitempty"`

MSSSent bool `json:"mss_sent,omitempty"`
MSSFailSent bool `json:"mss_fail_sent,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions libgm/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var responseType = map[gmproto.ActionType]proto.Message{
gmproto.ActionType_LIST_TOP_CONTACTS: &gmproto.ListTopContactsResponse{},
gmproto.ActionType_GET_OR_CREATE_CONVERSATION: &gmproto.GetOrCreateConversationResponse{},
gmproto.ActionType_UPDATE_CONVERSATION: &gmproto.UpdateConversationResponse{},
gmproto.ActionType_GET_FULL_SIZE_IMAGE: &gmproto.GetFullSizeImageResponse{},
}

func (c *Client) decryptInternalMessage(data *gmproto.IncomingRPCMessage) (*IncomingRPCMessage, error) {
Expand Down
253 changes: 186 additions & 67 deletions libgm/gmproto/client.pb.go

Large diffs are not rendered by default.

Binary file modified libgm/gmproto/client.pb.raw
Binary file not shown.
9 changes: 9 additions & 0 deletions libgm/gmproto/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,12 @@ message TypingUpdateRequest {

Data data = 2;
}

message GetFullSizeImageRequest {
string messageID = 1;
string actionMessageID = 2;
}

message GetFullSizeImageResponse {

}
28 changes: 14 additions & 14 deletions libgm/gmproto/conversations.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified libgm/gmproto/conversations.pb.raw
Binary file not shown.
4 changes: 2 additions & 2 deletions libgm/gmproto/conversations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ message MediaContent {
int64 size = 5;
Dimensions dimensions = 6;
bytes mediaData = 7;
string mediaID2 = 9;
string thumbnailMediaID = 9;
bytes decryptionKey = 11;
bytes decryptionKey2 = 12;
bytes thumbnailDecryptionKey = 12;
string mimeType = 14;
}

Expand Down
3 changes: 3 additions & 0 deletions libgm/manualdecrypt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ var requestType = map[gmproto.ActionType]proto.Message{
gmproto.ActionType_LIST_TOP_CONTACTS: &gmproto.ListTopContactsRequest{},
gmproto.ActionType_GET_OR_CREATE_CONVERSATION: &gmproto.GetOrCreateConversationRequest{},
gmproto.ActionType_UPDATE_CONVERSATION: &gmproto.UpdateConversationRequest{},
gmproto.ActionType_RESEND_MESSAGE: &gmproto.ResendMessageRequest{},
gmproto.ActionType_TYPING_UPDATES: &gmproto.TypingUpdateRequest{},
gmproto.ActionType_GET_FULL_SIZE_IMAGE: &gmproto.GetFullSizeImageRequest{},

gmproto.ActionType_CREATE_GAIA_PAIRING_CLIENT_INIT: &gmproto.GaiaPairingRequestContainer{},
gmproto.ActionType_CREATE_GAIA_PAIRING_CLIENT_FINISHED: &gmproto.GaiaPairingRequestContainer{},
Expand Down
7 changes: 7 additions & 0 deletions libgm/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,10 @@ func (c *Client) NotifyDittoActivity() (<-chan *IncomingRPCMessage, error) {
Data: &gmproto.NotifyDittoActivityRequest{Success: true},
})
}

func (c *Client) GetFullSizeImage(messageID, actionMessageID string) (*gmproto.GetFullSizeImageResponse, error) {
payload := &gmproto.GetFullSizeImageRequest{MessageID: messageID, ActionMessageID: actionMessageID}
actionType := gmproto.ActionType_GET_FULL_SIZE_IMAGE

return typedResponse[*gmproto.GetFullSizeImageResponse](c.sessionHandler.sendMessage(actionType, payload))
}
Loading

0 comments on commit 1c347fe

Please sign in to comment.