forked from mirrors/linphone-iphone
feat(MainDB): supports chat messages store
This commit is contained in:
parent
2a9d4afef2
commit
88fbd50b76
7 changed files with 52 additions and 6 deletions
|
|
@ -1327,6 +1327,14 @@ void ChatMessage::setToAddress(Address to) {
|
|||
d->to = to;
|
||||
}
|
||||
|
||||
const Address &ChatMessage::getLocalAddress () const {
|
||||
return getDirection() == Direction::Incoming ? getToAddress() : getFromAddress();
|
||||
}
|
||||
|
||||
const Address &ChatMessage::getRemoteAddress () const {
|
||||
return getDirection() != Direction::Incoming ? getToAddress() : getFromAddress();
|
||||
}
|
||||
|
||||
const string& ChatMessage::getFileTransferFilepath() const {
|
||||
L_D();
|
||||
return d->fileTransferFilePath;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ public:
|
|||
|
||||
const Address &getFromAddress () const;
|
||||
const Address &getToAddress () const;
|
||||
const Address &getLocalAddress () const;
|
||||
const Address &getRemoteAddress () const;
|
||||
|
||||
const LinphoneErrorInfo *getErrorInfo () const;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
BasicChatRoom (LinphoneCore *core, const Address &peerAddress);
|
||||
virtual ~BasicChatRoom () = default;
|
||||
|
||||
int getCapabilities () const override;
|
||||
CapabilitiesMask getCapabilities () const override;
|
||||
|
||||
/* ConferenceInterface. */
|
||||
void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override;
|
||||
|
|
|
|||
|
|
@ -39,10 +39,12 @@ public:
|
|||
L_DECLARE_ENUM(Capabilities, L_ENUM_VALUES_CHAT_ROOM_CAPABILITIES);
|
||||
L_DECLARE_ENUM(State, L_ENUM_VALUES_CHAT_ROOM_STATE);
|
||||
|
||||
typedef int CapabilitiesMask;
|
||||
|
||||
ChatRoom (LinphoneCore *core);
|
||||
virtual ~ChatRoom () = default;
|
||||
|
||||
virtual int getCapabilities () const = 0;
|
||||
virtual CapabilitiesMask getCapabilities () const = 0;
|
||||
|
||||
void compose ();
|
||||
std::shared_ptr<ChatMessage> createFileTransferMessage (const LinphoneContent *initialContent);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public:
|
|||
ClientGroupChatRoom (LinphoneCore *core, const Address &me, const std::string &uri, const std::string &subject);
|
||||
virtual ~ClientGroupChatRoom () = default;
|
||||
|
||||
int getCapabilities () const override;
|
||||
CapabilitiesMask getCapabilities () const override;
|
||||
|
||||
/* ConferenceInterface */
|
||||
void addParticipant (const Address &addr, const CallSessionParams *params, bool hasMedia) override;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public:
|
|||
RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress);
|
||||
virtual ~RealTimeTextChatRoom () = default;
|
||||
|
||||
int getCapabilities () const override;
|
||||
CapabilitiesMask getCapabilities () const override;
|
||||
|
||||
uint32_t getChar () const;
|
||||
LinphoneCall *getCall () const;
|
||||
|
|
|
|||
|
|
@ -247,8 +247,37 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
}
|
||||
|
||||
long MainDbPrivate::insertMessageEvent (const EventLog &eventLog) {
|
||||
// TODO.
|
||||
return 0;
|
||||
shared_ptr<ChatMessage> chatMessage = static_cast<const ChatMessageEvent &>(eventLog).getChatMessage();
|
||||
shared_ptr<ChatRoom> chatRoom = chatMessage->getChatRoom();
|
||||
if (!chatRoom) {
|
||||
lError() << "Unable to get a valid chat room. It was removed from database.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
tm eventTime = Utils::getLongAsTm(static_cast<long>(eventLog.getTime()));
|
||||
|
||||
struct MessageEventReferences references;
|
||||
references.eventId = insertEvent(EventLog::Type::ChatMessage, eventTime);
|
||||
references.localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString());
|
||||
references.remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString());
|
||||
references.chatRoomId = insertChatRoom(
|
||||
references.remoteSipAddressId,
|
||||
chatRoom->getCapabilities(),
|
||||
eventTime
|
||||
);
|
||||
|
||||
insertChatRoomParticipant(references.chatRoomId, references.remoteSipAddressId, false);
|
||||
|
||||
long eventId = insertMessageEvent (
|
||||
references,
|
||||
static_cast<int>(chatMessage->getState()),
|
||||
static_cast<int>(chatMessage->getDirection()),
|
||||
chatMessage->getImdnMessageId(),
|
||||
chatMessage->isSecured(),
|
||||
chatMessage->getContents()
|
||||
);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog) {
|
||||
|
|
@ -260,6 +289,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
soci::session *session = dbSession.getBackendSession<soci::session>();
|
||||
*session << "INSERT INTO conference_event (event_id, chat_room_id)"
|
||||
" VALUES (:eventId, :chatRoomId)", soci::use(eventId), soci::use(chatRoomId);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
|
|
@ -271,6 +301,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
" VALUES (:eventId, :notifyId)", soci::use(eventId), soci::use(
|
||||
static_cast<const ConferenceNotifiedEvent &>(eventLog).getNotifyId()
|
||||
);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
|
|
@ -283,6 +314,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
soci::session *session = dbSession.getBackendSession<soci::session>();
|
||||
*session << "INSERT INTO conference_participant_event (event_id, participant_address_id)"
|
||||
" VALUES (:eventId, :participantAddressId)", soci::use(eventId), soci::use(participantAddressId);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
|
|
@ -295,6 +327,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
soci::session *session = dbSession.getBackendSession<soci::session>();
|
||||
*session << "INSERT INTO conference_participant_device_event (event_id, gruu_address_id)"
|
||||
" VALUES (:eventId, :gruuAddressId)", soci::use(eventId), soci::use(gruuAddressId);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
|
|
@ -306,6 +339,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {}
|
|||
" VALUES (:eventId, :subject)", soci::use(eventId), soci::use(
|
||||
static_cast<const ConferenceSubjectEvent &>(eventLog).getSubject()
|
||||
);
|
||||
|
||||
return eventId;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue