Some work on #264 + pin

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-08-03 13:44:43 +02:00
parent 9ab55198ee
commit c50257653c
5 changed files with 146 additions and 8 deletions

View file

@ -289,13 +289,13 @@ public interface NcApi {
@Url String url, @Query("search") String query,
@Nullable @Query("limit") Integer limit);
// Url is: /api/{apiVersion}/room/{token}/favorite
// Url is: /api/{apiVersion}/room/{token}/pin
@POST
Observable<GenericOverall> addConversationToFavorites(@Header("Authorization") String authorization,
Observable<GenericOverall> pinConversation(@Header("Authorization") String authorization,
@Url String url);
// Url is: /api/{apiVersion}/room/{token}/favorite
// Url is: /api/{apiVersion}/room/{token}/pin
@DELETE
Observable<GenericOverall> removeConversationFromFavorites(@Header("Authorization") String authorization,
Observable<GenericOverall> unpinConversation(@Header("Authorization") String authorization,
@Url String url);
}

View file

@ -22,6 +22,7 @@ package com.nextcloud.talk.models.json.chat;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.R;
import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter;
import com.nextcloud.talk.utils.ApiUtils;
import com.stfalcon.chatkit.commons.models.IMessage;
import com.stfalcon.chatkit.commons.models.IUser;
@ -37,6 +38,24 @@ import lombok.Data;
@Data
@JsonObject
public class ChatMessage implements IMessage {
public enum SystemMessageType {
DUMMY,
CONVERSATION_CREATED,
CONVERSATION_RENAMED,
CALL_JOINED,
CALL_LEFT,
CALL_ENDED,
GUESTS_ALLOWED,
GUESTS_DISALLOWED,
PASSWORD_SET,
PASSWORD_REMOVED,
USER_ADDED,
USER_REMOVED,
MODERATOR_PROMOTED,
MODERATOR_DEMOTED
}
String baseUrl;
@JsonField(name = "id")
int jsonMessageId;
@ -57,8 +76,13 @@ public class ChatMessage implements IMessage {
String message;
@JsonField(name = "messageParameters")
HashMap<String, HashMap<String, String>> messageParameters;
@JsonField(name = "systemMessage", typeConverter = EnumSystemMessageTypeConverter.class)
SystemMessageType systemMessageType;
boolean isGrouped;
public String getBaseUrl() {
return baseUrl;
}

View file

@ -0,0 +1,114 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.converters;
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import static com.nextcloud.talk.models.json.chat.ChatMessage.SystemMessageType.*;
/*
conversation_created - {actor} created the conversation
conversation_renamed - {actor} renamed the conversation from "foo" to "bar"
call_joined - {actor} joined the call
call_left - {actor} left the call
call_ended - Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration 30:23)
guests_allowed - {actor} allowed guests in the conversation
guests_disallowed - {actor} disallowed guests in the conversation
password_set - {actor} set a password for the conversation
password_removed - {actor} removed the password for the conversation
user_added - {actor} added {user} to the conversation
user_removed - {actor} removed {user} from the conversation
moderator_promoted - {actor} promoted {user} to moderator
moderator_demoted - {actor} demoted {user} from moderator
*/
public class EnumSystemMessageTypeConverter extends StringBasedTypeConverter<ChatMessage.SystemMessageType> {
@Override
public ChatMessage.SystemMessageType getFromString(String string) {
switch (string) {
case "conversation_created":
return CONVERSATION_CREATED;
case "conversation_renamed":
return CONVERSATION_RENAMED;
case "call_joined":
return CALL_JOINED;
case "call_left":
return CALL_LEFT;
case "call_ended":
return CALL_ENDED;
case "guests_allowed":
return GUESTS_ALLOWED;
case "guests_disallowed":
return GUESTS_DISALLOWED;
case "password_set":
return PASSWORD_SET;
case "password_removed":
return PASSWORD_REMOVED;
case "user_added":
return USER_ADDED;
case "user_removed":
return USER_REMOVED;
case "moderator_promoted":
return MODERATOR_PROMOTED;
case "moderator_demoted":
return MODERATOR_DEMOTED;
default:
return DUMMY;
}
}
@Override
public String convertToString(ChatMessage.SystemMessageType object) {
switch (object) {
case CONVERSATION_CREATED:
return "conversation_created";
case CONVERSATION_RENAMED:
return "conversation_renamed";
case CALL_JOINED:
return "conversation_renamed";
case CALL_LEFT:
return "call_left";
case CALL_ENDED:
return "call_ended";
case GUESTS_ALLOWED:
return "guests_allowed";
case GUESTS_DISALLOWED:
return "guests_disallowed";
case PASSWORD_SET:
return "password_set";
case PASSWORD_REMOVED:
return "password_removed";
case USER_ADDED:
return "user_added";
case USER_REMOVED:
return "user_removed";
case MODERATOR_PROMOTED:
return "moderator_promoted";
case MODERATOR_DEMOTED:
return "moderator_demoted";
default:
return "";
}
}
}

View file

@ -64,8 +64,8 @@ public class Room {
@JsonField(name = "sessionId")
public String sessionId;
public String password;
@JsonField(name = "isFavorite")
public boolean isFavorite;
@JsonField(name = "isPinned")
public boolean isPinned;
@JsonField(name = "lastActivity")
public long lastActivity;
@JsonField(name = "unreadMessages")

View file

@ -188,7 +188,7 @@ public class ApiUtils {
getApplicationContext().getResources().getString(R.string.nc_push_server_url) + "/devices";
}
public static String getUrlForConversationFavorite(String baseUrl, String roomToken) {
return baseUrl + ocsApiVersion + "/room/" + roomToken + "/favorite";
public static String getUrlForConversationPin(String baseUrl, String roomToken) {
return baseUrl + ocsApiVersion + "/room/" + roomToken + "/pin";
}
}