getChatInfo static method
chat info contains messages per member, members of the chat, messages, and size of the chat
Implementation
static ChatContent getChatInfo(List<String> chat) {
bool isAndroid = Platform.isAndroid;
List<String> names = [];
List<List<int>> countNameMsgs = [];
List<MessageContent> msgContents = [];
List<String> lines = [];
bool first = true;
for (int i = isAndroid ? 1 : 2; i < chat.length; i++) {
if (_regExp.hasMatch(chat[i])) {
lines.add(chat[i]);
if (!first) {
MessageContent msgContent = _getMsgContentFromStringLine(
lines[lines.length - (isAndroid ? 1 : 2)]);
if (!names.contains(msgContent.senderId) &&
msgContent.senderId != null) {
names.add(msgContent.senderId!);
countNameMsgs.add([msgContents.length]);
msgContents.add(msgContent);
} else {
if (msgContent.senderId != null) {
countNameMsgs[names.indexOf(msgContent.senderId!)].add(
msgContents.length);
msgContents.add(msgContent);
}
}
}
first = false;
} else {
lines[lines.length - 1] += "\n${chat[i]}";
}
}
names.remove(null);
Map<String, List<int>> indexesPerMember = {};
Map<String, int> msgsPerPerson = {};
names.remove(null);
for (int i = 0; i < names.length; i++) {
msgsPerPerson[names[i]] = countNameMsgs[i].length;
indexesPerMember[names[i]] = countNameMsgs[i];
}
return ChatContent(
members: names,
messages: msgContents,
sizeOfChat: msgContents.length,
indexesPerMember: indexesPerMember,
msgsPerMember: msgsPerPerson,
chatName: '',
);
}