NekoX/TMessagesProj/src/main/java/org/telegram/messenger/ChatObject.java

60 lines
2.3 KiB
Java
Raw Normal View History

2015-09-24 22:52:02 +02:00
/*
2015-10-29 18:10:07 +01:00
* This is the source code of Telegram for Android v. 3.x.x.
2015-09-24 22:52:02 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2017-03-31 01:58:05 +02:00
* Copyright Nikolai Kudashov, 2013-2017.
2015-09-24 22:52:02 +02:00
*/
package org.telegram.messenger;
import org.telegram.tgnet.TLRPC;
public class ChatObject {
public static final int CHAT_TYPE_CHAT = 0;
public static final int CHAT_TYPE_BROADCAST = 1;
public static final int CHAT_TYPE_CHANNEL = 2;
public static final int CHAT_TYPE_USER = 3;
2015-11-26 22:04:02 +01:00
public static final int CHAT_TYPE_MEGAGROUP = 4;
2015-09-24 22:52:02 +02:00
public static boolean isLeftFromChat(TLRPC.Chat chat) {
2015-11-26 22:04:02 +01:00
return chat == null || chat instanceof TLRPC.TL_chatEmpty || chat instanceof TLRPC.TL_chatForbidden || chat instanceof TLRPC.TL_channelForbidden || chat.left || chat.deactivated;
2015-09-24 22:52:02 +02:00
}
public static boolean isKickedFromChat(TLRPC.Chat chat) {
2015-11-26 22:04:02 +01:00
return chat == null || chat instanceof TLRPC.TL_chatEmpty || chat instanceof TLRPC.TL_chatForbidden || chat instanceof TLRPC.TL_channelForbidden || chat.kicked || chat.deactivated;
2015-09-24 22:52:02 +02:00
}
public static boolean isNotInChat(TLRPC.Chat chat) {
2015-11-26 22:04:02 +01:00
return chat == null || chat instanceof TLRPC.TL_chatEmpty || chat instanceof TLRPC.TL_chatForbidden || chat instanceof TLRPC.TL_channelForbidden || chat.left || chat.kicked || chat.deactivated;
2015-09-24 22:52:02 +02:00
}
public static boolean isChannel(TLRPC.Chat chat) {
return chat instanceof TLRPC.TL_channel || chat instanceof TLRPC.TL_channelForbidden;
}
public static boolean isChannel(int chatId) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
return chat instanceof TLRPC.TL_channel || chat instanceof TLRPC.TL_channelForbidden;
}
public static boolean isCanWriteToChannel(int chatId) {
TLRPC.Chat chat = MessagesController.getInstance().getChat(chatId);
2015-11-26 22:04:02 +01:00
return chat != null && (chat.creator || chat.editor || chat.megagroup);
2015-09-24 22:52:02 +02:00
}
public static boolean canWriteToChat(TLRPC.Chat chat) {
2015-11-26 22:04:02 +01:00
return !isChannel(chat) || chat.creator || chat.editor || !chat.broadcast;
2015-09-24 22:52:02 +02:00
}
public static TLRPC.Chat getChatByDialog(long did) {
int lower_id = (int) did;
int high_id = (int) (did >> 32);
2015-10-29 18:10:07 +01:00
if (lower_id < 0) {
return MessagesController.getInstance().getChat(-lower_id);
2015-09-24 22:52:02 +02:00
}
return null;
}
}