Skip to content

Commit

Permalink
Merge pull request #492 from matrix-org/riot_1860
Browse files Browse the repository at this point in the history
Send Stickers: Manage local echo for sticker
  • Loading branch information
manuroe authored May 18, 2018
2 parents 9054d8d + 1f46b81 commit 8fba1cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
13 changes: 11 additions & 2 deletions MatrixSDK/Data/MXRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,16 +758,25 @@ FOUNDATION_EXPORT NSString *const kMXRoomDidFlushDataNotification;
- (MXEventTimeline*)timelineOnEvent:(NSString*)eventId;

#pragma mark - Fake event objects creation
/**
Create a temporary event for the room.
@param eventId the event id. A globally unique string with kMXEventLocalEventIdPrefix prefix is defined when this param is nil.
@param eventType the type of the event. @see MXEventType.
@param content the event content.
@return the created event.
*/
- (MXEvent*)fakeEventWithEventId:(NSString*)eventId eventType:(MXEventTypeString)eventType andContent:(NSDictionary<NSString*, id>*)content;

/**
Create a temporary message event for the room.
@param eventId the event id. A globally unique string with kMXEventLocalEventIdPrefix prefix is defined when this param is nil.
@param content the event content.
@return the created event.
*/
- (MXEvent*)fakeRoomMessageEventWithEventId:(NSString*)eventId andContent:(NSDictionary<NSString*, id>*)content;


#pragma mark - Outgoing events management
/**
Store into the store an outgoing message event being sent in the room.
Expand Down
30 changes: 18 additions & 12 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
else
{
// Check whether a local echo is required
if ([eventTypeString isEqualToString:kMXEventTypeStringRoomMessage])
if ([eventTypeString isEqualToString:kMXEventTypeStringRoomMessage]
|| [eventTypeString isEqualToString:kMXEventTypeStringSticker])
{
if (!event)
{
// Add a local echo for this message during the sending process.
event = [self addLocalEchoForMessageContent:contentCopy withState:MXEventSentStateEncrypting];
event = [self addLocalEchoForMessageContent:contentCopy eventType:eventTypeString withState:MXEventSentStateEncrypting];

if (localEcho)
{
Expand All @@ -377,7 +378,7 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
if (event)
{
// Encapsulate the resulting event in a fake encrypted event
MXEvent *clearEvent = [self fakeRoomMessageEventWithEventId:event.eventId andContent:event.content];
MXEvent *clearEvent = [self fakeEventWithEventId:event.eventId eventType:eventTypeString andContent:event.content];

event.wireType = encryptedEventType;
event.wireContent = encryptedContent;
Expand Down Expand Up @@ -418,12 +419,13 @@ - (MXHTTPOperation*)sendEventOfType:(MXEventTypeString)eventTypeString
else
{
// Check whether a local echo is required
if ([eventTypeString isEqualToString:kMXEventTypeStringRoomMessage])
if ([eventTypeString isEqualToString:kMXEventTypeStringRoomMessage]
|| [eventTypeString isEqualToString:kMXEventTypeStringSticker])
{
if (!event)
{
// Add a local echo for this message during the sending process.
event = [self addLocalEchoForMessageContent:contentCopy withState:MXEventSentStateSending];
event = [self addLocalEchoForMessageContent:contentCopy eventType:eventTypeString withState:MXEventSentStateSending];

if (localEcho)
{
Expand Down Expand Up @@ -647,7 +649,7 @@ - (MXHTTPOperation*)sendImage:(NSData*)imageData

// Add a local echo for this message during the sending process.
MXEventSentState initialSentState = (mxSession.crypto && self.state.isEncrypted) ? MXEventSentStateEncrypting : MXEventSentStateUploading;
event = [self addLocalEchoForMessageContent:msgContent withState:initialSentState];
event = [self addLocalEchoForMessageContent:msgContent eventType:kMXEventTypeStringRoomMessage withState:initialSentState];

if (localEcho)
{
Expand Down Expand Up @@ -848,7 +850,7 @@ - (MXHTTPOperation*)sendVideo:(NSURL*)videoLocalURL
};

// Add a local echo for this message during the sending process.
event = [self addLocalEchoForMessageContent:msgContent withState:MXEventSentStatePreparing];
event = [self addLocalEchoForMessageContent:msgContent eventType:kMXEventTypeStringRoomMessage withState:MXEventSentStatePreparing];

if (localEcho)
{
Expand Down Expand Up @@ -1110,7 +1112,7 @@ - (MXHTTPOperation*)sendFile:(NSURL*)fileLocalURL

// Add a local echo for this message during the sending process.
MXEventSentState initialSentState = (mxSession.crypto && self.state.isEncrypted) ? MXEventSentStateEncrypting : MXEventSentStateUploading;
event = [self addLocalEchoForMessageContent:msgContent withState:initialSentState];
event = [self addLocalEchoForMessageContent:msgContent eventType:kMXEventTypeStringRoomMessage withState:initialSentState];

if (localEcho)
{
Expand Down Expand Up @@ -1513,7 +1515,7 @@ - (MXEventTimeline*)timelineOnEvent:(NSString*)eventId;


#pragma mark - Fake event objects creation
- (MXEvent*)fakeRoomMessageEventWithEventId:(NSString*)eventId andContent:(NSDictionary*)content
- (MXEvent*)fakeEventWithEventId:(NSString*)eventId eventType:(NSString*)eventType andContent:(NSDictionary*)content
{
if (!eventId)
{
Expand All @@ -1523,14 +1525,18 @@ - (MXEvent*)fakeRoomMessageEventWithEventId:(NSString*)eventId andContent:(NSDic
MXEvent *event = [[MXEvent alloc] init];
event.roomId = _roomId;
event.eventId = eventId;
event.wireType = kMXEventTypeStringRoomMessage;
event.wireType = eventType;
event.originServerTs = (uint64_t) ([[NSDate date] timeIntervalSince1970] * 1000);
event.sender = mxSession.myUser.userId;
event.wireContent = content;

return event;
}

- (MXEvent*)fakeRoomMessageEventWithEventId:(NSString*)eventId andContent:(NSDictionary<NSString*, id>*)content
{
return [self fakeEventWithEventId:eventId eventType:kMXEventTypeStringRoomMessage andContent:content];
}

#pragma mark - Outgoing events management
- (void)storeOutgoingMessage:(MXEvent*)outgoingMessage
Expand Down Expand Up @@ -1659,10 +1665,10 @@ - (void)refreshOutgoingMessages

#pragma mark - Local echo handling

- (MXEvent*)addLocalEchoForMessageContent:(NSDictionary*)msgContent withState:(MXEventSentState)eventState
- (MXEvent*)addLocalEchoForMessageContent:(NSDictionary*)msgContent eventType:(MXEventTypeString)eventType withState:(MXEventSentState)eventState
{
// Create a room message event.
MXEvent *localEcho = [self fakeRoomMessageEventWithEventId:nil andContent:msgContent];
MXEvent *localEcho = [self fakeEventWithEventId:nil eventType:eventType andContent:msgContent];
localEcho.sentState = eventState;

// Register the echo as pending for its future deletion
Expand Down

0 comments on commit 8fba1cf

Please sign in to comment.