Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Display stickers #247

Merged
merged 4 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions matrix-sdk/src/main/java/org/matrix/androidsdk/MXSession.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2014 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.matrix.androidsdk.rest.client.ThirdPidRestClient;
import org.matrix.androidsdk.rest.model.CreateRoomParams;
import org.matrix.androidsdk.rest.model.CreateRoomResponse;
import org.matrix.androidsdk.rest.model.message.StickerMessage;
import org.matrix.androidsdk.rest.model.pid.DeleteDeviceAuth;
import org.matrix.androidsdk.rest.model.pid.DeleteDeviceParams;
import org.matrix.androidsdk.rest.model.sync.DevicesListResponse;
Expand Down Expand Up @@ -727,19 +729,23 @@ public void removeMediasBefore(final Context context, final long timestamp) {
if (null != events) {
for (Event event : events) {
try {
Message message = null;

if (TextUtils.equals(Event.EVENT_TYPE_MESSAGE, event.getType())) {
Message message = JsonUtils.toMessage(event.getContent());
message = JsonUtils.toMessage(event.getContent());
} else if (TextUtils.equals(Event.EVENT_TYPE_STICKER, event.getType())) {
message = JsonUtils.toStickerMessage(event.getContent());
}

if (message instanceof MediaMessage) {
MediaMessage mediaMessage = (MediaMessage) message;
if (null != message && message instanceof MediaMessage) {
MediaMessage mediaMessage = (MediaMessage) message;

if (mediaMessage.isThumbnailLocalContent()) {
filesToKeep.add(Uri.parse(mediaMessage.getThumbnailUrl()).getPath());
}
if (mediaMessage.isThumbnailLocalContent()) {
filesToKeep.add(Uri.parse(mediaMessage.getThumbnailUrl()).getPath());
}

if (mediaMessage.isLocalContent()) {
filesToKeep.add(Uri.parse(mediaMessage.getUrl()).getPath());
}
if (mediaMessage.isLocalContent()) {
filesToKeep.add(Uri.parse(mediaMessage.getUrl()).getPath());
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2015 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -163,6 +164,7 @@ public static boolean isSupportedEvent(Event event) {
TextUtils.equals(Event.EVENT_TYPE_STATE_ROOM_CREATE, type) ||
TextUtils.equals(Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY, type) ||
TextUtils.equals(Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE, type) ||
TextUtils.equals(Event.EVENT_TYPE_STICKER, type) ||
(event.isCallEvent() && !Event.EVENT_TYPE_CALL_CANDIDATES.equals(type));

if (!isSupported) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2015 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -906,8 +907,8 @@ protected boolean canAddEvent(Event event) {
Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(type) ||
Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(type) ||
Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY.equals(type) ||
(event.isCallEvent() && (!Event.EVENT_TYPE_CALL_CANDIDATES.equals(type)))
;
Event.EVENT_TYPE_STICKER.equals(type) ||
(event.isCallEvent() && (!Event.EVENT_TYPE_CALL_CANDIDATES.equals(type)));
}

//==============================================================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2014 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +23,7 @@
import org.matrix.androidsdk.rest.model.message.FileMessage;
import org.matrix.androidsdk.rest.model.message.ImageMessage;
import org.matrix.androidsdk.rest.model.message.Message;
import org.matrix.androidsdk.rest.model.message.StickerMessage;
import org.matrix.androidsdk.rest.model.message.VideoMessage;
import org.matrix.androidsdk.util.Log;

Expand Down Expand Up @@ -76,6 +78,7 @@ public enum SentState {

public static final String EVENT_TYPE_PRESENCE = "m.presence";
public static final String EVENT_TYPE_MESSAGE = "m.room.message";
public static final String EVENT_TYPE_STICKER = "m.sticker";
public static final String EVENT_TYPE_MESSAGE_ENCRYPTED = "m.room.encrypted";
public static final String EVENT_TYPE_MESSAGE_ENCRYPTION = "m.room.encryption";
public static final String EVENT_TYPE_FEEDBACK = "m.room.message.feedback";
Expand Down Expand Up @@ -672,6 +675,16 @@ public List<String> getMediaUrls() {
urls.add(videoMessage.getUrl());
}
}
} else if (Event.EVENT_TYPE_STICKER.equals(getType())) {
StickerMessage stickerMessage = JsonUtils.toStickerMessage(getContent());

if (null != stickerMessage.getUrl()) {
urls.add(stickerMessage.getUrl());
}

if (null != stickerMessage.getThumbnailUrl()) {
urls.add(stickerMessage.getThumbnailUrl());
}
}

return urls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class Message {
public static final String MSGTYPE_FILE = "m.file";
public static final String FORMAT_MATRIX_HTML = "org.matrix.custom.html";

// Add, in local, a fake message type in order to StickerMessage can inherit Message class
// Because sticker isn't a message type but a event type without msgtype field
public static final String MSGTYPE_STICKER_LOCAL = "org.matrix.android.sdk.sticker";

public String msgtype;
public String body;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2014 OpenMarket Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.androidsdk.rest.model.message;

// It's just an intermediate object to create a StickerMessage from a m.sticker event type.
public class StickerJsonMessage {

public String body;
public String url;
public String format;
public ImageInfo info;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.matrix.androidsdk.rest.model.message;


public class StickerMessage extends ImageMessage {

public StickerMessage() {
msgtype = MSGTYPE_STICKER_LOCAL;
}

public StickerMessage(StickerJsonMessage stickerJsonMessage) {
this.info = stickerJsonMessage.info;
this.url = stickerJsonMessage.url;
this.body = stickerJsonMessage.body;
this.format = stickerJsonMessage.format;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2016 OpenMarket Ltd
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -192,6 +193,15 @@ public CharSequence getTextualDisplay(Integer displayNameColor) {
((SpannableStringBuilder) text).setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, userDisplayName.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
} else if (Event.EVENT_TYPE_STICKER.equals(eventType)) {

// all m.stickers events should support the 'body' key fallback, so use it.
text = jsonEventContent.get("body") == null ? null : jsonEventContent.get("body").getAsString();

if (TextUtils.isEmpty(text)) {
text = mContext.getString(R.string.summary_user_sent_sticker, userDisplayName);
}

} else if (Event.EVENT_TYPE_MESSAGE_ENCRYPTION.equals(eventType)) {
text = mContext.getString(R.string.notice_end_to_end, userDisplayName, mEvent.getWireEventContent().algorithm);
} else if (Event.EVENT_TYPE_MESSAGE_ENCRYPTED.equals(eventType)) {
Expand Down
20 changes: 18 additions & 2 deletions matrix-sdk/src/main/java/org/matrix/androidsdk/util/JsonUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* Copyright 2014 OpenMarket Ltd
* Copyright 2017 Vector Creations Ltd
*
* Copyright 2018 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -36,14 +37,15 @@
import org.matrix.androidsdk.rest.model.MatrixError;
import org.matrix.androidsdk.rest.model.message.LocationMessage;
import org.matrix.androidsdk.rest.model.message.Message;
import org.matrix.androidsdk.rest.model.crypto.NewDeviceContent;
import org.matrix.androidsdk.rest.model.crypto.OlmEventContent;
import org.matrix.androidsdk.rest.model.crypto.OlmPayloadContent;
import org.matrix.androidsdk.rest.model.PowerLevels;
import org.matrix.androidsdk.rest.model.crypto.RoomKeyContent;
import org.matrix.androidsdk.rest.model.crypto.RoomKeyRequest;
import org.matrix.androidsdk.rest.model.RoomMember;
import org.matrix.androidsdk.rest.model.RoomTags;
import org.matrix.androidsdk.rest.model.message.StickerJsonMessage;
import org.matrix.androidsdk.rest.model.message.StickerMessage;
import org.matrix.androidsdk.rest.model.pid.RoomThirdPartyInvite;
import org.matrix.androidsdk.rest.model.User;
import org.matrix.androidsdk.rest.model.message.VideoMessage;
Expand Down Expand Up @@ -347,6 +349,20 @@ public static ImageMessage toImageMessage(JsonElement jsonObject) {
return (ImageMessage) toClass(jsonObject, ImageMessage.class);
}

/**
* Convert a JSON object to a StickerMessage.
* The result is never null.
*
* @param jsonObject the json to convert
* @return a StickerMessage
*/
public static StickerMessage toStickerMessage(JsonElement jsonObject) {
StickerJsonMessage stickerJsonMessage = (StickerJsonMessage) toClass(jsonObject, StickerJsonMessage.class);
StickerMessage stickerMessage = new StickerMessage(stickerJsonMessage);

return stickerMessage;
}

/**
* Convert a JSON object to an FileMessage.
* The result is never null.
Expand Down
1 change: 1 addition & 0 deletions matrix-sdk/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<string name="summary_message">%1$s: %2$s</string>
<string name="summary_user_sent_image">%1$s sent an image.</string>
<string name="summary_user_sent_sticker">%1$s sent a sticker.</string>

<string name="notice_room_invite_no_invitee">%s\'s invitation</string>
<string name="notice_room_invite">%1$s invited %2$s</string>
Expand Down