Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Konheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Konheko
Commits
a87df521
Commit
a87df521
authored
5 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Basic event handling
parent
9f698097
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/models/roomlistmodel.cpp
+1
-1
1 addition, 1 deletion
src/models/roomlistmodel.cpp
src/models/roommodel.cpp
+83
-1
83 additions, 1 deletion
src/models/roommodel.cpp
src/models/roommodel.h
+11
-0
11 additions, 0 deletions
src/models/roommodel.h
src/sync.cpp
+2
-0
2 additions, 0 deletions
src/sync.cpp
with
97 additions
and
2 deletions
src/models/roomlistmodel.cpp
+
1
−
1
View file @
a87df521
...
...
@@ -78,7 +78,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const {
switch
(
role
)
{
case
RoomNameRole
:
return
QString
::
fromStdString
(
room
->
n
ame
);
return
QString
::
fromStdString
(
room
->
N
ame
()
);
case
UnreadNotificationsRole
:
return
room
->
unreadNotifications
;
case
LastMessageRole
:
...
...
This diff is collapsed.
Click to expand it.
src/models/roommodel.cpp
+
83
−
1
View file @
a87df521
...
...
@@ -8,15 +8,97 @@
Q_DECLARE_METATYPE
(
Room
);
Q_DECLARE_METATYPE
(
QSharedPointer
<
Room
>
);
std
::
string
Room
::
Name
()
{
qDebug
()
<<
"called name"
;
if
(
!
name
.
empty
())
{
return
name
;
}
if
(
!
canonical_alias
.
empty
())
{
qDebug
()
<<
"return alias"
<<
QString
::
fromStdString
(
canonical_alias
);
return
canonical_alias
;
}
std
::
string
heroes
;
for
(
const
auto
&
m
:
members
)
{
if
(
!
heroes
.
empty
())
heroes
+=
", "
;
std
::
string
hero_name
=
memberInfos
[
m
].
display_name
;
heroes
+=
hero_name
.
empty
()
?
m
:
hero_name
;
}
qDebug
()
<<
"return heroes"
<<
QString
::
fromStdString
(
heroes
);
return
heroes
;
}
void
Room
::
applyEvents
(
const
std
::
vector
<
mtx
::
events
::
collections
::
TimelineEvent
>
&
events
)
{
using
namespace
mtx
::
events
;
for
(
const
mtx
::
events
::
collections
::
TimelineEvent
&
e
:
events
)
{
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Name
>>
(
&
e
.
data
))
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Aliases
>>
(
&
e
.
data
))
{
if
(
this
->
canonical_alias
.
empty
()
&&
!
ev
->
content
.
aliases
.
empty
())
this
->
canonical_alias
=
ev
->
content
.
aliases
.
front
();
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Avatar
>>
(
&
e
.
data
))
{
this
->
avatar_url
=
ev
->
content
.
url
;
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
CanonicalAlias
>>
(
&
e
.
data
))
{
this
->
canonical_alias
=
ev
->
content
.
alias
;
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Create
>>
(
&
e
.
data
))
{
this
->
members
.
insert
(
ev
->
content
.
creator
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Encryption
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
GuestAccess
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
HistoryVisibility
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
JoinRules
>>
(
&
e
.
data
))
{
this
->
join_rule
=
ev
->
content
.
join_rule
;
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Member
>>
(
&
e
.
data
))
{
switch
(
ev
->
content
.
membership
)
{
case
state
::
Membership
::
Join
:
case
state
::
Membership
::
Invite
:
this
->
members
.
insert
(
ev
->
sender
);
this
->
memberInfos
[
ev
->
sender
]
=
MemberInfo
{
ev
->
content
.
avatar_url
,
ev
->
content
.
display_name
,
ev
->
sender
};
break
;
case
state
::
Membership
::
Ban
:
case
state
::
Membership
::
Leave
:
this
->
members
.
erase
(
ev
->
sender
);
this
->
memberInfos
.
erase
(
ev
->
sender
);
break
;
}
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Name
>>
(
&
e
.
data
))
this
->
name
=
ev
->
content
.
name
;
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
PinnedEvents
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
PowerLevels
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
StateEvent
<
state
::
Topic
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
EncryptedEvent
<
msg
::
Encrypted
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
RedactionEvent
<
msg
::
Redaction
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
Sticker
>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Redacted
>>
(
&
e
.
data
))
{
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Audio
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Emote
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
File
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Image
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Notice
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Text
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
else
if
(
const
auto
ev
=
boost
::
get
<
RoomEvent
<
msg
::
Video
>>
(
&
e
.
data
))
{
this
->
msgInfo
.
body
=
QString
::
fromStdString
(
ev
->
content
.
body
);
this
->
lastMessage
=
ev
->
content
.
body
;
this
->
msgInfo
.
userid
=
QString
::
fromStdString
(
ev
->
sender
);
}
}
this
->
events
.
insert
(
this
->
events
.
end
(),
events
.
begin
(),
events
.
end
());
...
...
This diff is collapsed.
Click to expand it.
src/models/roommodel.h
+
11
−
0
View file @
a87df521
#pragma once
#include
<map>
#include
<set>
#include
<string>
#include
<vector>
...
...
@@ -17,6 +19,10 @@ struct DescInfo {
QDateTime
datetime
;
};
struct
MemberInfo
{
std
::
string
avatar_url
,
display_name
,
userid
;
};
struct
Room
{
std
::
string
id
,
lastMessage
,
tag
;
...
...
@@ -24,6 +30,7 @@ struct Room {
//! The calculated name of the room.
std
::
string
name
;
std
::
string
canonical_alias
;
//! The topic of the room.
std
::
string
topic
;
//! The calculated avatar url of the room.
...
...
@@ -40,7 +47,11 @@ struct Room {
//! The list of tags associated with this room
std
::
vector
<
std
::
string
>
tags
;
std
::
set
<
std
::
string
>
members
;
std
::
map
<
std
::
string
,
MemberInfo
>
memberInfos
;
void
applyEvents
(
const
std
::
vector
<
mtx
::
events
::
collections
::
TimelineEvent
>
&
events
);
std
::
string
Name
();
private:
std
::
vector
<
mtx
::
events
::
collections
::
TimelineEvent
>
events
;
...
...
This diff is collapsed.
Click to expand it.
src/sync.cpp
+
2
−
0
View file @
a87df521
...
...
@@ -109,6 +109,8 @@ void Sync::sync() {
room
->
id
=
invite
.
first
;
room
->
tags
.
push_back
(
"invite"
);
room
->
is_invite
=
true
;
room
->
name
=
r
.
name
();
room
->
avatar_url
=
r
.
avatar
();
qDebug
()
<<
QString
::
fromStdString
(
room
->
id
);
std
::
vector
<
mtx
::
events
::
collections
::
TimelineEvent
>
timeline
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment