public void updateSessionReadyData(SocketResponseSessionData sessionReadyData) { sessionReadyData.lobbyChannels.ForEach(channel => { this.updateNormalChannelLite(channel: channel); if (!this.joinedChannels.Contains(item: channel.id)) { this.joinedChannels.Add(item: channel.id); } }); sessionReadyData.publicChannels.ForEach(channel => { this.updateNormalChannelLite(channel: channel); if (!this.joinedChannels.Contains(item: channel.id)) { this.joinedChannels.Add(item: channel.id); } }); sessionReadyData.privateChannels.ForEach(channel => { this.updateNormalChannelLite(channel: channel); if (!this.joinedChannels.Contains(item: channel.id)) { this.joinedChannels.Add(item: channel.id); } }); sessionReadyData.users.ForEach(user => { this.joinedChannels.ForEach(channelId => { this.channelDict[key: channelId].updateMessageUser(user: user); }); }); sessionReadyData.lastMessages.ForEach(message => { var channelId = message.channelId; if (this.channelDict.TryGetValue(key: channelId, out var channel)) { channel.lastMessageId = message.id; channel.lastMessage = ChannelMessageView.fromChannelMessageLite(message: message); channel.lastMessage.author = channel.getMember(userId: channel.lastMessage.author.id)?.user; channel.lastMessage.mentions = channel.lastMessage.mentions?.Select( user => channel.getMember(userId: user.id).user)?.ToList(); } }); sessionReadyData.readState.ForEach(readState => { var channelId = readState.channelId; if (this.channelDict.TryGetValue(key: channelId, out var channel)) { channel.mentioned = readState.mentionCount; channel.unread = channel.lastMessageId != null && readState.lastMessageId != null && readState.lastMessageId.hexToLong() < channel.lastMessageId.hexToLong() ? 1 : 0; channel.lastReadMessageId = readState.lastMessageId; channel.atMe = channel.mentioned > 0 && channel.unread > 0; } }); }
public FileMessage( ChannelMessageView message, GestureTapCallback onTap = null, Key key = null ) : base(key: key) { this.message = message; this.onTap = onTap; }
public TextMessage( ChannelMessageView message, MentionTapCallback onTap, Key key = null ) : base(key: key) { this.message = message; this.onTap = onTap; }
public static float CalculateTextHeight(ChannelMessageView message, float width) { var attachment = message.attachments.first(); var fileTitleHeight = CTextUtils.CalculateTextHeight(text: attachment.filename, textStyle: _fileTitleStyle, width - _filePadding.horizontal - 42 - 16); var fileSizeHeight = CTextUtils.CalculateTextHeight(CStringUtils.FileSize(bytes: attachment.size), textStyle: _fileSizeStyle, width - _filePadding.horizontal - 42 - 16); return(_filePadding.vertical + fileTitleHeight + fileSizeHeight + 4); }
public static float CalculateTextHeight(ChannelMessageView message) { if (message.width > message.height * 16.0f / 9.0f) { return(140.0f * 9.0f / 16.0f); } return(message.width > message.height ? 140.0f * message.height / message.width : 140.0f); }
/** * * save the given messages to DB (update its value if it already exists in DB) * */ public static void SyncSaveMessages(List <ChannelMessage> messages) { var msgLites = new List <DBMessageLite>(); foreach (var message in messages) { msgLites.Add(ConvertToDbMessageLite(ChannelMessageView.fromChannelMessage(message))); } SQLiteDBManager.instance.SaveMessages(msgLites); }
static void updateRemoteReaction(ChannelMessageView message, string type) { var local = getMessageReactions(message.id)?.getOrDefault(type, 0) ?? 0; var remote = message.getUserReactionsDict(UserInfoManager.getUserInfo().userId)?.getOrDefault(type, 0) ?? 0; if (local > 0 && remote == 0) { StoreProvider.store.dispatcher.dispatch(Actions.addReaction(messageId: message.id, likeEmoji: type)); } else if (local == 0 && remote > 0) { StoreProvider.store.dispatcher.dispatch(Actions.cancelReaction(messageId: message.id, type: type)); } }
public EmbedMessage( ChannelMessageView message, MentionTapCallback onClickUser, Action <string> onClickUrl, Action <string> onClickImage, Dictionary <string, string> headers = null, Key key = null ) : base(key: key) { this.message = message; this.onClickUser = onClickUser; this.onClickUrl = onClickUrl; this.onClickImage = onClickImage; this.headers = headers; }
public void removeLocalMessage(ChannelMessageView channelMessage) { var channel = this.channelDict[channelMessage.channelId]; var key = $"{channelMessage.author.id}:{channel.id}:{channelMessage.nonce:x16}"; if (channel.localMessageIds.Contains($"{channelMessage.nonce:x16}") && this.localMessageDict.ContainsKey(key)) { if (channelMessage.type == ChannelMessageType.image) { channelMessage.imageData = this.localMessageDict[key].imageData; } this.localMessageDict.Remove(key); channel.localMessageIds.Remove($"{channelMessage.nonce:x16}"); } }
public static void updateMyReaction(ChannelMessageView message, string type) { if (!myReactionsDict.ContainsKey(key: message.id)) { myReactionsDict.Add(key: message.id, new Dictionary <string, int>()); } if (!myReactionsDict[key : message.id].ContainsKey(key : type)) { myReactionsDict[key : message.id].Add(key : type, 0); } myReactionsDict[key : message.id][key : type] = 1 - myReactionsDict[key : message.id][key : type]; timerDict.getOrDefault(message.id + type, null)?.cancel(); timerDict[message.id + type] = Window.instance.run(TimeSpan.FromMilliseconds(1000), () => { updateRemoteReaction(message, type); timerDict.Remove(message.id + type); }); }
static DBMessageLite ConvertToDbMessageLite(ChannelMessageView message) { var embedsList = new DBEmbedList { embeds = message.embeds ?? new List <Embed>() }; var embedsJson = JsonConvert.SerializeObject(embedsList); var mentionsList = new DBUserList { users = new List <DBUser>() }; if (message.mentions != null) { foreach (var metion in message.mentions) { mentionsList.users.Add(new DBUser { id = metion.id, name = metion.fullName, thumb = metion.avatar }); } } var metionsJson = JsonConvert.SerializeObject(mentionsList); return(new DBMessageLite { messageKey = MessageIdToKey(message.id), messageId = message.id, content = message.content, authorName = message.author.fullName, authorThumb = message.author.avatar, authorId = message.author.id, channelId = message.channelId, nonce = message.nonce, type = (int)message.type, mentionEveryone = message.mentionEveryone ? 1 : 0, deleted = message.deleted ? 1 : 0, embedsJson = embedsJson, mentionsJson = metionsJson }); }
public static float CalculateTextHeight(ChannelMessageView message, float width) { var contentHeight = CTextUtils.CalculateTextHeight( text: MessageUtils.truncateMessage(message.content), textStyle: _contentStyle, textWidth: width - _contentPadding.horizontal); float descriptionHeight; if (message.type == ChannelMessageType.embedImage) { descriptionHeight = ImageMessage.CalculateTextHeight(message: message); } else if (message.type == ChannelMessageType.embedExternal) { var embedData = message.embeds[0].embedData; var embedDataTitleHeight = CTextUtils.CalculateTextHeight(text: embedData.title, textStyle: _embedTitleStyle, width - 48); var embedDescriptionHeight = CTextUtils.CalculateTextHeight(text: embedData.description, textStyle: _embedDescriptionStyle, width - 48, 4); float embedNameHeight; if (embedData.image.isEmpty() && embedData.name.isEmpty()) { embedNameHeight = 0; } else { embedNameHeight = 22; } descriptionHeight = embedDataTitleHeight + 4 + embedDescriptionHeight + 4 + embedNameHeight; } else { descriptionHeight = 0; } return(contentHeight + descriptionHeight + _contentPadding.vertical + _contentPadding.vertical); }
/** * * save the given message to DB (update its value if it already exists in DB) * */ public static void SyncSaveMessage(ChannelMessageView message) { SyncSaveMessages(new List <ChannelMessageView> { message }); }