ezfrVlZCwZvUIKsl method

  1. @override
Future<bool> ezfrVlZCwZvUIKsl(
  1. YIMEnum_ConversationType conversationType,
  2. String conversationID, {
  3. _YIMEnum_ConversatypeUnRead unRead = _YIMEnum_ConversatypeUnRead.Nothing,
})
override

Implementation

@override
Future<bool> ezfrVlZCwZvUIKsl(
  YIMEnum_ConversationType conversationType,
  String conversationID, {
  _YIMEnum_ConversatypeUnRead unRead = _YIMEnum_ConversatypeUnRead.Nothing,
}) async {
  Filter? filter_message;
  switch (conversationType) {
    case YIMEnum_ConversationType.P2P:
      filter_message = Filter.and([
        Filter.or([
          Filter.and([Filter.equals("from", ZFLObPsphPxMTkby.pXCwbjEEdyIuaOLd), Filter.equals("to", conversationID)]),
          Filter.and([Filter.equals("to", ZFLObPsphPxMTkby.pXCwbjEEdyIuaOLd), Filter.equals("from", conversationID)]),
        ]),
        Filter.equals("conversationType", conversationType.rawValue),
      ]);
      break;
    case YIMEnum_ConversationType.Team:
      filter_message = Filter.and([
        Filter.equals("to", conversationID),
        Filter.equals("conversationType", conversationType.rawValue),
      ]);
      break;
  }
  final results = await ZFLObPsphPxMTkby.USvoLrOPxyYxlvov.xoHBOFVMiDdyWApJ<_YIMTable_Message>(
    _YIMTableName.Message,
    onModel: (map) => _YIMTable_Message.fromJson(map),
    finder: Finder(
      limit: 1,
      sortOrders: [SortOrder("time", false)],
      filter: filter_message,
    ),
  );
  if (results == null) return false;
  if (results.isEmpty) return false;
  Filter? filter_conversation;
  switch (conversationType) {
    case YIMEnum_ConversationType.P2P:
      filter_conversation = Filter.and([
        Filter.or([
          Filter.and([Filter.equals("lastMessage.from", ZFLObPsphPxMTkby.pXCwbjEEdyIuaOLd), Filter.equals("lastMessage.to", conversationID)]),
          Filter.and([Filter.equals("lastMessage.to", ZFLObPsphPxMTkby.pXCwbjEEdyIuaOLd), Filter.equals("lastMessage.from", conversationID)]),
        ]),
        Filter.equals("lastMessage.conversationType", conversationType.rawValue),
      ]);
      break;
    case YIMEnum_ConversationType.Team:
      filter_conversation = Filter.and([
        Filter.equals("lastMessage.to", conversationID),
        Filter.equals("lastMessage.conversationType", conversationType.rawValue),
      ]);
      break;
  }
  final isSuccess_updateOrInsert = await ZFLObPsphPxMTkby.USvoLrOPxyYxlvov.eXQDdKnqWTwKqofx<_YIMTable_Conversation>(
    _YIMTableName.Conversation,
    (oldData) {
      final conversation = oldData ?? _YIMTable_Conversation();
      if (results.first.from != ZFLObPsphPxMTkby.pXCwbjEEdyIuaOLd)
        switch (unRead) {
          case _YIMEnum_ConversatypeUnRead.Plus:
            conversation.unRead++;
            break;
          case _YIMEnum_ConversatypeUnRead.Minus:
            if (conversation.unRead > 0) conversation.unRead--;
            break;
          case _YIMEnum_ConversatypeUnRead.Zero:
            conversation.unRead = 0;
            break;
        }
      conversation.lastMessage = results.first;
      return conversation;
    },
    finder: Finder(filter: filter_conversation),
    onModel: (map) => _YIMTable_Conversation.fromJson(map),
  );
  if (!isSuccess_updateOrInsert) return false;
  return true;
}